Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/engine/PhabricatorMySQLFileStorageEngine.php
12241 views
1
<?php
2
3
/**
4
* MySQL blob storage engine. This engine is the easiest to set up but doesn't
5
* scale very well.
6
*
7
* It uses the @{class:PhabricatorFileStorageBlob} to actually access the
8
* underlying database table.
9
*
10
* @task internal Internals
11
*/
12
final class PhabricatorMySQLFileStorageEngine
13
extends PhabricatorFileStorageEngine {
14
15
16
/* -( Engine Metadata )---------------------------------------------------- */
17
18
19
/**
20
* For historical reasons, this engine identifies as "blob".
21
*/
22
public function getEngineIdentifier() {
23
return 'blob';
24
}
25
26
public function getEnginePriority() {
27
return 1;
28
}
29
30
public function canWriteFiles() {
31
return ($this->getFilesizeLimit() > 0);
32
}
33
34
35
public function hasFilesizeLimit() {
36
return true;
37
}
38
39
40
public function getFilesizeLimit() {
41
return PhabricatorEnv::getEnvConfig('storage.mysql-engine.max-size');
42
}
43
44
45
/* -( Managing File Data )------------------------------------------------- */
46
47
48
/**
49
* Write file data into the big blob store table in MySQL. Returns the row
50
* ID as the file data handle.
51
*/
52
public function writeFile($data, array $params) {
53
$blob = new PhabricatorFileStorageBlob();
54
$blob->setData($data);
55
$blob->save();
56
57
return $blob->getID();
58
}
59
60
61
/**
62
* Load a stored blob from MySQL.
63
*/
64
public function readFile($handle) {
65
return $this->loadFromMySQLFileStorage($handle)->getData();
66
}
67
68
69
/**
70
* Delete a blob from MySQL.
71
*/
72
public function deleteFile($handle) {
73
$this->loadFromMySQLFileStorage($handle)->delete();
74
}
75
76
77
/* -( Internals )---------------------------------------------------------- */
78
79
80
/**
81
* Load the Lisk object that stores the file data for a handle.
82
*
83
* @param string File data handle.
84
* @return PhabricatorFileStorageBlob Data DAO.
85
* @task internal
86
*/
87
private function loadFromMySQLFileStorage($handle) {
88
$blob = id(new PhabricatorFileStorageBlob())->load($handle);
89
if (!$blob) {
90
throw new Exception(pht("Unable to load MySQL blob file '%s'!", $handle));
91
}
92
return $blob;
93
}
94
95
}
96
97