Changeset View
Changeset View
Standalone View
Standalone View
src/applications/pholio/storage/PholioImage.php
<?php | <?php | ||||
final class PholioImage extends PholioDAO | final class PholioImage extends PholioDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorExtendedPolicyInterface { | PhabricatorExtendedPolicyInterface { | ||||
protected $authorPHID; | protected $authorPHID; | ||||
protected $mockID; | protected $mockPHID; | ||||
protected $filePHID; | protected $filePHID; | ||||
protected $name; | protected $name; | ||||
protected $description; | protected $description; | ||||
protected $sequence; | protected $sequence; | ||||
protected $isObsolete; | protected $isObsolete; | ||||
protected $replacesImagePHID = null; | protected $replacesImagePHID = null; | ||||
private $inlineComments = self::ATTACHABLE; | private $inlineComments = self::ATTACHABLE; | ||||
private $file = self::ATTACHABLE; | private $file = self::ATTACHABLE; | ||||
private $mock = self::ATTACHABLE; | private $mock = self::ATTACHABLE; | ||||
public static function initializeNewImage() { | public static function initializeNewImage() { | ||||
return id(new self()) | return id(new self()) | ||||
->setName('') | ->setName('') | ||||
->setDescription('') | ->setDescription('') | ||||
->setIsObsolete(0); | ->setIsObsolete(0); | ||||
} | } | ||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'mockID' => 'id?', | 'mockPHID' => 'phid?', | ||||
'name' => 'text128', | 'name' => 'text128', | ||||
'description' => 'text', | 'description' => 'text', | ||||
'sequence' => 'uint32', | 'sequence' => 'uint32', | ||||
'isObsolete' => 'bool', | 'isObsolete' => 'bool', | ||||
'replacesImagePHID' => 'phid?', | 'replacesImagePHID' => 'phid?', | ||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_phid' => null, | // TODO: There should be a key starting with "mockPHID" here at a | ||||
Lint: TODO Comment: This comment has a TODO. | |||||
'keyPHID' => array( | // minimum, but it's not entirely clear what other columns we should | ||||
'columns' => array('phid'), | // have as part of the key. | ||||
'unique' => true, | |||||
), | |||||
'mockID' => array( | |||||
'columns' => array('mockID', 'isObsolete', 'sequence'), | |||||
), | |||||
epriestleyAuthorUnsubmitted Done Inline ActionsFor now, I've just removed these keys:
epriestley: For now, I've just removed these keys:
- We'll get an automatic `key_phid` on `bin/storage… | |||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function getPHIDType() { | public function getPHIDType() { | ||||
return PholioImagePHIDType::TYPECONST; | return PholioImagePHIDType::TYPECONST; | ||||
} | } | ||||
Show All 10 Lines | public function attachMock(PholioMock $mock) { | ||||
$this->mock = $mock; | $this->mock = $mock; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getMock() { | public function getMock() { | ||||
return $this->assertAttached($this->mock); | return $this->assertAttached($this->mock); | ||||
} | } | ||||
public function hasMock() { | |||||
return (bool)$this->getMockPHID(); | |||||
} | |||||
public function attachInlineComments(array $inline_comments) { | public function attachInlineComments(array $inline_comments) { | ||||
assert_instances_of($inline_comments, 'PholioTransactionComment'); | assert_instances_of($inline_comments, 'PholioTransactionComment'); | ||||
$this->inlineComments = $inline_comments; | $this->inlineComments = $inline_comments; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getInlineComments() { | public function getInlineComments() { | ||||
$this->assertAttached($this->inlineComments); | $this->assertAttached($this->inlineComments); | ||||
return $this->inlineComments; | return $this->inlineComments; | ||||
} | } | ||||
public function getURI() { | |||||
if ($this->hasMock()) { | |||||
$mock = $this->getMock(); | |||||
$mock_uri = $mock->getURI(); | |||||
$image_id = $this->getID(); | |||||
return "{$mock_uri}/{$image_id}/"; | |||||
} | |||||
// For now, standalone images have no URI. We could provide one at some | |||||
// point, although it's not clear that there's any motivation to do so. | |||||
return null; | |||||
} | |||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
); | ); | ||||
} | } | ||||
public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
// If the image is attached to a mock, we use an extended policy to match | // If the image is attached to a mock, we use an extended policy to match | ||||
// the mock's permissions. | // the mock's permissions. | ||||
if ($this->getMockID()) { | if ($this->hasMock()) { | ||||
return PhabricatorPolicies::getMostOpenPolicy(); | return PhabricatorPolicies::getMostOpenPolicy(); | ||||
} | } | ||||
// If the image is not attached to a mock, only the author can see it. | // If the image is not attached to a mock, only the author can see it. | ||||
return $this->getAuthorPHID(); | return $this->getAuthorPHID(); | ||||
} | } | ||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | ||||
return false; | return false; | ||||
} | } | ||||
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */ | /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */ | ||||
public function getExtendedPolicy($capability, PhabricatorUser $viewer) { | public function getExtendedPolicy($capability, PhabricatorUser $viewer) { | ||||
if ($this->getMockID()) { | if ($this->hasMock()) { | ||||
return array( | return array( | ||||
array( | array( | ||||
$this->getMock(), | $this->getMock(), | ||||
$capability, | $capability, | ||||
), | ), | ||||
); | ); | ||||
} | } | ||||
return array(); | return array(); | ||||
} | } | ||||
} | } |
This comment has a TODO.