4 * MySQL blob storage engine. This engine is the easiest to set up but doesn't
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 )---------------------------------------------------- */
20 * For historical reasons, this engine identifies as "blob".
22 public function getEngineIdentifier() {
26 public function getEnginePriority() {
30 public function canWriteFiles() {
31 return ($this->getFilesizeLimit() > 0);
35 public function hasFilesizeLimit() {
40 public function getFilesizeLimit() {
41 return PhabricatorEnv
::getEnvConfig('storage.mysql-engine.max-size');
45 /* -( Managing File Data )------------------------------------------------- */
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);
57 return $blob->getID();
62 * Load a stored blob from MySQL.
64 public function readFile($handle) {
65 return $this->loadFromMySQLFileStorage($handle)->getData();
70 * Delete a blob from MySQL.
72 public function deleteFile($handle) {
73 $this->loadFromMySQLFileStorage($handle)->delete();
77 /* -( Internals )---------------------------------------------------------- */
81 * Load the Lisk object that stores the file data for a handle.
83 * @param string File data handle.
84 * @return PhabricatorFileStorageBlob Data DAO.
87 private function loadFromMySQLFileStorage($handle) {
88 $blob = id(new PhabricatorFileStorageBlob())->load($handle);
90 throw new Exception(pht("Unable to load MySQL blob file '%s'!", $handle));