@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 95 lines 2.1 kB view raw
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 */ 12final 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 $handle 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}