[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/maniphest/storage/ -> ManiphestTask.php (source)

   1  <?php
   2  
   3  final class ManiphestTask extends ManiphestDAO
   4    implements
   5      PhabricatorMarkupInterface,
   6      PhabricatorPolicyInterface,
   7      PhabricatorTokenReceiverInterface,
   8      PhabricatorFlaggableInterface,
   9      PhabricatorMentionableInterface,
  10      PhrequentTrackableInterface,
  11      PhabricatorCustomFieldInterface,
  12      PhabricatorDestructibleInterface,
  13      PhabricatorApplicationTransactionInterface,
  14      PhabricatorProjectInterface {
  15  
  16    const MARKUP_FIELD_DESCRIPTION = 'markup:desc';
  17  
  18    protected $authorPHID;
  19    protected $ownerPHID;
  20    protected $ccPHIDs = array();
  21  
  22    protected $status;
  23    protected $priority;
  24    protected $subpriority = 0;
  25  
  26    protected $title = '';
  27    protected $originalTitle = '';
  28    protected $description = '';
  29    protected $originalEmailSource;
  30    protected $mailKey;
  31    protected $viewPolicy = PhabricatorPolicies::POLICY_USER;
  32    protected $editPolicy = PhabricatorPolicies::POLICY_USER;
  33  
  34    protected $attached = array();
  35    protected $projectPHIDs = array();
  36    private $subscribersNeedUpdate;
  37  
  38    protected $ownerOrdering;
  39  
  40    private $groupByProjectPHID = self::ATTACHABLE;
  41    private $customFields = self::ATTACHABLE;
  42    private $edgeProjectPHIDs = self::ATTACHABLE;
  43  
  44    public static function initializeNewTask(PhabricatorUser $actor) {
  45      $app = id(new PhabricatorApplicationQuery())
  46        ->setViewer($actor)
  47        ->withClasses(array('PhabricatorManiphestApplication'))
  48        ->executeOne();
  49  
  50      $view_policy = $app->getPolicy(ManiphestDefaultViewCapability::CAPABILITY);
  51      $edit_policy = $app->getPolicy(ManiphestDefaultEditCapability::CAPABILITY);
  52  
  53      return id(new ManiphestTask())
  54        ->setStatus(ManiphestTaskStatus::getDefaultStatus())
  55        ->setPriority(ManiphestTaskPriority::getDefaultPriority())
  56        ->setAuthorPHID($actor->getPHID())
  57        ->setViewPolicy($view_policy)
  58        ->setEditPolicy($edit_policy)
  59        ->attachProjectPHIDs(array());
  60    }
  61  
  62    public function getConfiguration() {
  63      return array(
  64        self::CONFIG_AUX_PHID => true,
  65        self::CONFIG_SERIALIZATION => array(
  66          'ccPHIDs' => self::SERIALIZATION_JSON,
  67          'attached' => self::SERIALIZATION_JSON,
  68          'projectPHIDs' => self::SERIALIZATION_JSON,
  69        ),
  70        self::CONFIG_COLUMN_SCHEMA => array(
  71          'ownerPHID' => 'phid?',
  72          'status' => 'text12',
  73          'priority' => 'uint32',
  74          'title' => 'sort',
  75          'originalTitle' => 'text',
  76          'description' => 'text',
  77          'mailKey' => 'bytes20',
  78          'ownerOrdering' => 'text64?',
  79          'originalEmailSource' => 'text255?',
  80          'subpriority' => 'double',
  81  
  82          // T6203/NULLABILITY
  83          // This should not be nullable. It's going away soon anyway.
  84          'ccPHIDs' => 'text?',
  85  
  86        ),
  87        self::CONFIG_KEY_SCHEMA => array(
  88          'key_phid' => null,
  89          'phid' => array(
  90            'columns' => array('phid'),
  91            'unique' => true,
  92          ),
  93          'priority' => array(
  94            'columns' => array('priority', 'status'),
  95          ),
  96          'status' => array(
  97            'columns' => array('status'),
  98          ),
  99          'ownerPHID' => array(
 100            'columns' => array('ownerPHID', 'status'),
 101          ),
 102          'authorPHID' => array(
 103            'columns' => array('authorPHID', 'status'),
 104          ),
 105          'ownerOrdering' => array(
 106            'columns' => array('ownerOrdering'),
 107          ),
 108          'priority_2' => array(
 109            'columns' => array('priority', 'subpriority'),
 110          ),
 111          'key_dateCreated' => array(
 112            'columns' => array('dateCreated'),
 113          ),
 114          'key_dateModified' => array(
 115            'columns' => array('dateModified'),
 116          ),
 117          'key_title' => array(
 118            'columns' => array('title(64)'),
 119          ),
 120        ),
 121      ) + parent::getConfiguration();
 122    }
 123  
 124    public function loadDependsOnTaskPHIDs() {
 125      return PhabricatorEdgeQuery::loadDestinationPHIDs(
 126        $this->getPHID(),
 127        PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK);
 128    }
 129  
 130    public function loadDependedOnByTaskPHIDs() {
 131      return PhabricatorEdgeQuery::loadDestinationPHIDs(
 132        $this->getPHID(),
 133        PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK);
 134    }
 135  
 136    public function getAttachedPHIDs($type) {
 137      return array_keys(idx($this->attached, $type, array()));
 138    }
 139  
 140    public function generatePHID() {
 141      return PhabricatorPHID::generateNewPHID(ManiphestTaskPHIDType::TYPECONST);
 142    }
 143  
 144    public function getCCPHIDs() {
 145      return array_values(nonempty($this->ccPHIDs, array()));
 146    }
 147  
 148    public function getProjectPHIDs() {
 149      return $this->assertAttached($this->edgeProjectPHIDs);
 150    }
 151  
 152    public function attachProjectPHIDs(array $phids) {
 153      $this->edgeProjectPHIDs = $phids;
 154      return $this;
 155    }
 156  
 157    public function setCCPHIDs(array $phids) {
 158      $this->ccPHIDs = array_values($phids);
 159      $this->subscribersNeedUpdate = true;
 160      return $this;
 161    }
 162  
 163    public function setOwnerPHID($phid) {
 164      $this->ownerPHID = nonempty($phid, null);
 165      $this->subscribersNeedUpdate = true;
 166      return $this;
 167    }
 168  
 169    public function setTitle($title) {
 170      $this->title = $title;
 171      if (!$this->getID()) {
 172        $this->originalTitle = $title;
 173      }
 174      return $this;
 175    }
 176  
 177    public function getMonogram() {
 178      return 'T'.$this->getID();
 179    }
 180  
 181    public function attachGroupByProjectPHID($phid) {
 182      $this->groupByProjectPHID = $phid;
 183      return $this;
 184    }
 185  
 186    public function getGroupByProjectPHID() {
 187      return $this->assertAttached($this->groupByProjectPHID);
 188    }
 189  
 190    public function save() {
 191      if (!$this->mailKey) {
 192        $this->mailKey = Filesystem::readRandomCharacters(20);
 193      }
 194  
 195      $result = parent::save();
 196  
 197      if ($this->subscribersNeedUpdate) {
 198        // If we've changed the subscriber PHIDs for this task, update the link
 199        // table.
 200        ManiphestTaskSubscriber::updateTaskSubscribers($this);
 201        $this->subscribersNeedUpdate = false;
 202      }
 203  
 204      return $result;
 205    }
 206  
 207    public function isClosed() {
 208      return ManiphestTaskStatus::isClosedStatus($this->getStatus());
 209    }
 210  
 211    public function getPrioritySortVector() {
 212      return array(
 213        $this->getPriority(),
 214        -$this->getSubpriority(),
 215        $this->getID(),
 216      );
 217    }
 218  
 219  
 220  /* -(  Markup Interface  )--------------------------------------------------- */
 221  
 222  
 223    /**
 224     * @task markup
 225     */
 226    public function getMarkupFieldKey($field) {
 227      $hash = PhabricatorHash::digest($this->getMarkupText($field));
 228      $id = $this->getID();
 229      return "maniphest:T{$id}:{$field}:{$hash}";
 230    }
 231  
 232  
 233    /**
 234     * @task markup
 235     */
 236    public function getMarkupText($field) {
 237      return $this->getDescription();
 238    }
 239  
 240  
 241    /**
 242     * @task markup
 243     */
 244    public function newMarkupEngine($field) {
 245      return PhabricatorMarkupEngine::newManiphestMarkupEngine();
 246    }
 247  
 248  
 249    /**
 250     * @task markup
 251     */
 252    public function didMarkupText(
 253      $field,
 254      $output,
 255      PhutilMarkupEngine $engine) {
 256      return $output;
 257    }
 258  
 259  
 260    /**
 261     * @task markup
 262     */
 263    public function shouldUseMarkupCache($field) {
 264      return (bool)$this->getID();
 265    }
 266  
 267  
 268  /* -(  Policy Interface  )--------------------------------------------------- */
 269  
 270  
 271    public function getCapabilities() {
 272      return array(
 273        PhabricatorPolicyCapability::CAN_VIEW,
 274        PhabricatorPolicyCapability::CAN_EDIT,
 275      );
 276    }
 277  
 278    public function getPolicy($capability) {
 279      switch ($capability) {
 280        case PhabricatorPolicyCapability::CAN_VIEW:
 281          return $this->getViewPolicy();
 282        case PhabricatorPolicyCapability::CAN_EDIT:
 283          return $this->getEditPolicy();
 284      }
 285    }
 286  
 287    public function hasAutomaticCapability($capability, PhabricatorUser $user) {
 288      // The owner of a task can always view and edit it.
 289      $owner_phid = $this->getOwnerPHID();
 290      if ($owner_phid) {
 291        $user_phid = $user->getPHID();
 292        if ($user_phid == $owner_phid) {
 293          return true;
 294        }
 295      }
 296  
 297      return false;
 298    }
 299  
 300    public function describeAutomaticCapability($capability) {
 301      return pht('The owner of a task can always view and edit it.');
 302    }
 303  
 304  
 305  /* -(  PhabricatorTokenReceiverInterface  )---------------------------------- */
 306  
 307  
 308    public function getUsersToNotifyOfTokenGiven() {
 309      // Sort of ambiguous who this was intended for; just let them both know.
 310      return array_filter(
 311        array_unique(
 312          array(
 313            $this->getAuthorPHID(),
 314            $this->getOwnerPHID(),
 315          )));
 316    }
 317  
 318  
 319  /* -(  PhabricatorCustomFieldInterface  )------------------------------------ */
 320  
 321  
 322    public function getCustomFieldSpecificationForRole($role) {
 323      return PhabricatorEnv::getEnvConfig('maniphest.fields');
 324    }
 325  
 326    public function getCustomFieldBaseClass() {
 327      return 'ManiphestCustomField';
 328    }
 329  
 330    public function getCustomFields() {
 331      return $this->assertAttached($this->customFields);
 332    }
 333  
 334    public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) {
 335      $this->customFields = $fields;
 336      return $this;
 337    }
 338  
 339  
 340  /* -(  PhabricatorDestructibleInterface  )----------------------------------- */
 341  
 342  
 343    public function destroyObjectPermanently(
 344      PhabricatorDestructionEngine $engine) {
 345  
 346      $this->openTransaction();
 347  
 348        // TODO: Once this implements PhabricatorTransactionInterface, this
 349        // will be handled automatically and can be removed.
 350        $xactions = id(new ManiphestTransaction())->loadAllWhere(
 351          'objectPHID = %s',
 352          $this->getPHID());
 353        foreach ($xactions as $xaction) {
 354          $engine->destroyObject($xaction);
 355        }
 356  
 357        $this->delete();
 358      $this->saveTransaction();
 359    }
 360  
 361  
 362  /* -(  PhabricatorApplicationTransactionInterface  )------------------------- */
 363  
 364  
 365    public function getApplicationTransactionEditor() {
 366      return new ManiphestTransactionEditor();
 367    }
 368  
 369    public function getApplicationTransactionObject() {
 370      return $this;
 371    }
 372  
 373    public function getApplicationTransactionTemplate() {
 374      return new ManiphestTransaction();
 375    }
 376  
 377  }


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