Remove product literal strings in "pht()", part 5
[phabricator.git] / src / applications / files / engine / PhabricatorMySQLFileStorageEngine.php
blobeb49ef78c32145a5cc56f58420163e0ea099d0ca
1 <?php
3 /**
4 * MySQL blob storage engine. This engine is the easiest to set up but doesn't
5 * scale very well.
7 * It uses the @{class:PhabricatorFileStorageBlob} to actually access the
8 * underlying database table.
10 * @task internal Internals
12 final class PhabricatorMySQLFileStorageEngine
13 extends PhabricatorFileStorageEngine {
16 /* -( Engine Metadata )---------------------------------------------------- */
19 /**
20 * For historical reasons, this engine identifies as "blob".
22 public function getEngineIdentifier() {
23 return 'blob';
26 public function getEnginePriority() {
27 return 1;
30 public function canWriteFiles() {
31 return ($this->getFilesizeLimit() > 0);
35 public function hasFilesizeLimit() {
36 return true;
40 public function getFilesizeLimit() {
41 return PhabricatorEnv::getEnvConfig('storage.mysql-engine.max-size');
45 /* -( Managing File Data )------------------------------------------------- */
48 /**
49 * Write file data into the big blob store table in MySQL. Returns the row
50 * ID as the file data handle.
52 public function writeFile($data, array $params) {
53 $blob = new PhabricatorFileStorageBlob();
54 $blob->setData($data);
55 $blob->save();
57 return $blob->getID();
61 /**
62 * Load a stored blob from MySQL.
64 public function readFile($handle) {
65 return $this->loadFromMySQLFileStorage($handle)->getData();
69 /**
70 * Delete a blob from MySQL.
72 public function deleteFile($handle) {
73 $this->loadFromMySQLFileStorage($handle)->delete();
77 /* -( Internals )---------------------------------------------------------- */
80 /**
81 * Load the Lisk object that stores the file data for a handle.
83 * @param string File data handle.
84 * @return PhabricatorFileStorageBlob Data DAO.
85 * @task internal
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));
92 return $blob;