Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/editor/PhrictionTransactionEditor.php
Show First 20 Lines • Show All 471 Lines • ▼ Show 20 Lines | foreach ($xactions as $xaction) { | ||||
} else if ($this->getProcessContentVersionError()) { | } 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; | ||||
} | } | ||||
} | } | ||||
break; | break; | ||||
case PhrictionTransaction::TYPE_MOVE_TO: | |||||
$source_document = $xaction->getNewValue(); | |||||
switch ($source_document->getStatus()) { | |||||
case PhrictionDocumentStatus::STATUS_DELETED: | |||||
$e_text = pht('A deleted document can not be moved.'); | |||||
break; | |||||
case PhrictionDocumentStatus::STATUS_MOVED: | |||||
$e_text = pht('A moved document can not be moved again.'); | |||||
break; | |||||
case PhrictionDocumentStatus::STATUS_STUB: | |||||
$e_text = pht('A stub document can not be moved.'); | |||||
break; | |||||
default: | |||||
$e_text = null; | |||||
break; | |||||
} | |||||
if ($e_text) { | |||||
$error = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Can not move document.'), | |||||
$e_text, | |||||
$xaction); | |||||
$errors[] = $error; | |||||
} | |||||
// NOTE: We use the ominpotent user because we can't let users | |||||
// overwrite documents even if they can't see them. | |||||
$target_document = id(new PhrictionDocumentQuery()) | |||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
->withSlugs(array($object->getSlug())) | |||||
->needContent(true) | |||||
->executeOne(); | |||||
// Considering to overwrite existing docs? Nuke this! | |||||
$exists = PhrictionDocumentStatus::STATUS_EXISTS; | |||||
if ($target_document && $target_document->getStatus() == $exists) { | |||||
$error = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Can not move document.'), | |||||
pht('Can not overwrite existing target document.'), | |||||
$xaction); | |||||
$errors[] = $error; | |||||
} | |||||
break; | |||||
case PhrictionTransaction::TYPE_DELETE: | case PhrictionTransaction::TYPE_DELETE: | ||||
switch ($object->getStatus()) { | switch ($object->getStatus()) { | ||||
case PhrictionDocumentStatus::STATUS_DELETED: | case PhrictionDocumentStatus::STATUS_DELETED: | ||||
$e_text = pht('An already deleted document can not be deleted.'); | $e_text = pht('An already deleted document can not be deleted.'); | ||||
break; | break; | ||||
case PhrictionDocumentStatus::STATUS_MOVED: | case PhrictionDocumentStatus::STATUS_MOVED: | ||||
$e_text = pht('A moved document can not be deleted.'); | $e_text = pht('A moved document can not be deleted.'); | ||||
break; | break; | ||||
case PhrictionDocumentStatus::STATUS_STUB: | case PhrictionDocumentStatus::STATUS_STUB: | ||||
$e_text = pht('A stub document can not be deleted.'); | $e_text = pht('A stub document can not be deleted.'); | ||||
break; | break; | ||||
default: | default: | ||||
break 2; | break 2; | ||||
} | } | ||||
$error = new PhabricatorApplicationTransactionValidationError( | $error = new PhabricatorApplicationTransactionValidationError( | ||||
$type, | $type, | ||||
pht('Can not delete document.'), | pht('Can not delete document.'), | ||||
$e_text, | $e_text, | ||||
$xaction); | $xaction); | ||||
$errors[] = $error; | $errors[] = $error; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return $errors; | return $errors; | ||||
} | } | ||||
private function validateContentVersion( | private function validateContentVersion( | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |