1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-12 20:34:54 +01:00
phorge-phorge/src/applications/phriction/xaction/PhrictionDocumentPublishTransaction.php
epriestley 349686319e Allow the published version of a Phriction document to differ from the most recent version
Summary:
Depends on D19620. Ref T13077. This adds a "Publish" operation which points the current version at some historical version of the document -- not necessarily the most recent version. Newer versions become "drafts".

This is still quite rough and missing a lot of hinting in the UI, I'm just making it work so I can start making the UI understand it.

Test Plan: Used the "Publish" action to publish older versions of a document, saw the document revert. Many UI hints are missing and this operation is puzzling and not yet usable for normal users.

Reviewers: amckinley

Maniphest Tasks: T13077

Differential Revision: https://secure.phabricator.com/D19621
2018-08-29 13:47:36 -07:00

71 lines
1.7 KiB
PHP

<?php
final class PhrictionDocumentPublishTransaction
extends PhrictionDocumentTransactionType {
const TRANSACTIONTYPE = 'publish';
public function generateOldValue($object) {
return $object->getContentPHID();
}
public function applyInternalEffects($object, $value) {
$object->setContentPHID($value);
}
public function getActionName() {
return pht('Published');
}
public function getTitle() {
return pht(
'%s published a new version of this document.',
$this->renderAuthor());
}
public function getTitleForFeed() {
return pht(
'%s published a new version of %s.',
$this->renderAuthor(),
$this->renderObject());
}
public function validateTransactions($object, array $xactions) {
$actor = $this->getActor();
$errors = array();
foreach ($xactions as $xaction) {
$content_phid = $xaction->getNewValue();
// If this isn't changing anything, skip it.
if ($content_phid === $object->getContentPHID()) {
continue;
}
$content = id(new PhrictionContentQuery())
->setViewer($actor)
->withPHIDs(array($content_phid))
->executeOne();
if (!$content) {
$errors[] = $this->newInvalidError(
pht(
'Unable to load Content object with PHID "%s".',
$content_phid),
$xaction);
continue;
}
if ($content->getDocumentPHID() !== $object->getPHID()) {
$errors[] = $this->newInvalidError(
pht(
'Content object "%s" can not be published because it belongs '.
'to a different document.',
$content_phid));
continue;
}
}
return $errors;
}
}