[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/paste/storage/ -> PhabricatorPaste.php (source)

   1  <?php
   2  
   3  final class PhabricatorPaste extends PhabricatorPasteDAO
   4    implements
   5      PhabricatorSubscribableInterface,
   6      PhabricatorTokenReceiverInterface,
   7      PhabricatorFlaggableInterface,
   8      PhabricatorMentionableInterface,
   9      PhabricatorPolicyInterface,
  10      PhabricatorProjectInterface,
  11      PhabricatorDestructibleInterface,
  12      PhabricatorApplicationTransactionInterface {
  13  
  14    protected $title;
  15    protected $authorPHID;
  16    protected $filePHID;
  17    protected $language;
  18    protected $parentPHID;
  19    protected $viewPolicy;
  20    protected $mailKey;
  21  
  22    private $content = self::ATTACHABLE;
  23    private $rawContent = self::ATTACHABLE;
  24  
  25    public static function initializeNewPaste(PhabricatorUser $actor) {
  26      $app = id(new PhabricatorApplicationQuery())
  27        ->setViewer($actor)
  28        ->withClasses(array('PhabricatorPasteApplication'))
  29        ->executeOne();
  30  
  31      $view_policy = $app->getPolicy(PasteDefaultViewCapability::CAPABILITY);
  32  
  33      return id(new PhabricatorPaste())
  34        ->setTitle('')
  35        ->setAuthorPHID($actor->getPHID())
  36        ->setViewPolicy($view_policy);
  37    }
  38  
  39    public function getURI() {
  40      return '/P'.$this->getID();
  41    }
  42  
  43    public function getConfiguration() {
  44      return array(
  45        self::CONFIG_AUX_PHID => true,
  46        self::CONFIG_COLUMN_SCHEMA => array(
  47          'title' => 'text255',
  48          'language' => 'text64',
  49          'mailKey' => 'bytes20',
  50          'parentPHID' => 'phid?',
  51  
  52          // T6203/NULLABILITY
  53          // Pastes should always have a view policy.
  54          'viewPolicy' => 'policy?',
  55        ),
  56        self::CONFIG_KEY_SCHEMA => array(
  57          'parentPHID' => array(
  58            'columns' => array('parentPHID'),
  59          ),
  60          'authorPHID' => array(
  61            'columns' => array('authorPHID'),
  62          ),
  63          'key_dateCreated' => array(
  64            'columns' => array('dateCreated'),
  65          ),
  66          'key_language' => array(
  67            'columns' => array('language'),
  68          ),
  69        ),
  70      ) + parent::getConfiguration();
  71    }
  72  
  73    public function generatePHID() {
  74      return PhabricatorPHID::generateNewPHID(
  75        PhabricatorPastePastePHIDType::TYPECONST);
  76    }
  77  
  78    public function save() {
  79      if (!$this->getMailKey()) {
  80        $this->setMailKey(Filesystem::readRandomCharacters(20));
  81      }
  82      return parent::save();
  83    }
  84  
  85    public function getFullName() {
  86      $title = $this->getTitle();
  87      if (!$title) {
  88        $title = pht('(An Untitled Masterwork)');
  89      }
  90      return 'P'.$this->getID().' '.$title;
  91    }
  92  
  93    public function getContent() {
  94      return $this->assertAttached($this->content);
  95    }
  96  
  97    public function attachContent($content) {
  98      $this->content = $content;
  99      return $this;
 100    }
 101  
 102    public function getRawContent() {
 103      return $this->assertAttached($this->rawContent);
 104    }
 105  
 106    public function attachRawContent($raw_content) {
 107      $this->rawContent = $raw_content;
 108      return $this;
 109    }
 110  
 111  /* -(  PhabricatorSubscribableInterface  )----------------------------------- */
 112  
 113  
 114    public function isAutomaticallySubscribed($phid) {
 115      return ($this->authorPHID == $phid);
 116    }
 117  
 118    public function shouldShowSubscribersProperty() {
 119      return true;
 120    }
 121  
 122    public function shouldAllowSubscription($phid) {
 123      return true;
 124    }
 125  
 126  
 127  /* -(  PhabricatorTokenReceiverInterface  )---------------------------------- */
 128  
 129    public function getUsersToNotifyOfTokenGiven() {
 130      return array(
 131        $this->getAuthorPHID(),
 132      );
 133    }
 134  
 135  
 136  /* -(  PhabricatorPolicyInterface  )----------------------------------------- */
 137  
 138  
 139    public function getCapabilities() {
 140      return array(
 141        PhabricatorPolicyCapability::CAN_VIEW,
 142        PhabricatorPolicyCapability::CAN_EDIT,
 143      );
 144    }
 145  
 146    public function getPolicy($capability) {
 147      if ($capability == PhabricatorPolicyCapability::CAN_VIEW) {
 148        return $this->viewPolicy;
 149      }
 150      return PhabricatorPolicies::POLICY_NOONE;
 151    }
 152  
 153    public function hasAutomaticCapability($capability, PhabricatorUser $user) {
 154      return ($user->getPHID() == $this->getAuthorPHID());
 155    }
 156  
 157    public function describeAutomaticCapability($capability) {
 158      return pht('The author of a paste can always view and edit it.');
 159    }
 160  
 161  
 162  /* -(  PhabricatorDestructibleInterface  )----------------------------------- */
 163  
 164  
 165    public function destroyObjectPermanently(
 166      PhabricatorDestructionEngine $engine) {
 167  
 168      if ($this->filePHID) {
 169        $file = id(new PhabricatorFileQuery())
 170          ->setViewer(PhabricatorUser::getOmnipotentUser())
 171          ->withPHIDs(array($this->filePHID))
 172          ->executeOne();
 173        if ($file) {
 174          $engine->destroyObject($file);
 175        }
 176      }
 177  
 178      $this->delete();
 179    }
 180  
 181  
 182  /* -(  PhabricatorApplicationTransactionInterface  )------------------------- */
 183  
 184  
 185    public function getApplicationTransactionEditor() {
 186      return new PhabricatorPasteEditor();
 187    }
 188  
 189    public function getApplicationTransactionObject() {
 190      return $this;
 191    }
 192  
 193    public function getApplicationTransactionTemplate() {
 194      return new PhabricatorPasteTransaction();
 195    }
 196  
 197  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1