Changeset View
Changeset View
Standalone View
Standalone View
src/applications/maniphest/editor/ManiphestTransactionEditor.php
Show All 21 Lines | public function getTransactionTypes() { | ||||
$types[] = ManiphestTransaction::TYPE_DESCRIPTION; | $types[] = ManiphestTransaction::TYPE_DESCRIPTION; | ||||
$types[] = ManiphestTransaction::TYPE_OWNER; | $types[] = ManiphestTransaction::TYPE_OWNER; | ||||
$types[] = ManiphestTransaction::TYPE_SUBPRIORITY; | $types[] = ManiphestTransaction::TYPE_SUBPRIORITY; | ||||
$types[] = ManiphestTransaction::TYPE_PROJECT_COLUMN; | $types[] = ManiphestTransaction::TYPE_PROJECT_COLUMN; | ||||
$types[] = ManiphestTransaction::TYPE_MERGED_INTO; | $types[] = ManiphestTransaction::TYPE_MERGED_INTO; | ||||
$types[] = ManiphestTransaction::TYPE_MERGED_FROM; | $types[] = ManiphestTransaction::TYPE_MERGED_FROM; | ||||
$types[] = ManiphestTransaction::TYPE_UNBLOCK; | $types[] = ManiphestTransaction::TYPE_UNBLOCK; | ||||
$types[] = ManiphestTransaction::TYPE_PARENT; | $types[] = ManiphestTransaction::TYPE_PARENT; | ||||
$types[] = ManiphestTransaction::TYPE_COLUMN; | |||||
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; | $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; | ||||
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; | $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; | ||||
return $types; | return $types; | ||||
} | } | ||||
protected function getCustomTransactionOldValue( | protected function getCustomTransactionOldValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
Show All 26 Lines | switch ($xaction->getTransactionType()) { | ||||
// These are pre-populated. | // These are pre-populated. | ||||
return $xaction->getOldValue(); | return $xaction->getOldValue(); | ||||
case ManiphestTransaction::TYPE_SUBPRIORITY: | case ManiphestTransaction::TYPE_SUBPRIORITY: | ||||
return $object->getSubpriority(); | return $object->getSubpriority(); | ||||
case ManiphestTransaction::TYPE_MERGED_INTO: | case ManiphestTransaction::TYPE_MERGED_INTO: | ||||
case ManiphestTransaction::TYPE_MERGED_FROM: | case ManiphestTransaction::TYPE_MERGED_FROM: | ||||
return null; | return null; | ||||
case ManiphestTransaction::TYPE_PARENT: | case ManiphestTransaction::TYPE_PARENT: | ||||
case ManiphestTransaction::TYPE_COLUMN: | |||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
protected function getCustomTransactionNewValue( | protected function getCustomTransactionNewValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case ManiphestTransaction::TYPE_PRIORITY: | case ManiphestTransaction::TYPE_PRIORITY: | ||||
return (int)$xaction->getNewValue(); | return (int)$xaction->getNewValue(); | ||||
case ManiphestTransaction::TYPE_OWNER: | case ManiphestTransaction::TYPE_OWNER: | ||||
return nonempty($xaction->getNewValue(), null); | return nonempty($xaction->getNewValue(), null); | ||||
case ManiphestTransaction::TYPE_STATUS: | case ManiphestTransaction::TYPE_STATUS: | ||||
case ManiphestTransaction::TYPE_TITLE: | case ManiphestTransaction::TYPE_TITLE: | ||||
case ManiphestTransaction::TYPE_DESCRIPTION: | case ManiphestTransaction::TYPE_DESCRIPTION: | ||||
case ManiphestTransaction::TYPE_SUBPRIORITY: | case ManiphestTransaction::TYPE_SUBPRIORITY: | ||||
case ManiphestTransaction::TYPE_PROJECT_COLUMN: | case ManiphestTransaction::TYPE_PROJECT_COLUMN: | ||||
case ManiphestTransaction::TYPE_MERGED_INTO: | case ManiphestTransaction::TYPE_MERGED_INTO: | ||||
case ManiphestTransaction::TYPE_MERGED_FROM: | case ManiphestTransaction::TYPE_MERGED_FROM: | ||||
case ManiphestTransaction::TYPE_UNBLOCK: | case ManiphestTransaction::TYPE_UNBLOCK: | ||||
return $xaction->getNewValue(); | return $xaction->getNewValue(); | ||||
case ManiphestTransaction::TYPE_PARENT: | case ManiphestTransaction::TYPE_PARENT: | ||||
case ManiphestTransaction::TYPE_COLUMN: | |||||
return $xaction->getNewValue(); | return $xaction->getNewValue(); | ||||
} | } | ||||
} | } | ||||
protected function transactionHasEffect( | protected function transactionHasEffect( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | switch ($xaction->getTransactionType()) { | ||||
return; | return; | ||||
case ManiphestTransaction::TYPE_PROJECT_COLUMN: | case ManiphestTransaction::TYPE_PROJECT_COLUMN: | ||||
// these do external (edge) updates | // these do external (edge) updates | ||||
return; | return; | ||||
case ManiphestTransaction::TYPE_MERGED_INTO: | case ManiphestTransaction::TYPE_MERGED_INTO: | ||||
$object->setStatus(ManiphestTaskStatus::getDuplicateStatus()); | $object->setStatus(ManiphestTaskStatus::getDuplicateStatus()); | ||||
return; | return; | ||||
case ManiphestTransaction::TYPE_MERGED_FROM: | case ManiphestTransaction::TYPE_MERGED_FROM: | ||||
return; | |||||
case ManiphestTransaction::TYPE_PARENT: | case ManiphestTransaction::TYPE_PARENT: | ||||
case ManiphestTransaction::TYPE_COLUMN: | |||||
return; | return; | ||||
} | } | ||||
} | } | ||||
protected function applyCustomExternalTransaction( | protected function applyCustomExternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
▲ Show 20 Lines • Show All 580 Lines • ▼ Show 20 Lines | switch ($type) { | ||||
pht('Task title is required.'), | pht('Task title is required.'), | ||||
nonempty(last($xactions), null)); | nonempty(last($xactions), null)); | ||||
$error->setIsMissingFieldError(true); | $error->setIsMissingFieldError(true); | ||||
$errors[] = $error; | $errors[] = $error; | ||||
} | } | ||||
break; | break; | ||||
case ManiphestTransaction::TYPE_PARENT: | case ManiphestTransaction::TYPE_PARENT: | ||||
if ($xactions && !$this->getIsNewObject()) { | $with_effect = array(); | ||||
$error = new PhabricatorApplicationTransactionValidationError( | foreach ($xactions as $xaction) { | ||||
$task_phid = $xaction->getNewValue(); | |||||
if (!$task_phid) { | |||||
continue; | |||||
} | |||||
$with_effect[] = $xaction; | |||||
$task = id(new ManiphestTaskQuery()) | |||||
->setViewer($this->getActor()) | |||||
->withPHIDs(array($task_phid)) | |||||
->executeOne(); | |||||
if (!$task) { | |||||
$errors[] = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Invalid'), | |||||
pht( | |||||
'Parent task identifier "%s" does not identify a visible '. | |||||
'task.', | |||||
$task_phid), | |||||
$xaction); | |||||
} | |||||
} | |||||
if ($with_effect && !$this->getIsNewObject()) { | |||||
$errors[] = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | $type, | ||||
pht('Invalid'), | pht('Invalid'), | ||||
pht( | pht( | ||||
'You can only select a parent task when creating a '. | 'You can only select a parent task when creating a '. | ||||
'transaction for the first time.'), | 'transaction for the first time.'), | ||||
last($xactions)); | last($with_effect)); | ||||
} | |||||
break; | |||||
case ManiphestTransaction::TYPE_COLUMN: | |||||
$with_effect = array(); | |||||
foreach ($xactions as $xaction) { | |||||
$column_phid = $xaction->getNewValue(); | |||||
if (!$column_phid) { | |||||
continue; | |||||
} | |||||
$with_effect[] = $xaction; | |||||
$column = $this->loadProjectColumn($column_phid); | |||||
if (!$column) { | |||||
$errors[] = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Invalid'), | |||||
pht( | |||||
'Column PHID "%s" does not identify a visible column.', | |||||
$column_phid), | |||||
$xaction); | |||||
} | |||||
} | |||||
if ($with_effect && !$this->getIsNewObject()) { | |||||
$errors[] = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Invalid'), | |||||
pht( | |||||
'You can only put a task into an initial column during task '. | |||||
'creation.'), | |||||
last($with_effect)); | |||||
} | } | ||||
break; | break; | ||||
} | } | ||||
return $errors; | return $errors; | ||||
} | } | ||||
protected function expandTransactions( | protected function expandTransactions( | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | final class ManiphestTransactionEditor | ||||
protected function expandTransaction( | protected function expandTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
$results = parent::expandTransaction($object, $xaction); | $results = parent::expandTransaction($object, $xaction); | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case ManiphestTransaction::TYPE_COLUMN: | |||||
$column_phid = $xaction->getNewValue(); | |||||
if (!$column_phid) { | |||||
break; | |||||
} | |||||
// When a task is created into a column, we also generate a transaction | |||||
// to actually put it in that column. | |||||
$column = $this->loadProjectColumn($column_phid); | |||||
$results[] = id(new ManiphestTransaction()) | |||||
->setTransactionType(ManiphestTransaction::TYPE_PROJECT_COLUMN) | |||||
->setOldValue( | |||||
array( | |||||
'projectPHID' => $column->getProjectPHID(), | |||||
'columnPHIDs' => array(), | |||||
)) | |||||
->setNewValue( | |||||
array( | |||||
'projectPHID' => $column->getProjectPHID(), | |||||
'columnPHIDs' => array($column->getPHID()), | |||||
)); | |||||
break; | |||||
case ManiphestTransaction::TYPE_OWNER: | case ManiphestTransaction::TYPE_OWNER: | ||||
// When a task is reassigned, move the old owner to the subscriber | // When a task is reassigned, move the old owner to the subscriber | ||||
// list so they're still in the loop. | // list so they're still in the loop. | ||||
$owner_phid = $object->getOwnerPHID(); | $owner_phid = $object->getOwnerPHID(); | ||||
if ($owner_phid) { | if ($owner_phid) { | ||||
$results[] = id(new ManiphestTransaction()) | $results[] = id(new ManiphestTransaction()) | ||||
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) | ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) | ||||
->setIgnoreOnNoEffect(true) | ->setIgnoreOnNoEffect(true) | ||||
->setNewValue( | ->setNewValue( | ||||
array( | array( | ||||
'+' => array($owner_phid => $owner_phid), | '+' => array($owner_phid => $owner_phid), | ||||
)); | )); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
return $results; | return $results; | ||||
} | } | ||||
private function loadProjectColumn($column_phid) { | |||||
return id(new PhabricatorProjectColumnQuery()) | |||||
->setViewer($this->getActor()) | |||||
->withPHIDs(array($column_phid)) | |||||
->executeOne(); | |||||
} | |||||
} | } |