Remove product literal strings in "pht()", part 5
[phabricator.git] / src / applications / files / storage / PhabricatorFileChunk.php
blob648ec18c6b9f6f33e2dc05354673873d8c2c74fe
1 <?php
3 final class PhabricatorFileChunk extends PhabricatorFileDAO
4 implements
5 PhabricatorPolicyInterface,
6 PhabricatorDestructibleInterface {
8 protected $chunkHandle;
9 protected $byteStart;
10 protected $byteEnd;
11 protected $dataFilePHID;
13 private $dataFile = self::ATTACHABLE;
15 protected function getConfiguration() {
16 return array(
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(
25 'key_file' => array(
26 'columns' => array('chunkHandle', 'byteStart', 'byteEnd'),
28 'key_data' => array(
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)
44 ->setByteEnd($end);
47 public function attachDataFile(PhabricatorFile $file = null) {
48 $this->dataFile = $file;
49 return $this;
52 public function getDataFile() {
53 return $this->assertAttached($this->dataFile);
57 /* -( PhabricatorPolicyInterface )----------------------------------------- */
60 public function getCapabilities() {
61 return array(
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) {
76 return false;
80 /* -( PhabricatorDestructibleInterface )----------------------------------- */
83 public function destroyObjectPermanently(
84 PhabricatorDestructionEngine $engine) {
86 $data_phid = $this->getDataFilePHID();
87 if ($data_phid) {
88 $data_file = id(new PhabricatorFileQuery())
89 ->setViewer($engine->getViewer())
90 ->withPHIDs(array($data_phid))
91 ->executeOne();
92 if ($data_file) {
93 $engine->destroyObject($data_file);
97 $this->delete();