Path: blob/master/src/applications/files/engine/PhabricatorMySQLFileStorageEngine.php
12241 views
<?php12/**3* MySQL blob storage engine. This engine is the easiest to set up but doesn't4* scale very well.5*6* It uses the @{class:PhabricatorFileStorageBlob} to actually access the7* underlying database table.8*9* @task internal Internals10*/11final class PhabricatorMySQLFileStorageEngine12extends PhabricatorFileStorageEngine {131415/* -( Engine Metadata )---------------------------------------------------- */161718/**19* For historical reasons, this engine identifies as "blob".20*/21public function getEngineIdentifier() {22return 'blob';23}2425public function getEnginePriority() {26return 1;27}2829public function canWriteFiles() {30return ($this->getFilesizeLimit() > 0);31}323334public function hasFilesizeLimit() {35return true;36}373839public function getFilesizeLimit() {40return PhabricatorEnv::getEnvConfig('storage.mysql-engine.max-size');41}424344/* -( Managing File Data )------------------------------------------------- */454647/**48* Write file data into the big blob store table in MySQL. Returns the row49* ID as the file data handle.50*/51public function writeFile($data, array $params) {52$blob = new PhabricatorFileStorageBlob();53$blob->setData($data);54$blob->save();5556return $blob->getID();57}585960/**61* Load a stored blob from MySQL.62*/63public function readFile($handle) {64return $this->loadFromMySQLFileStorage($handle)->getData();65}666768/**69* Delete a blob from MySQL.70*/71public function deleteFile($handle) {72$this->loadFromMySQLFileStorage($handle)->delete();73}747576/* -( Internals )---------------------------------------------------------- */777879/**80* Load the Lisk object that stores the file data for a handle.81*82* @param string File data handle.83* @return PhabricatorFileStorageBlob Data DAO.84* @task internal85*/86private function loadFromMySQLFileStorage($handle) {87$blob = id(new PhabricatorFileStorageBlob())->load($handle);88if (!$blob) {89throw new Exception(pht("Unable to load MySQL blob file '%s'!", $handle));90}91return $blob;92}9394}959697