Path: blob/master/src/applications/maniphest/xaction/ManiphestTaskPriorityTransaction.php
12256 views
<?php12final class ManiphestTaskPriorityTransaction3extends ManiphestTaskTransactionType {45const TRANSACTIONTYPE = 'priority';67public function generateOldValue($object) {8return (string)$object->getPriority();9}1011public function generateNewValue($object, $value) {12// `$value` is supposed to be a keyword, but if the priority13// assigned to a task has been removed from the config,14// no such keyword will be available. Other edits to the task15// should still be allowed, even if the priority is no longer16// valid, so treat this as a no-op.17if ($value === ManiphestTaskPriority::UNKNOWN_PRIORITY_KEYWORD) {18return (string)$object->getPriority();19}2021return (string)ManiphestTaskPriority::getTaskPriorityFromKeyword($value);22}2324public function applyInternalEffects($object, $value) {25$object->setPriority($value);26}2728public function getActionStrength() {29return 110;30}3132public function getActionName() {33$old = $this->getOldValue();34$new = $this->getNewValue();3536if ($old == ManiphestTaskPriority::getDefaultPriority()) {37return pht('Triaged');38} else if ($old > $new) {39return pht('Lowered Priority');40} else {41return pht('Raised Priority');42}43}4445public function getTitle() {46$old = $this->getOldValue();47$new = $this->getNewValue();4849$old_name = ManiphestTaskPriority::getTaskPriorityName($old);50$new_name = ManiphestTaskPriority::getTaskPriorityName($new);5152if ($old == ManiphestTaskPriority::getDefaultPriority()) {53return pht(54'%s triaged this task as %s priority.',55$this->renderAuthor(),56$this->renderValue($new_name));57} else if ($old > $new) {58return pht(59'%s lowered the priority of this task from %s to %s.',60$this->renderAuthor(),61$this->renderValue($old_name),62$this->renderValue($new_name));63} else {64return pht(65'%s raised the priority of this task from %s to %s.',66$this->renderAuthor(),67$this->renderValue($old_name),68$this->renderValue($new_name));69}70}7172public function getTitleForFeed() {73$old = $this->getOldValue();74$new = $this->getNewValue();7576$old_name = ManiphestTaskPriority::getTaskPriorityName($old);77$new_name = ManiphestTaskPriority::getTaskPriorityName($new);7879if ($old == ManiphestTaskPriority::getDefaultPriority()) {80return pht(81'%s triaged %s as %s priority.',82$this->renderAuthor(),83$this->renderObject(),84$this->renderValue($new_name));85} else if ($old > $new) {86return pht(87'%s lowered the priority of %s from %s to %s.',88$this->renderAuthor(),89$this->renderObject(),90$this->renderValue($old_name),91$this->renderValue($new_name));92} else {93return pht(94'%s raised the priority of %s from %s to %s.',95$this->renderAuthor(),96$this->renderObject(),97$this->renderValue($old_name),98$this->renderValue($new_name));99}100}101102public function getIcon() {103$old = $this->getOldValue();104$new = $this->getNewValue();105106if ($old == ManiphestTaskPriority::getDefaultPriority()) {107return 'fa-arrow-right';108} else if ($old > $new) {109return 'fa-arrow-down';110} else {111return 'fa-arrow-up';112}113}114115public function getColor() {116$old = $this->getOldValue();117$new = $this->getNewValue();118119if ($old == ManiphestTaskPriority::getDefaultPriority()) {120return 'green';121} else if ($old > $new) {122return 'grey';123} else {124return 'yellow';125}126}127128public function validateTransactions($object, array $xactions) {129$errors = array();130131$content_source = $this->getEditor()->getContentSource();132$is_web = ($content_source instanceof PhabricatorWebContentSource);133134foreach ($xactions as $xaction) {135$value = $xaction->getNewValue();136137// If this is a legitimate keyword like "low" or "high", this transaction138// is fine and apply normally.139$keyword = ManiphestTaskPriority::getTaskPriorityFromKeyword($value);140if ($keyword !== null) {141continue;142}143144// If this is the magic "don't change things" value for editing tasks145// with an obsolete priority constant in the database, let it through if146// this is a web edit.147if ($value === ManiphestTaskPriority::UNKNOWN_PRIORITY_KEYWORD) {148if ($is_web) {149continue;150}151}152153$keyword_list = array();154foreach (ManiphestTaskPriority::getTaskPriorityMap() as $pri => $name) {155$keyword = ManiphestTaskPriority::getKeywordForTaskPriority($pri);156if ($keyword === null) {157continue;158}159$keyword_list[] = $keyword;160}161162$errors[] = $this->newInvalidError(163pht(164'Task priority "%s" is not a valid task priority. Use a priority '.165'keyword to choose a task priority: %s.',166$value,167implode(', ', $keyword_list)),168$xaction);169}170171return $errors;172}173174public function getTransactionTypeForConduit($xaction) {175return 'priority';176}177178public function getFieldValuesForConduit($xaction, $data) {179$old = $xaction->getOldValue();180if ($old !== null) {181$old = (int)$old;182$old_name = ManiphestTaskPriority::getTaskPriorityName($old);183} else {184$old_name = null;185}186187$new = $xaction->getNewValue();188$new = (int)$new;189$new_name = ManiphestTaskPriority::getTaskPriorityName($new);190191return array(192'old' => array(193'value' => $old,194'name' => $old_name,195),196'new' => array(197'value' => $new,198'name' => $new_name,199),200);201}202203}204205206