Path: blob/master/src/applications/files/storage/PhabricatorFileChunk.php
12242 views
<?php12final class PhabricatorFileChunk extends PhabricatorFileDAO3implements4PhabricatorPolicyInterface,5PhabricatorDestructibleInterface {67protected $chunkHandle;8protected $byteStart;9protected $byteEnd;10protected $dataFilePHID;1112private $dataFile = self::ATTACHABLE;1314protected function getConfiguration() {15return array(16self::CONFIG_TIMESTAMPS => false,17self::CONFIG_COLUMN_SCHEMA => array(18'chunkHandle' => 'bytes12',19'byteStart' => 'uint64',20'byteEnd' => 'uint64',21'dataFilePHID' => 'phid?',22),23self::CONFIG_KEY_SCHEMA => array(24'key_file' => array(25'columns' => array('chunkHandle', 'byteStart', 'byteEnd'),26),27'key_data' => array(28'columns' => array('dataFilePHID'),29),30),31) + parent::getConfiguration();32}3334public static function newChunkHandle() {35$seed = Filesystem::readRandomBytes(64);36return PhabricatorHash::digestForIndex($seed);37}3839public static function initializeNewChunk($handle, $start, $end) {40return id(new PhabricatorFileChunk())41->setChunkHandle($handle)42->setByteStart($start)43->setByteEnd($end);44}4546public function attachDataFile(PhabricatorFile $file = null) {47$this->dataFile = $file;48return $this;49}5051public function getDataFile() {52return $this->assertAttached($this->dataFile);53}545556/* -( PhabricatorPolicyInterface )----------------------------------------- */575859public function getCapabilities() {60return array(61PhabricatorPolicyCapability::CAN_VIEW,62);63}646566public function getPolicy($capability) {67// These objects are low-level and only accessed through the storage68// engine, so policies are mostly just in place to let us use the common69// query infrastructure.70return PhabricatorPolicies::getMostOpenPolicy();71}727374public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {75return false;76}777879/* -( PhabricatorDestructibleInterface )----------------------------------- */808182public function destroyObjectPermanently(83PhabricatorDestructionEngine $engine) {8485$data_phid = $this->getDataFilePHID();86if ($data_phid) {87$data_file = id(new PhabricatorFileQuery())88->setViewer($engine->getViewer())89->withPHIDs(array($data_phid))90->executeOne();91if ($data_file) {92$engine->destroyObject($data_file);93}94}9596$this->delete();97}9899}100101102