Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/editor/PhrictionTransactionEditor.php
| <?php | <?php | ||||
| final class PhrictionTransactionEditor | final class PhrictionTransactionEditor | ||||
| extends PhabricatorApplicationTransactionEditor { | extends PhabricatorApplicationTransactionEditor { | ||||
| const VALIDATE_CREATE_ANCESTRY = 'create'; | const VALIDATE_CREATE_ANCESTRY = 'create'; | ||||
| const VALIDATE_MOVE_ANCESTRY = 'move'; | const VALIDATE_MOVE_ANCESTRY = 'move'; | ||||
| private $description; | private $description; | ||||
| private $oldContent; | private $oldContent; | ||||
| private $newContent; | private $newContent; | ||||
| private $moveAwayDocument; | private $moveAwayDocument; | ||||
| private $skipAncestorCheck; | private $skipAncestorCheck; | ||||
| private $contentVersion; | private $contentVersion; | ||||
| private $processContentVersionError = true; | private $processContentVersionError = true; | ||||
| private $contentDiffURI; | |||||
| public function setDescription($description) { | public function setDescription($description) { | ||||
| $this->description = $description; | $this->description = $description; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| private function getDescription() { | private function getDescription() { | ||||
| return $this->description; | return $this->description; | ||||
| ▲ Show 20 Lines • Show All 319 Lines • ▼ Show 20 Lines | if ($this->moveAwayDocument !== null) { | ||||
| $sub_editor = id(new PhrictionTransactionEditor()) | $sub_editor = id(new PhrictionTransactionEditor()) | ||||
| ->setActor($this->getActor()) | ->setActor($this->getActor()) | ||||
| ->setContentSource($this->getContentSource()) | ->setContentSource($this->getContentSource()) | ||||
| ->setContinueOnNoEffect($this->getContinueOnNoEffect()) | ->setContinueOnNoEffect($this->getContinueOnNoEffect()) | ||||
| ->setDescription($this->getDescription()) | ->setDescription($this->getDescription()) | ||||
| ->applyTransactions($this->moveAwayDocument, $move_away_xactions); | ->applyTransactions($this->moveAwayDocument, $move_away_xactions); | ||||
| } | } | ||||
| // Compute the content diff URI for the publishing phase. | |||||
| foreach ($xactions as $xaction) { | |||||
| switch ($xaction->getTransactionType()) { | |||||
| case PhrictionTransaction::TYPE_CONTENT: | |||||
| $uri = id(new PhutilURI('/phriction/diff/'.$object->getID().'/')) | |||||
| ->alter('l', $this->getOldContent()->getVersion()) | |||||
| ->alter('r', $this->getNewContent()->getVersion()); | |||||
| $this->contentDiffURI = (string)$uri; | |||||
| break 2; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| } | |||||
| return $xactions; | return $xactions; | ||||
| } | } | ||||
| protected function shouldSendMail( | protected function shouldSendMail( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| array $xactions) { | array $xactions) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| Show All 39 Lines | protected function buildMailBody( | ||||
| array $xactions) { | array $xactions) { | ||||
| $body = parent::buildMailBody($object, $xactions); | $body = parent::buildMailBody($object, $xactions); | ||||
| if ($this->getIsNewObject()) { | if ($this->getIsNewObject()) { | ||||
| $body->addTextSection( | $body->addTextSection( | ||||
| pht('DOCUMENT CONTENT'), | pht('DOCUMENT CONTENT'), | ||||
| $object->getContent()->getContent()); | $object->getContent()->getContent()); | ||||
| } else { | } else if ($this->contentDiffURI) { | ||||
| foreach ($xactions as $xaction) { | |||||
| switch ($xaction->getTransactionType()) { | |||||
| case PhrictionTransaction::TYPE_CONTENT: | |||||
| $diff_uri = id(new PhutilURI( | |||||
| '/phriction/diff/'.$object->getID().'/')) | |||||
| ->alter('l', $this->getOldContent()->getVersion()) | |||||
| ->alter('r', $this->getNewContent()->getVersion()); | |||||
| $body->addLinkSection( | $body->addLinkSection( | ||||
| pht('DOCUMENT DIFF'), | pht('DOCUMENT DIFF'), | ||||
| PhabricatorEnv::getProductionURI($diff_uri)); | PhabricatorEnv::getProductionURI($this->contentDiffURI)); | ||||
| break 2; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| $body->addLinkSection( | $body->addLinkSection( | ||||
| pht('DOCUMENT DETAIL'), | pht('DOCUMENT DETAIL'), | ||||
| PhabricatorEnv::getProductionURI( | PhabricatorEnv::getProductionURI( | ||||
| PhrictionDocument::getSlugURI($object->getSlug()))); | PhrictionDocument::getSlugURI($object->getSlug()))); | ||||
| return $body; | return $body; | ||||
| ▲ Show 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | private function buildNewContentTemplate( | ||||
| if (strlen($this->getDescription())) { | if (strlen($this->getDescription())) { | ||||
| $new_content->setDescription($this->getDescription()); | $new_content->setDescription($this->getDescription()); | ||||
| } | } | ||||
| $new_content->setVersion($this->getOldContent()->getVersion() + 1); | $new_content->setVersion($this->getOldContent()->getVersion() + 1); | ||||
| return $new_content; | return $new_content; | ||||
| } | } | ||||
| protected function getCustomWorkerState() { | |||||
| return array( | |||||
| 'contentDiffURI' => $this->contentDiffURI, | |||||
| ); | |||||
| } | |||||
| protected function loadCustomWorkerState(array $state) { | |||||
| $this->contentDiffURI = idx($state, 'contentDiffURI'); | |||||
| return $this; | |||||
| } | |||||
| } | } | ||||