Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/editor/PhrictionTransactionEditor.php
Show First 20 Lines • Show All 79 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[] = 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( | |||||
PhabricatorLiskDAO $object, | |||||
PhabricatorApplicationTransaction $xaction) { | |||||
switch ($xaction->getTransactionType()) { | |||||
case PhrictionTransaction::TYPE_CONTENT: | |||||
if ($this->getIsNewObject()) { | |||||
return null; | |||||
} | |||||
return $this->getOldContent()->getContent(); | |||||
} | |||||
} | |||||
protected function getCustomTransactionNewValue( | |||||
PhabricatorLiskDAO $object, | |||||
PhabricatorApplicationTransaction $xaction) { | |||||
switch ($xaction->getTransactionType()) { | |||||
case PhrictionTransaction::TYPE_CONTENT: | |||||
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 PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: | case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: | ||||
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: | case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: | ||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: | case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: | ||||
case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE: | 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( | |||||
PhabricatorLiskDAO $object, | |||||
PhabricatorApplicationTransaction $xaction) { | |||||
switch ($xaction->getTransactionType()) { | |||||
case PhrictionTransaction::TYPE_CONTENT: | |||||
$object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); | |||||
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); | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: | ||||
if ($this->getIsNewObject()) { | if ($this->getIsNewObject()) { | ||||
break; | break; | ||||
} | } | ||||
$content = $xaction->getNewValue(); | $content = $xaction->getNewValue(); | ||||
if ($content === '') { | if ($content === '') { | ||||
$xactions[] = id(new PhrictionTransaction()) | $xactions[] = id(new PhrictionTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE) | PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE) | ||||
Show All 13 Lines | switch ($xaction->getTransactionType()) { | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
return $xactions; | return $xactions; | ||||
} | } | ||||
protected function applyCustomExternalTransaction( | |||||
PhabricatorLiskDAO $object, | |||||
PhabricatorApplicationTransaction $xaction) { | |||||
switch ($xaction->getTransactionType()) { | |||||
case PhrictionTransaction::TYPE_CONTENT: | |||||
$this->getNewContent()->setContent($xaction->getNewValue()); | |||||
break; | |||||
default: | |||||
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 PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE: | case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE: | ||||
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: | case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: | ||||
$save_content = true; | $save_content = true; | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if ($save_content) { | if ($save_content) { | ||||
Show All 26 Lines | if ($this->getIsNewObject() && !$this->getSkipAncestorCheck()) { | ||||
$slug); | $slug); | ||||
$stub_xactions = array(); | $stub_xactions = array(); | ||||
$stub_xactions[] = id(new PhrictionTransaction()) | $stub_xactions[] = id(new PhrictionTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
PhrictionDocumentTitleTransaction::TRANSACTIONTYPE) | PhrictionDocumentTitleTransaction::TRANSACTIONTYPE) | ||||
->setNewValue(PhabricatorSlug::getDefaultTitle($slug)) | ->setNewValue(PhabricatorSlug::getDefaultTitle($slug)) | ||||
->setMetadataValue('stub:create:phid', $object->getPHID()); | ->setMetadataValue('stub:create:phid', $object->getPHID()); | ||||
$stub_xactions[] = id(new PhrictionTransaction()) | $stub_xactions[] = id(new PhrictionTransaction()) | ||||
->setTransactionType(PhrictionTransaction::TYPE_CONTENT) | ->setTransactionType( | ||||
PhrictionDocumentContentTransaction::TRANSACTIONTYPE) | |||||
->setNewValue('') | ->setNewValue('') | ||||
->setMetadataValue('stub:create:phid', $object->getPHID()); | ->setMetadataValue('stub:create:phid', $object->getPHID()); | ||||
$stub_xactions[] = id(new PhrictionTransaction()) | $stub_xactions[] = id(new PhrictionTransaction()) | ||||
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) | ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) | ||||
->setNewValue($object->getViewPolicy()); | ->setNewValue($object->getViewPolicy()); | ||||
$stub_xactions[] = id(new PhrictionTransaction()) | $stub_xactions[] = id(new PhrictionTransaction()) | ||||
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) | ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) | ||||
->setNewValue($object->getEditPolicy()); | ->setNewValue($object->getEditPolicy()); | ||||
Show All 21 Lines | if ($this->moveAwayDocument !== null) { | ||||
->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. | // Compute the content diff URI for the publishing phase. | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: | ||||
$uri = id(new PhutilURI('/phriction/diff/'.$object->getID().'/')) | $uri = id(new PhutilURI('/phriction/diff/'.$object->getID().'/')) | ||||
->alter('l', $this->getOldContent()->getVersion()) | ->alter('l', $this->getOldContent()->getVersion()) | ||||
->alter('r', $this->getNewContent()->getVersion()); | ->alter('r', $this->getNewContent()->getVersion()); | ||||
$this->contentDiffURI = (string)$uri; | $this->contentDiffURI = (string)$uri; | ||||
break 2; | break 2; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | protected function validateTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
$type, | $type, | ||||
array $xactions) { | array $xactions) { | ||||
$errors = parent::validateTransaction($object, $type, $xactions); | $errors = parent::validateTransaction($object, $type, $xactions); | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
switch ($type) { | switch ($type) { | ||||
case PhrictionTransaction::TYPE_CONTENT: | case PhrictionDocumentContentTransaction::TRANSACTIONTYPE: | ||||
if ($xaction->getMetadataValue('stub:create:phid')) { | if ($xaction->getMetadataValue('stub:create:phid')) { | ||||
continue; | continue; | ||||
} | } | ||||
$missing = false; | if ($this->getProcessContentVersionError()) { | ||||
if ($this->getIsNewObject()) { | |||||
$content = $object->getContent()->getContent(); | |||||
$missing = $this->validateIsEmptyTextField( | |||||
$content, | |||||
$xactions); | |||||
} | |||||
if ($missing) { | |||||
$error = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Required'), | |||||
pht('Document content is required.'), | |||||
nonempty(last($xactions), null)); | |||||
$error->setIsMissingFieldError(true); | |||||
$errors[] = $error; | |||||
} else if ($this->getProcessContentVersionError()) { | |||||
$error = $this->validateContentVersion($object, $type, $xaction); | $error = $this->validateContentVersion($object, $type, $xaction); | ||||
if ($error) { | if ($error) { | ||||
$this->setProcessContentVersionError(false); | $this->setProcessContentVersionError(false); | ||||
$errors[] = $error; | $errors[] = $error; | ||||
} | } | ||||
} | } | ||||
if ($this->getIsNewObject()) { | if ($this->getIsNewObject()) { | ||||
$ancestry_errors = $this->validateAncestry( | $ancestry_errors = $this->validateAncestry( | ||||
$object, | $object, | ||||
$type, | $type, | ||||
$xaction, | $xaction, | ||||
self::VALIDATE_CREATE_ANCESTRY); | self::VALIDATE_CREATE_ANCESTRY); | ||||
if ($ancestry_errors) { | if ($ancestry_errors) { | ||||
$errors = array_merge($errors, $ancestry_errors); | $errors = array_merge($errors, $ancestry_errors); | ||||
} | } | ||||
} | } | ||||
break; | break; | ||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: | case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: | ||||
$source_document = $xaction->getNewValue(); | $source_document = $xaction->getNewValue(); | ||||
$ancestry_errors = $this->validateAncestry( | $ancestry_errors = $this->validateAncestry( | ||||
$object, | $object, | ||||
$type, | $type, | ||||
▲ Show 20 Lines • Show All 217 Lines • Show Last 20 Lines |