Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/editor/PhrictionTransactionEditor.php
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | final class PhrictionTransactionEditor | ||||
public function getEditorObjectsDescription() { | public function getEditorObjectsDescription() { | ||||
return pht('Phriction Documents'); | return pht('Phriction Documents'); | ||||
} | } | ||||
public function getTransactionTypes() { | public function getTransactionTypes() { | ||||
$types = parent::getTransactionTypes(); | $types = parent::getTransactionTypes(); | ||||
$types[] = PhrictionTransaction::TYPE_CONTENT; | $types[] = PhrictionTransaction::TYPE_CONTENT; | ||||
$types[] = PhrictionTransaction::TYPE_MOVE_AWAY; | |||||
$types[] = PhabricatorTransactions::TYPE_EDGE; | $types[] = PhabricatorTransactions::TYPE_EDGE; | ||||
$types[] = PhabricatorTransactions::TYPE_COMMENT; | $types[] = PhabricatorTransactions::TYPE_COMMENT; | ||||
$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_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_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_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
return $xaction->getNewValue(); | return $xaction->getNewValue(); | ||||
case PhrictionTransaction::TYPE_MOVE_AWAY: | |||||
$document = $xaction->getNewValue(); | |||||
$dict = array( | |||||
'id' => $document->getID(), | |||||
'phid' => $document->getPHID(), | |||||
'content' => $document->getContent()->getContent(), | |||||
'title' => $document->getContent()->getTitle(), | |||||
); | |||||
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 PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: | case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: | case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: | ||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: | case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: | ||||
case PhrictionTransaction::TYPE_MOVE_AWAY: | case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE: | ||||
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_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
$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 expandTransaction( | protected function expandTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
$xactions = parent::expandTransaction($object, $xaction); | $xactions = parent::expandTransaction($object, $xaction); | ||||
Show All 31 Lines | final class PhrictionTransactionEditor | ||||
protected function applyCustomExternalTransaction( | protected function applyCustomExternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionTransaction::TYPE_CONTENT: | ||||
$this->getNewContent()->setContent($xaction->getNewValue()); | $this->getNewContent()->setContent($xaction->getNewValue()); | ||||
break; | 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 PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: | case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: | ||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: | case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE: | ||||
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: | case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: | ||||
case PhrictionTransaction::TYPE_MOVE_AWAY: | case PhrictionTransaction::TYPE_CONTENT: | ||||
$save_content = true; | $save_content = true; | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if ($save_content) { | if ($save_content) { | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if ($this->getIsNewObject() && !$this->getSkipAncestorCheck()) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ($this->moveAwayDocument !== null) { | if ($this->moveAwayDocument !== null) { | ||||
$move_away_xactions = array(); | $move_away_xactions = array(); | ||||
$move_away_xactions[] = id(new PhrictionTransaction()) | $move_away_xactions[] = id(new PhrictionTransaction()) | ||||
->setTransactionType(PhrictionTransaction::TYPE_MOVE_AWAY) | ->setTransactionType( | ||||
PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE) | |||||
->setNewValue($object); | ->setNewValue($object); | ||||
$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); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 394 Lines • Show Last 20 Lines |