Changeset View
Changeset View
Standalone View
Standalone View
src/applications/maniphest/editor/ManiphestTransactionEditor.php
| <?php | <?php | ||||
| final class ManiphestTransactionEditor | final class ManiphestTransactionEditor | ||||
| extends PhabricatorApplicationTransactionEditor { | extends PhabricatorApplicationTransactionEditor { | ||||
| private $oldProjectPHIDs; | |||||
| private $moreValidationErrors = array(); | private $moreValidationErrors = array(); | ||||
| public function getEditorApplicationClass() { | public function getEditorApplicationClass() { | ||||
| return 'PhabricatorManiphestApplication'; | return 'PhabricatorManiphestApplication'; | ||||
| } | } | ||||
| public function getEditorObjectsDescription() { | public function getEditorObjectsDescription() { | ||||
| return pht('Maniphest Tasks'); | return pht('Maniphest Tasks'); | ||||
| ▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | if ($this->getIsNewObject()) { | ||||
| ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) | ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) | ||||
| ->setNewValue( | ->setNewValue( | ||||
| array( | array( | ||||
| '+' => array($actor_phid => $actor_phid), | '+' => array($actor_phid => $actor_phid), | ||||
| )); | )); | ||||
| } | } | ||||
| } | } | ||||
| $send_notifications = PhabricatorNotificationClient::isEnabled(); | |||||
| if ($send_notifications) { | |||||
| $this->oldProjectPHIDs = $this->loadProjectPHIDs($object); | |||||
| } | |||||
| return $results; | return $results; | ||||
| } | } | ||||
| protected function expandTransaction( | protected function expandTransaction( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
| $results = parent::expandTransaction($object, $xaction); | $results = parent::expandTransaction($object, $xaction); | ||||
| ▲ Show 20 Lines • Show All 465 Lines • ▼ Show 20 Lines | foreach ($phid_list as $key => $phid) { | ||||
| } | } | ||||
| unset($phid_list[$key]); | unset($phid_list[$key]); | ||||
| } | } | ||||
| return array_values($phid_list); | return array_values($phid_list); | ||||
| } | } | ||||
| protected function didApplyTransactions($object, array $xactions) { | protected function didApplyTransactions($object, array $xactions) { | ||||
| // TODO: This should include projects which the object was previously | $send_notifications = PhabricatorNotificationClient::isEnabled(); | ||||
| // associated with but no longer is (so it can be removed from those | if ($send_notifications) { | ||||
| // boards) but currently does not. | $old_phids = $this->oldProjectPHIDs; | ||||
| $new_phids = $this->loadProjectPHIDs($object); | |||||
| // We want to emit update notifications for all old and new tagged | |||||
| // projects, and all parents of those projects. For example, if an | |||||
| // edit removes project "A > B" from a task, the "A" workboard should | |||||
| // receive an update event. | |||||
| $edge_query = id(new PhabricatorEdgeQuery()) | $project_phids = array_fuse($old_phids) + array_fuse($new_phids); | ||||
| ->withSourcePHIDs(array($object->getPHID())) | $project_phids = array_keys($project_phids); | ||||
| ->withEdgeTypes( | |||||
| array( | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, | |||||
| )); | |||||
| $edge_query->execute(); | $projects = id(new PhabricatorProjectQuery()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
| ->withPHIDs($project_phids) | |||||
| ->execute(); | |||||
| $notify_projects = array(); | |||||
| foreach ($projects as $project) { | |||||
| $notify_projects[$project->getPHID()] = $project; | |||||
| foreach ($project->getAncestorProjects() as $ancestor) { | |||||
| $notify_projects[$ancestor->getPHID()] = $ancestor; | |||||
| } | |||||
| } | |||||
| $project_phids = $edge_query->getDestinationPHIDs(); | foreach ($notify_projects as $key => $project) { | ||||
| if (!$project->getHasWorkboard()) { | |||||
| unset($notify_projects[$key]); | |||||
| } | |||||
| } | |||||
| if ($project_phids) { | $notify_phids = array_keys($notify_projects); | ||||
| if ($notify_phids) { | |||||
| $data = array( | $data = array( | ||||
| 'type' => 'workboards', | 'type' => 'workboards', | ||||
| 'subscribers' => $project_phids, | 'subscribers' => $notify_phids, | ||||
| ); | ); | ||||
| PhabricatorNotificationClient::tryToPostMessage($data); | PhabricatorNotificationClient::tryToPostMessage($data); | ||||
| } | } | ||||
| } | |||||
| return $xactions; | return $xactions; | ||||
| } | } | ||||
| private function loadProjectPHIDs(ManiphestTask $task) { | |||||
| if (!$task->getPHID()) { | |||||
| return array(); | |||||
| } | |||||
| $edge_query = id(new PhabricatorEdgeQuery()) | |||||
| ->withSourcePHIDs(array($task->getPHID())) | |||||
| ->withEdgeTypes( | |||||
| array( | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, | |||||
| )); | |||||
| $edge_query->execute(); | |||||
| return $edge_query->getDestinationPHIDs(); | |||||
| } | |||||
| } | } | ||||