Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/editor/PhrictionTransactionEditor.php
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 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; | |||||
/* 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: | |||||
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(); | ||||
} | } | ||||
} | } | ||||
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: | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return parent::shouldApplyInitialEffects($object, $xactions); | return parent::shouldApplyInitialEffects($object, $xactions); | ||||
} | } | ||||
protected function applyInitialEffects( | protected function applyInitialEffects( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
Show All 21 Lines | protected function applyCustomExternalTransaction( | ||||
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; | |||||
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: | |||||
$save_content = true; | $save_content = true; | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if ($save_content) { | if ($save_content) { | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | final class PhrictionTransactionEditor | ||||
} | } | ||||
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 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | 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())) { | ||||
shadowhandUnsubmitted Not Done Inline Actionsshadowhand: thumbsup | |||||
$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; | ||||
} | } | ||||
} | } |