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 { | ||||
private $description; | private $description; | ||||
private $oldContent; | private $oldContent; | ||||
private $newContent; | private $newContent; | ||||
private $moveAwayDocument; | |||||
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 All 26 Lines | final class PhrictionTransactionEditor | ||||
} | } | ||||
public function getTransactionTypes() { | public function getTransactionTypes() { | ||||
$types = parent::getTransactionTypes(); | $types = parent::getTransactionTypes(); | ||||
$types[] = PhabricatorTransactions::TYPE_COMMENT; | $types[] = PhabricatorTransactions::TYPE_COMMENT; | ||||
$types[] = PhrictionTransaction::TYPE_TITLE; | $types[] = PhrictionTransaction::TYPE_TITLE; | ||||
$types[] = PhrictionTransaction::TYPE_CONTENT; | $types[] = PhrictionTransaction::TYPE_CONTENT; | ||||
$types[] = PhrictionTransaction::TYPE_DELETE; | |||||
$types[] = PhrictionTransaction::TYPE_MOVE_TO; | |||||
$types[] = PhrictionTransaction::TYPE_MOVE_AWAY; | |||||
/* TODO | /* TODO | ||||
$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, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhrictionTransaction::TYPE_TITLE: | case PhrictionTransaction::TYPE_TITLE: | ||||
if ($this->getIsNewObject()) { | if ($this->getIsNewObject()) { | ||||
return null; | return null; | ||||
} | } | ||||
return $this->getOldContent()->getTitle(); | return $this->getOldContent()->getTitle(); | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
if ($this->getIsNewObject()) { | if ($this->getIsNewObject()) { | ||||
return null; | return null; | ||||
} | } | ||||
return $this->getOldContent()->getContent(); | return $this->getOldContent()->getContent(); | ||||
case PhrictionTransaction::TYPE_DELETE: | |||||
case PhrictionTransaction::TYPE_MOVE_TO: | |||||
case PhrictionTransaction::TYPE_MOVE_AWAY: | |||||
return null; | |||||
} | } | ||||
} | } | ||||
protected function getCustomTransactionNewValue( | protected function getCustomTransactionNewValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhrictionTransaction::TYPE_TITLE: | case PhrictionTransaction::TYPE_TITLE: | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
case PhrictionTransaction::TYPE_DELETE: | |||||
return $xaction->getNewValue(); | return $xaction->getNewValue(); | ||||
case PhrictionTransaction::TYPE_MOVE_TO: | |||||
$document = $xaction->getNewValue(); | |||||
// grab the real object now for the sub-editor to come | |||||
$this->moveAwayDocument = $document; | |||||
$dict = array( | |||||
'id' => $document->getID(), | |||||
'phid' => $document->getPHID(), | |||||
'content' => $document->getContent()->getContent(),); | |||||
return $dict; | |||||
case PhrictionTransaction::TYPE_MOVE_AWAY: | |||||
$document = $xaction->getNewValue(); | |||||
$dict = array( | |||||
'id' => $document->getID(), | |||||
'phid' => $document->getPHID(), | |||||
'content' => $document->getContent()->getContent(),); | |||||
return $dict; | |||||
} | } | ||||
} | } | ||||
protected function shouldApplyInitialEffects( | protected function shouldApplyInitialEffects( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhrictionTransaction::TYPE_TITLE: | case PhrictionTransaction::TYPE_TITLE: | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
case PhrictionTransaction::TYPE_DELETE: | |||||
case PhrictionTransaction::TYPE_MOVE_TO: | |||||
case PhrictionTransaction::TYPE_MOVE_AWAY: | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return parent::shouldApplyInitialEffects($object, $xactions); | return parent::shouldApplyInitialEffects($object, $xactions); | ||||
} | } | ||||
protected function applyInitialEffects( | protected function applyInitialEffects( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
$this->setOldContent($object->getContent()); | $this->setOldContent($object->getContent()); | ||||
$this->setNewContent($this->buildNewContentTemplate($object)); | $this->setNewContent($this->buildNewContentTemplate($object)); | ||||
} | } | ||||
protected function applyCustomInternalTransaction( | protected function applyCustomInternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhrictionTransaction::TYPE_TITLE: | case PhrictionTransaction::TYPE_TITLE: | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
case PhrictionTransaction::TYPE_MOVE_TO: | |||||
$object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); | $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); | ||||
return; | return; | ||||
case PhrictionTransaction::TYPE_MOVE_AWAY: | |||||
$object->setStatus(PhrictionDocumentStatus::STATUS_MOVED); | |||||
return; | |||||
} | } | ||||
} | } | ||||
protected function applyCustomExternalTransaction( | protected function applyCustomExternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhrictionTransaction::TYPE_TITLE: | case PhrictionTransaction::TYPE_TITLE: | ||||
$this->getNewContent()->setTitle($xaction->getNewValue()); | $this->getNewContent()->setTitle($xaction->getNewValue()); | ||||
break; | break; | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
$this->getNewContent()->setContent($xaction->getNewValue()); | $this->getNewContent()->setContent($xaction->getNewValue()); | ||||
break; | break; | ||||
case PhrictionTransaction::TYPE_DELETE: | |||||
$this->getNewContent()->setContent(''); | |||||
$this->getNewContent()->setChangeType( | |||||
PhrictionChangeType::CHANGE_DELETE); | |||||
break; | |||||
case PhrictionTransaction::TYPE_MOVE_TO: | |||||
$dict = $xaction->getNewValue(); | |||||
$this->getNewContent()->setContent($dict['content']); | |||||
$this->getNewContent()->setChangeType( | |||||
PhrictionChangeType::CHANGE_MOVE_HERE); | |||||
$this->getNewContent()->setChangeRef($dict['id']); | |||||
break; | |||||
case PhrictionTransaction::TYPE_MOVE_AWAY: | |||||
$dict = $xaction->getNewValue(); | |||||
$this->getNewContent()->setContent(''); | |||||
$this->getNewContent()->setChangeType( | |||||
PhrictionChangeType::CHANGE_MOVE_AWAY); | |||||
$this->getNewContent()->setChangeRef($dict['id']); | |||||
break; | |||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
protected function applyFinalEffects( | protected function applyFinalEffects( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
$save_content = false; | $save_content = false; | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhrictionTransaction::TYPE_TITLE: | case PhrictionTransaction::TYPE_TITLE: | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
case PhrictionTransaction::TYPE_DELETE: | |||||
case PhrictionTransaction::TYPE_MOVE_AWAY: | |||||
case PhrictionTransaction::TYPE_MOVE_TO: | |||||
$save_content = true; | $save_content = true; | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if ($save_content) { | if ($save_content) { | ||||
Show All 24 Lines | if ($this->getIsNewObject()) { | ||||
->setTitle(PhabricatorSlug::getDefaultTitle($slug)) | ->setTitle(PhabricatorSlug::getDefaultTitle($slug)) | ||||
->setContent('') | ->setContent('') | ||||
->setDescription(pht('Empty Parent Document')) | ->setDescription(pht('Empty Parent Document')) | ||||
->stub(); | ->stub(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ($this->moveAwayDocument !== null) { | |||||
$move_away_xactions = array(); | |||||
$move_away_xactions[] = id(new PhrictionTransaction()) | |||||
->setTransactionType(PhrictionTransaction::TYPE_MOVE_AWAY) | |||||
->setNewValue($object); | |||||
$sub_editor = id(new PhrictionTransactionEditor()) | |||||
->setActor($this->getActor()) | |||||
->setContentSource($this->getContentSource()) | |||||
->setContinueOnNoEffect($this->getContinueOnNoEffect()) | |||||
->setDescription($this->getDescription()) | |||||
->applyTransactions($this->moveAwayDocument, $move_away_xactions); | |||||
} | |||||
return $xactions; | return $xactions; | ||||
} | } | ||||
protected function shouldSendMail( | protected function shouldSendMail( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
return true; | |||||
$xactions = mfilter($xactions, 'shouldHide', true); | |||||
return $xactions; | |||||
} | } | ||||
protected function getMailSubjectPrefix() { | protected function getMailSubjectPrefix() { | ||||
return '[Phriction]'; | return '[Phriction]'; | ||||
} | } | ||||
protected function getMailTo(PhabricatorLiskDAO $object) { | protected function getMailTo(PhabricatorLiskDAO $object) { | ||||
return array( | return array( | ||||
$object->getContent()->getAuthorPHID(), | $object->getContent()->getAuthorPHID(), | ||||
$this->getActingAsPHID(), | $this->getActingAsPHID(), | ||||
); | ); | ||||
} | } | ||||
public function getMailTagsMap() { | public function getMailTagsMap() { | ||||
return array( | return array( | ||||
PhrictionTransaction::MAILTAG_TITLE => | PhrictionTransaction::MAILTAG_TITLE => | ||||
pht("A document's title changes."), | pht("A document's title changes."), | ||||
PhrictionTransaction::MAILTAG_CONTENT => | PhrictionTransaction::MAILTAG_CONTENT => | ||||
pht("A document's content changes."), | pht("A document's content changes."), | ||||
PhrictionTransaction::MAILTAG_DELETE => | |||||
pht('A document is deleted.'), | |||||
); | ); | ||||
} | } | ||||
protected function buildReplyHandler(PhabricatorLiskDAO $object) { | protected function buildReplyHandler(PhabricatorLiskDAO $object) { | ||||
return id(new PhrictionReplyHandler()) | return id(new PhrictionReplyHandler()) | ||||
->setMailReceiver($object); | ->setMailReceiver($object); | ||||
} | } | ||||
Show All 32 Lines | protected function shouldPublishFeedStory( | ||||
return $this->shouldSendMail($object, $xactions); | return $this->shouldSendMail($object, $xactions); | ||||
} | } | ||||
protected function getFeedRelatedPHIDs( | protected function getFeedRelatedPHIDs( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
$phids = parent::getFeedRelatedPHIDs($object, $xactions); | $phids = parent::getFeedRelatedPHIDs($object, $xactions); | ||||
// TODO - once the editor supports moves, we'll need to surface the | |||||
// "from document phid" to related phids. | foreach ($xactions as $xaction) { | ||||
switch ($xaction->getTransactionType()) { | |||||
case PhrictionTransaction::TYPE_MOVE_TO: | |||||
$dict = $xaction->getNewValue(); | |||||
$phids[] = $dict['phid']; | |||||
break; | |||||
} | |||||
} | |||||
return $phids; | return $phids; | ||||
} | } | ||||
protected function supportsSearch() { | protected function supportsSearch() { | ||||
return true; | return true; | ||||
} | } | ||||
protected function shouldApplyHeraldRules( | protected function shouldApplyHeraldRules( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
return false; | return false; | ||||
} | } | ||||
private function buildNewContentTemplate( | private function buildNewContentTemplate( | ||||
PhrictionDocument $document) { | PhrictionDocument $document) { | ||||
$new_content = new PhrictionContent(); | $new_content = id(new PhrictionContent()) | ||||
$new_content->setSlug($document->getSlug()); | ->setSlug($document->getSlug()) | ||||
$new_content->setAuthorPHID($this->getActor()->getPHID()); | ->setAuthorPHID($this->getActor()->getPHID()) | ||||
$new_content->setChangeType(PhrictionChangeType::CHANGE_EDIT); | ->setChangeType(PhrictionChangeType::CHANGE_EDIT) | ||||
->setTitle($this->getOldContent()->getTitle()) | |||||
$new_content->setTitle($this->getOldContent()->getTitle()); | ->setContent($this->getOldContent()->getContent()); | ||||
$new_content->setContent($this->getOldContent()->getContent()); | |||||
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; | ||||
} | } | ||||
} | } |