Differential D21533 Diff 51254 src/applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php
| <?php | <?php | ||||
| abstract class PhabricatorRepositoryCommitParserWorker | abstract class PhabricatorRepositoryCommitParserWorker | ||||
| extends PhabricatorWorker { | extends PhabricatorWorker { | ||||
| protected $commit; | protected $commit; | ||||
| protected $repository; | protected $repository; | ||||
| private function loadCommit() { | private function loadCommit() { | ||||
| if ($this->commit) { | if ($this->commit) { | ||||
| return $this->commit; | return $this->commit; | ||||
| } | } | ||||
| $commit_id = idx($this->getTaskData(), 'commitID'); | $viewer = $this->getViewer(); | ||||
| if (!$commit_id) { | $task_data = $this->getTaskData(); | ||||
| $commit_query = id(new DiffusionCommitQuery()) | |||||
| ->setViewer($viewer); | |||||
| $commit_phid = idx($task_data, 'commitPHID'); | |||||
| // TODO: See T13591. This supports execution of legacy tasks and can | |||||
Lint: TODO Comment: This comment has a TODO. | |||||
| // eventually be removed. Newer tasks use "commitPHID" instead of | |||||
| // "commitID". | |||||
| if (!$commit_phid) { | |||||
| $commit_id = idx($task_data, 'commitID'); | |||||
| if ($commit_id) { | |||||
| $legacy_commit = id(clone $commit_query) | |||||
| ->withIDs(array($commit_id)) | |||||
| ->executeOne(); | |||||
| if ($legacy_commit) { | |||||
| $commit_phid = $legacy_commit->getPHID(); | |||||
| } | |||||
| } | |||||
| } | |||||
| if (!$commit_phid) { | |||||
| throw new PhabricatorWorkerPermanentFailureException( | throw new PhabricatorWorkerPermanentFailureException( | ||||
| pht('No "%s" in task data.', 'commitID')); | pht('Task data has no "commitPHID".')); | ||||
| } | } | ||||
| $commit = id(new DiffusionCommitQuery()) | $commit = id(clone $commit_query) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->withPHIDs(array($commit_phid)) | ||||
| ->withIDs(array($commit_id)) | |||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$commit) { | if (!$commit) { | ||||
| throw new PhabricatorWorkerPermanentFailureException( | throw new PhabricatorWorkerPermanentFailureException( | ||||
| pht('Commit "%s" does not exist.', $commit_id)); | pht('Commit "%s" does not exist.', $commit_phid)); | ||||
| } | } | ||||
| if ($commit->isUnreachable()) { | if ($commit->isUnreachable()) { | ||||
| throw new PhabricatorWorkerPermanentFailureException( | throw new PhabricatorWorkerPermanentFailureException( | ||||
| pht( | pht( | ||||
| 'Commit "%s" (with internal ID "%s") is no longer reachable from '. | 'Commit "%s" (with PHID "%s") is no longer reachable from any '. | ||||
| 'any branch, tag, or ref in this repository, so it will not be '. | 'branch, tag, or ref in this repository, so it will not be '. | ||||
| 'imported. This usually means that the branch the commit was on '. | 'imported. This usually means that the branch the commit was on '. | ||||
| 'was deleted or overwritten.', | 'was deleted or overwritten.', | ||||
| $commit->getMonogram(), | $commit->getMonogram(), | ||||
| $commit_id)); | $commit_phid)); | ||||
| } | } | ||||
| $this->commit = $commit; | $this->commit = $commit; | ||||
| return $commit; | return $commit; | ||||
| } | } | ||||
| final protected function doWork() { | final protected function doWork() { | ||||
| Show All 13 Lines | final protected function queueCommitTask($task_class) { | ||||
| if (!$this->shouldQueueFollowupTasks()) { | if (!$this->shouldQueueFollowupTasks()) { | ||||
| return; | return; | ||||
| } | } | ||||
| $commit = $this->loadCommit(); | $commit = $this->loadCommit(); | ||||
| $repository = $commit->getRepository(); | $repository = $commit->getRepository(); | ||||
| $data = array( | $data = array( | ||||
| 'commitID' => $commit->getID(), | 'commitPHID' => $commit->getPHID(), | ||||
| ); | ); | ||||
| $task_data = $this->getTaskData(); | $task_data = $this->getTaskData(); | ||||
| if (isset($task_data['via'])) { | if (isset($task_data['via'])) { | ||||
| $data['via'] = $task_data['via']; | $data['via'] = $task_data['via']; | ||||
| } | } | ||||
| $options = array( | $options = array( | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | return id(new DiffusionCommitHintQuery()) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| } | } | ||||
| public function renderForDisplay(PhabricatorUser $viewer) { | public function renderForDisplay(PhabricatorUser $viewer) { | ||||
| $suffix = parent::renderForDisplay($viewer); | $suffix = parent::renderForDisplay($viewer); | ||||
| $commit = id(new DiffusionCommitQuery()) | $commit = id(new DiffusionCommitQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withIDs(array(idx($this->getTaskData(), 'commitID'))) | ->withPHIDs(array(idx($this->getTaskData(), 'commitPHID'))) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$commit) { | if (!$commit) { | ||||
| return $suffix; | return $suffix; | ||||
| } | } | ||||
| $link = DiffusionView::linkCommit( | $link = DiffusionView::linkCommit( | ||||
| $commit->getRepository(), | $commit->getRepository(), | ||||
| $commit->getCommitIdentifier()); | $commit->getCommitIdentifier()); | ||||
| Show All 29 Lines | |||||
This comment has a TODO.