Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / macro / storage / PhabricatorFileImageMacro.php
blob656a4c9c577a3c28baf00701dcfe5352fae16291
1 <?php
3 final class PhabricatorFileImageMacro extends PhabricatorFileDAO
4 implements
5 PhabricatorSubscribableInterface,
6 PhabricatorApplicationTransactionInterface,
7 PhabricatorFlaggableInterface,
8 PhabricatorTokenReceiverInterface,
9 PhabricatorPolicyInterface {
11 protected $authorPHID;
12 protected $filePHID;
13 protected $name;
14 protected $isDisabled = 0;
15 protected $audioPHID;
16 protected $audioBehavior = self::AUDIO_BEHAVIOR_NONE;
17 protected $mailKey;
19 private $file = self::ATTACHABLE;
20 private $audio = self::ATTACHABLE;
22 const AUDIO_BEHAVIOR_NONE = 'audio:none';
23 const AUDIO_BEHAVIOR_ONCE = 'audio:once';
24 const AUDIO_BEHAVIOR_LOOP = 'audio:loop';
26 public function attachFile(PhabricatorFile $file) {
27 $this->file = $file;
28 return $this;
31 public function getFile() {
32 return $this->assertAttached($this->file);
35 public function attachAudio(PhabricatorFile $audio = null) {
36 $this->audio = $audio;
37 return $this;
40 public function getAudio() {
41 return $this->assertAttached($this->audio);
44 public static function initializeNewFileImageMacro(PhabricatorUser $actor) {
45 $macro = id(new self())
46 ->setAuthorPHID($actor->getPHID());
47 return $macro;
50 protected function getConfiguration() {
51 return array(
52 self::CONFIG_AUX_PHID => true,
53 self::CONFIG_COLUMN_SCHEMA => array(
54 'name' => 'text128',
55 'authorPHID' => 'phid?',
56 'isDisabled' => 'bool',
57 'audioPHID' => 'phid?',
58 'audioBehavior' => 'text64',
59 'mailKey' => 'bytes20',
61 self::CONFIG_KEY_SCHEMA => array(
62 'name' => array(
63 'columns' => array('name'),
64 'unique' => true,
66 'key_disabled' => array(
67 'columns' => array('isDisabled'),
69 'key_dateCreated' => array(
70 'columns' => array('dateCreated'),
73 ) + parent::getConfiguration();
76 public function generatePHID() {
77 return PhabricatorPHID::generateNewPHID(
78 PhabricatorMacroMacroPHIDType::TYPECONST);
82 public function save() {
83 if (!$this->getMailKey()) {
84 $this->setMailKey(Filesystem::readRandomCharacters(20));
86 return parent::save();
89 public function getViewURI() {
90 return '/macro/view/'.$this->getID().'/';
94 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
97 public function getApplicationTransactionEditor() {
98 return new PhabricatorMacroEditor();
101 public function getApplicationTransactionTemplate() {
102 return new PhabricatorMacroTransaction();
106 /* -( PhabricatorSubscribableInterface )----------------------------------- */
109 public function isAutomaticallySubscribed($phid) {
110 return false;
114 /* -( PhabricatorTokenRecevierInterface )---------------------------------- */
117 public function getUsersToNotifyOfTokenGiven() {
118 return array(
119 $this->getAuthorPHID(),
124 /* -( PhabricatorPolicyInterface )----------------------------------------- */
127 public function getCapabilities() {
128 return array(
129 PhabricatorPolicyCapability::CAN_VIEW,
130 PhabricatorPolicyCapability::CAN_EDIT,
134 public function getPolicy($capability) {
135 switch ($capability) {
136 case PhabricatorPolicyCapability::CAN_VIEW:
137 return PhabricatorPolicies::getMostOpenPolicy();
138 case PhabricatorPolicyCapability::CAN_EDIT:
139 $app = PhabricatorApplication::getByClass(
140 'PhabricatorMacroApplication');
141 return $app->getPolicy(PhabricatorMacroManageCapability::CAPABILITY);
145 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
146 return false;