3 final class PhabricatorFileChunk
extends PhabricatorFileDAO
5 PhabricatorPolicyInterface
,
6 PhabricatorDestructibleInterface
{
8 protected $chunkHandle;
11 protected $dataFilePHID;
13 private $dataFile = self
::ATTACHABLE
;
15 protected function getConfiguration() {
17 self
::CONFIG_TIMESTAMPS
=> false,
18 self
::CONFIG_COLUMN_SCHEMA
=> array(
19 'chunkHandle' => 'bytes12',
20 'byteStart' => 'uint64',
21 'byteEnd' => 'uint64',
22 'dataFilePHID' => 'phid?',
24 self
::CONFIG_KEY_SCHEMA
=> array(
26 'columns' => array('chunkHandle', 'byteStart', 'byteEnd'),
29 'columns' => array('dataFilePHID'),
32 ) + parent
::getConfiguration();
35 public static function newChunkHandle() {
36 $seed = Filesystem
::readRandomBytes(64);
37 return PhabricatorHash
::digestForIndex($seed);
40 public static function initializeNewChunk($handle, $start, $end) {
41 return id(new PhabricatorFileChunk())
42 ->setChunkHandle($handle)
43 ->setByteStart($start)
47 public function attachDataFile(PhabricatorFile
$file = null) {
48 $this->dataFile
= $file;
52 public function getDataFile() {
53 return $this->assertAttached($this->dataFile
);
57 /* -( PhabricatorPolicyInterface )----------------------------------------- */
60 public function getCapabilities() {
62 PhabricatorPolicyCapability
::CAN_VIEW
,
67 public function getPolicy($capability) {
68 // These objects are low-level and only accessed through the storage
69 // engine, so policies are mostly just in place to let us use the common
70 // query infrastructure.
71 return PhabricatorPolicies
::getMostOpenPolicy();
75 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
80 /* -( PhabricatorDestructibleInterface )----------------------------------- */
83 public function destroyObjectPermanently(
84 PhabricatorDestructionEngine
$engine) {
86 $data_phid = $this->getDataFilePHID();
88 $data_file = id(new PhabricatorFileQuery())
89 ->setViewer($engine->getViewer())
90 ->withPHIDs(array($data_phid))
93 $engine->destroyObject($data_file);