[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/files/engine/ -> PhabricatorMySQLFileStorageEngine.php (source)

   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 impl     Implementation
  11   * @task internal Internals
  12   */
  13  final class PhabricatorMySQLFileStorageEngine
  14    extends PhabricatorFileStorageEngine {
  15  
  16  /* -(  Implementation  )----------------------------------------------------- */
  17  
  18  
  19    /**
  20     * For historical reasons, this engine identifies as "blob".
  21     *
  22     * @task impl
  23     */
  24    public function getEngineIdentifier() {
  25      return 'blob';
  26    }
  27  
  28  
  29    /**
  30     * Write file data into the big blob store table in MySQL. Returns the row
  31     * ID as the file data handle.
  32     *
  33     * @task impl
  34     */
  35    public function writeFile($data, array $params) {
  36      $blob = new PhabricatorFileStorageBlob();
  37      $blob->setData($data);
  38      $blob->save();
  39  
  40      return $blob->getID();
  41    }
  42  
  43  
  44    /**
  45     * Load a stored blob from MySQL.
  46     * @task impl
  47     */
  48    public function readFile($handle) {
  49      return $this->loadFromMySQLFileStorage($handle)->getData();
  50    }
  51  
  52  
  53    /**
  54     * Delete a blob from MySQL.
  55     * @task impl
  56     */
  57    public function deleteFile($handle) {
  58      $this->loadFromMySQLFileStorage($handle)->delete();
  59    }
  60  
  61  
  62  /* -(  Internals  )---------------------------------------------------------- */
  63  
  64  
  65    /**
  66     * Load the Lisk object that stores the file data for a handle.
  67     *
  68     * @param string  File data handle.
  69     * @return PhabricatorFileStorageBlob Data DAO.
  70     * @task internal
  71     */
  72    private function loadFromMySQLFileStorage($handle) {
  73      $blob = id(new PhabricatorFileStorageBlob())->load($handle);
  74      if (!$blob) {
  75        throw new Exception("Unable to load MySQL blob file '{$handle}'!");
  76      }
  77      return $blob;
  78    }
  79  
  80  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1