1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

Move Phriction internal document/content references from IDs to PHIDs

Summary:
Ref T13077. This is mostly just a small cleanup change, even though the actual change is large.

We currently reference content and document objects from one another with `contentID` and `documentID`, but this means that `contentID` must be nullable. Switching to PHIDs allows the column to be non-nullable.

This also supports reorienting some current and future transactions around PHIDs, which is preferable for the API. In particular, I'm adding a "publish version X" transaction soon, and would rather callers pass a PHID than an ID or version number, since this will make the API more consistent and powerful.

Today, `contentID` gets used as a cheaty way to order documents by (content) edit time. Since PHIDs aren't orderable and stuff is going to become actually-revertible soon, replace this with an epoch timestamp.

Test Plan:
  - Created, edited, moved, retitled, and deleted Phriction documents.
  - Grepped for `documentID` and `contentID`.
  - This probably breaks //something// but I'll be in this code for a bit and am likely to catch whatever breaks.

Reviewers: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13077

Differential Revision: https://secure.phabricator.com/D19619
This commit is contained in:
epriestley 2018-08-28 16:09:24 -07:00
parent 04f8270a74
commit 64cee4a902
21 changed files with 183 additions and 122 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_phriction.phriction_document
ADD contentPHID VARBINARY(64) NOT NULL;

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_phriction.phriction_content
ADD documentPHID VARBINARY(64) NOT NULL;

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_phriction.phriction_document
ADD editedEpoch INT UNSIGNED NOT NULL;

View file

@ -0,0 +1,57 @@
<?php
// Update the PhrictionDocument and PhrictionContent tables to refer to one
// another by PHID instead of by ID.
$document_table = new PhrictionDocument();
$content_table = new PhrictionContent();
$conn = $document_table->establishConnection('w');
$document_iterator = new LiskRawMigrationIterator(
$conn,
$document_table->getTableName());
foreach ($document_iterator as $row) {
$content_id = $row['contentID'];
$content_row = queryfx_one(
$conn,
'SELECT phid, dateCreated FROM %T WHERE id = %d',
$content_table->getTableName(),
$content_id);
if (!$content_row) {
continue;
}
queryfx(
$conn,
'UPDATE %T SET contentPHID = %s, editedEpoch = %d WHERE id = %d',
$document_table->getTableName(),
$content_row['phid'],
$content_row['dateCreated'],
$row['id']);
}
$content_iterator = new LiskRawMigrationIterator(
$conn,
$content_table->getTableName());
foreach ($content_iterator as $row) {
$document_id = $row['documentID'];
$document_row = queryfx_one(
$conn,
'SELECT phid FROM %T WHERE id = %d',
$document_table->getTableName(),
$document_id);
if (!$document_row) {
continue;
}
queryfx(
$conn,
'UPDATE %T SET documentPHID = %s WHERE id = %d',
$content_table->getTableName(),
$document_row['phid'],
$row['id']);
}

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_phriction.phriction_document
DROP contentID;

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_phriction.phriction_content
DROP documentID;

View file

@ -5036,6 +5036,7 @@ phutil_register_library_map(array(
'PhrictionDocumentTitleHeraldField' => 'applications/phriction/herald/PhrictionDocumentTitleHeraldField.php', 'PhrictionDocumentTitleHeraldField' => 'applications/phriction/herald/PhrictionDocumentTitleHeraldField.php',
'PhrictionDocumentTitleTransaction' => 'applications/phriction/xaction/PhrictionDocumentTitleTransaction.php', 'PhrictionDocumentTitleTransaction' => 'applications/phriction/xaction/PhrictionDocumentTitleTransaction.php',
'PhrictionDocumentTransactionType' => 'applications/phriction/xaction/PhrictionDocumentTransactionType.php', 'PhrictionDocumentTransactionType' => 'applications/phriction/xaction/PhrictionDocumentTransactionType.php',
'PhrictionDocumentVersionTransaction' => 'applications/phriction/xaction/PhrictionDocumentVersionTransaction.php',
'PhrictionEditConduitAPIMethod' => 'applications/phriction/conduit/PhrictionEditConduitAPIMethod.php', 'PhrictionEditConduitAPIMethod' => 'applications/phriction/conduit/PhrictionEditConduitAPIMethod.php',
'PhrictionEditController' => 'applications/phriction/controller/PhrictionEditController.php', 'PhrictionEditController' => 'applications/phriction/controller/PhrictionEditController.php',
'PhrictionHistoryConduitAPIMethod' => 'applications/phriction/conduit/PhrictionHistoryConduitAPIMethod.php', 'PhrictionHistoryConduitAPIMethod' => 'applications/phriction/conduit/PhrictionHistoryConduitAPIMethod.php',
@ -11129,17 +11130,17 @@ phutil_register_library_map(array(
), ),
'PhrictionDocumentAuthorHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentAuthorHeraldField' => 'PhrictionDocumentHeraldField',
'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField',
'PhrictionDocumentContentTransaction' => 'PhrictionDocumentTransactionType', 'PhrictionDocumentContentTransaction' => 'PhrictionDocumentVersionTransaction',
'PhrictionDocumentController' => 'PhrictionController', 'PhrictionDocumentController' => 'PhrictionController',
'PhrictionDocumentDatasource' => 'PhabricatorTypeaheadDatasource', 'PhrictionDocumentDatasource' => 'PhabricatorTypeaheadDatasource',
'PhrictionDocumentDeleteTransaction' => 'PhrictionDocumentTransactionType', 'PhrictionDocumentDeleteTransaction' => 'PhrictionDocumentVersionTransaction',
'PhrictionDocumentFerretEngine' => 'PhabricatorFerretEngine', 'PhrictionDocumentFerretEngine' => 'PhabricatorFerretEngine',
'PhrictionDocumentFulltextEngine' => 'PhabricatorFulltextEngine', 'PhrictionDocumentFulltextEngine' => 'PhabricatorFulltextEngine',
'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter', 'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter',
'PhrictionDocumentHeraldField' => 'HeraldField', 'PhrictionDocumentHeraldField' => 'HeraldField',
'PhrictionDocumentHeraldFieldGroup' => 'HeraldFieldGroup', 'PhrictionDocumentHeraldFieldGroup' => 'HeraldFieldGroup',
'PhrictionDocumentMoveAwayTransaction' => 'PhrictionDocumentTransactionType', 'PhrictionDocumentMoveAwayTransaction' => 'PhrictionDocumentVersionTransaction',
'PhrictionDocumentMoveToTransaction' => 'PhrictionDocumentTransactionType', 'PhrictionDocumentMoveToTransaction' => 'PhrictionDocumentVersionTransaction',
'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType', 'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType',
'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField',
'PhrictionDocumentPolicyCodex' => 'PhabricatorPolicyCodex', 'PhrictionDocumentPolicyCodex' => 'PhabricatorPolicyCodex',
@ -11148,8 +11149,9 @@ phutil_register_library_map(array(
'PhrictionDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhrictionDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhrictionDocumentStatus' => 'PhabricatorObjectStatus', 'PhrictionDocumentStatus' => 'PhabricatorObjectStatus',
'PhrictionDocumentTitleHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentTitleHeraldField' => 'PhrictionDocumentHeraldField',
'PhrictionDocumentTitleTransaction' => 'PhrictionDocumentTransactionType', 'PhrictionDocumentTitleTransaction' => 'PhrictionDocumentVersionTransaction',
'PhrictionDocumentTransactionType' => 'PhabricatorModularTransactionType', 'PhrictionDocumentTransactionType' => 'PhabricatorModularTransactionType',
'PhrictionDocumentVersionTransaction' => 'PhrictionDocumentTransactionType',
'PhrictionEditConduitAPIMethod' => 'PhrictionConduitAPIMethod', 'PhrictionEditConduitAPIMethod' => 'PhrictionConduitAPIMethod',
'PhrictionEditController' => 'PhrictionController', 'PhrictionEditController' => 'PhrictionController',
'PhrictionHistoryConduitAPIMethod' => 'PhrictionConduitAPIMethod', 'PhrictionHistoryConduitAPIMethod' => 'PhrictionConduitAPIMethod',

View file

@ -65,8 +65,8 @@ final class PhrictionDiffController extends PhrictionController {
$slug = $document->getSlug(); $slug = $document->getSlug();
$revert_l = $this->renderRevertButton($content_l, $current); $revert_l = $this->renderRevertButton($document, $content_l, $current);
$revert_r = $this->renderRevertButton($content_r, $current); $revert_r = $this->renderRevertButton($document, $content_r, $current);
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$crumb_views = $this->renderBreadcrumbs($slug); $crumb_views = $this->renderBreadcrumbs($slug);
@ -179,10 +179,11 @@ final class PhrictionDiffController extends PhrictionController {
} }
private function renderRevertButton( private function renderRevertButton(
PhrictionDocument $document,
PhrictionContent $content, PhrictionContent $content,
PhrictionContent $current) { PhrictionContent $current) {
$document_id = $content->getDocumentID(); $document_id = $document->getID();
$version = $content->getVersion(); $version = $content->getVersion();
$hidden_statuses = array( $hidden_statuses = array(

View file

@ -78,7 +78,7 @@ final class PhrictionDocumentController
return new Aphront404Response(); return new Aphront404Response();
} }
if ($content->getID() != $document->getContentID()) { if ($content->getPHID() != $document->getContentPHID()) {
$version_note = id(new PHUIInfoView()) $version_note = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE) ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->appendChild( ->appendChild(

View file

@ -52,7 +52,7 @@ final class PhrictionHistoryController
} }
$vs_head = null; $vs_head = null;
if ($content->getID() != $document->getContentID()) { if ($content->getPHID() != $document->getContentPHID()) {
$vs_head = $diff_uri $vs_head = $diff_uri
->alter('l', $content->getVersion()) ->alter('l', $content->getVersion())
->alter('r', $current->getVersion()); ->alter('r', $current->getVersion());

View file

@ -93,29 +93,13 @@ final class PhrictionTransactionEditor
return $types; return $types;
} }
protected function shouldApplyInitialEffects( protected function expandTransactions(
PhabricatorLiskDAO $object,
array $xactions) {
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
case PhrictionDocumentContentTransaction::TRANSACTIONTYPE:
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE:
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
return true;
}
}
return parent::shouldApplyInitialEffects($object, $xactions);
}
protected function applyInitialEffects(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {
$this->setOldContent($object->getContent()); $this->setOldContent($object->getContent());
$this->setNewContent($this->buildNewContentTemplate($object));
return parent::expandTransactions($object, $xactions);
} }
protected function expandTransaction( protected function expandTransaction(
@ -148,7 +132,6 @@ final class PhrictionTransactionEditor
break; break;
default: default:
break; break;
} }
return $xactions; return $xactions;
@ -158,29 +141,12 @@ final class PhrictionTransactionEditor
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {
$save_content = false; if ($this->hasNewDocumentContent()) {
foreach ($xactions as $xaction) { $content = $this->getNewDocumentContent($object);
switch ($xaction->getTransactionType()) {
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE:
case PhrictionDocumentContentTransaction::TRANSACTIONTYPE:
$save_content = true;
break;
default:
break;
}
}
if ($save_content) { $content
$content = $this->getNewContent(); ->setDocumentPHID($object->getPHID())
$content->setDocumentID($object->getID()); ->save();
$content->save();
$object->setContentID($content->getID());
$object->save();
$object->attachContent($content);
} }
if ($this->getIsNewObject() && !$this->getSkipAncestorCheck()) { if ($this->getIsNewObject() && !$this->getSkipAncestorCheck()) {
@ -535,24 +501,47 @@ final class PhrictionTransactionEditor
->setDocument($object); ->setDocument($object);
} }
private function buildNewContentTemplate( private function hasNewDocumentContent() {
PhrictionDocument $document) { return (bool)$this->newContent;
}
$new_content = id(new PhrictionContent()) public function getNewDocumentContent(PhrictionDocument $document) {
if (!$this->hasNewDocumentContent()) {
$content = $this->newDocumentContent($document);
// Generate a PHID now so we can populate "contentPHID" before saving
// the document to the database: the column is not nullable so we need
// a value.
$content_phid = $content->generatePHID();
$content->setPHID($content_phid);
$document->setContentPHID($content_phid);
$document->attachContent($content);
$document->setEditedEpoch(PhabricatorTime::getNow());
$this->newContent = $content;
}
return $this->newContent;
}
private function newDocumentContent(PhrictionDocument $document) {
$content = id(new PhrictionContent())
->setSlug($document->getSlug()) ->setSlug($document->getSlug())
->setAuthorPHID($this->getActor()->getPHID()) ->setAuthorPHID($this->getActingAsPHID())
->setChangeType(PhrictionChangeType::CHANGE_EDIT) ->setChangeType(PhrictionChangeType::CHANGE_EDIT)
->setTitle($this->getOldContent()->getTitle()) ->setTitle($this->getOldContent()->getTitle())
->setContent($this->getOldContent()->getContent()) ->setContent($this->getOldContent()->getContent())
->setDescription(''); ->setDescription('');
if (strlen($this->getDescription())) { if (strlen($this->getDescription())) {
$new_content->setDescription($this->getDescription()); $content->setDescription($this->getDescription());
} }
$new_content->setVersion($this->getOldContent()->getVersion() + 1); $content->setVersion($this->getOldContent()->getVersion() + 1);
return $new_content; return $content;
} }
protected function getCustomWorkerState() { protected function getCustomWorkerState() {

View file

@ -76,7 +76,7 @@ final class PhrictionContentQuery
if ($this->shouldJoinDocumentTable()) { if ($this->shouldJoinDocumentTable()) {
$joins[] = qsprintf( $joins[] = qsprintf(
$conn, $conn,
'JOIN %T d ON d.id = c.documentID', 'JOIN %T d ON d.phid = c.documentPHID',
id(new PhrictionDocument())->getTableName()); id(new PhrictionDocument())->getTableName());
} }
@ -84,19 +84,19 @@ final class PhrictionContentQuery
} }
protected function willFilterPage(array $contents) { protected function willFilterPage(array $contents) {
$document_ids = mpull($contents, 'getDocumentID'); $document_phids = mpull($contents, 'getDocumentPHID');
$documents = id(new PhrictionDocumentQuery()) $documents = id(new PhrictionDocumentQuery())
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
->setParentQuery($this) ->setParentQuery($this)
->withIDs($document_ids) ->withPHIDs($document_phids)
->execute(); ->execute();
$documents = mpull($documents, null, 'getID'); $documents = mpull($documents, null, 'getPHID');
foreach ($contents as $key => $content) { foreach ($contents as $key => $content) {
$document_id = $content->getDocumentID(); $document_phid = $content->getDocumentPHID();
$document = idx($documents, $document_id); $document = idx($documents, $document_phid);
if (!$document) { if (!$document) {
unset($contents[$key]); unset($contents[$key]);
$this->didRejectResult($content); $this->didRejectResult($content);

View file

@ -151,17 +151,17 @@ final class PhrictionDocumentQuery
$contents = id(new PhrictionContentQuery()) $contents = id(new PhrictionContentQuery())
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
->setParentQuery($this) ->setParentQuery($this)
->withIDs(mpull($documents, 'getContentID')) ->withPHIDs(mpull($documents, 'getContentPHID'))
->execute(); ->execute();
$contents = mpull($contents, null, 'getID'); $contents = mpull($contents, null, 'getPHID');
foreach ($documents as $key => $document) { foreach ($documents as $key => $document) {
$content_id = $document->getContentID(); $content_phid = $document->getContentPHID();
if (empty($contents[$content_id])) { if (empty($contents[$content_phid])) {
unset($documents[$key]); unset($documents[$key]);
continue; continue;
} }
$document->attachContent($contents[$content_id]); $document->attachContent($contents[$content_phid]);
} }
} }
@ -175,7 +175,7 @@ final class PhrictionDocumentQuery
$content_dao = new PhrictionContent(); $content_dao = new PhrictionContent();
$joins[] = qsprintf( $joins[] = qsprintf(
$conn, $conn,
'JOIN %T c ON d.contentID = c.id', 'JOIN %T c ON d.contentPHID = c.phid',
$content_dao->getTableName()); $content_dao->getTableName());
} }
@ -321,7 +321,7 @@ final class PhrictionDocumentQuery
public function getBuiltinOrders() { public function getBuiltinOrders() {
return parent::getBuiltinOrders() + array( return parent::getBuiltinOrders() + array(
self::ORDER_HIERARCHY => array( self::ORDER_HIERARCHY => array(
'vector' => array('depth', 'title', 'updated'), 'vector' => array('depth', 'title', 'updated', 'id'),
'name' => pht('Hierarchy'), 'name' => pht('Hierarchy'),
), ),
); );
@ -343,9 +343,9 @@ final class PhrictionDocumentQuery
), ),
'updated' => array( 'updated' => array(
'table' => 'd', 'table' => 'd',
'column' => 'contentID', 'column' => 'editedEpoch',
'type' => 'int', 'type' => 'int',
'unique' => true, 'unique' => false,
), ),
); );
} }
@ -356,7 +356,7 @@ final class PhrictionDocumentQuery
$map = array( $map = array(
'id' => $document->getID(), 'id' => $document->getID(),
'depth' => $document->getDepth(), 'depth' => $document->getDepth(),
'updated' => $document->getContentID(), 'updated' => $document->getEditedEpoch(),
); );
foreach ($keys as $key) { foreach ($keys as $key) {

View file

@ -7,7 +7,7 @@ final class PhrictionContent
PhabricatorDestructibleInterface, PhabricatorDestructibleInterface,
PhabricatorConduitResultInterface { PhabricatorConduitResultInterface {
protected $documentID; protected $documentPHID;
protected $version; protected $version;
protected $authorPHID; protected $authorPHID;
@ -35,7 +35,7 @@ final class PhrictionContent
), ),
self::CONFIG_KEY_SCHEMA => array( self::CONFIG_KEY_SCHEMA => array(
'documentID' => array( 'documentID' => array(
'columns' => array('documentID', 'version'), 'columns' => array('documentPHID', 'version'),
'unique' => true, 'unique' => true,
), ),
'authorPHID' => array( 'authorPHID' => array(

View file

@ -17,12 +17,13 @@ final class PhrictionDocument extends PhrictionDAO
protected $slug; protected $slug;
protected $depth; protected $depth;
protected $contentID; protected $contentPHID;
protected $status; protected $status;
protected $mailKey; protected $mailKey;
protected $viewPolicy; protected $viewPolicy;
protected $editPolicy; protected $editPolicy;
protected $spacePHID; protected $spacePHID;
protected $editedEpoch;
private $contentObject = self::ATTACHABLE; private $contentObject = self::ATTACHABLE;
private $ancestors = array(); private $ancestors = array();
@ -34,16 +35,11 @@ final class PhrictionDocument extends PhrictionDAO
self::CONFIG_COLUMN_SCHEMA => array( self::CONFIG_COLUMN_SCHEMA => array(
'slug' => 'sort128', 'slug' => 'sort128',
'depth' => 'uint32', 'depth' => 'uint32',
'contentID' => 'id?',
'status' => 'text32', 'status' => 'text32',
'mailKey' => 'bytes20', 'mailKey' => 'bytes20',
'editedEpoch' => 'epoch',
), ),
self::CONFIG_KEY_SCHEMA => array( self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null,
'phid' => array(
'columns' => array('phid'),
'unique' => true,
),
'slug' => array( 'slug' => array(
'columns' => array('slug'), 'columns' => array('slug'),
'unique' => true, 'unique' => true,
@ -56,17 +52,16 @@ final class PhrictionDocument extends PhrictionDAO
) + parent::getConfiguration(); ) + parent::getConfiguration();
} }
public function generatePHID() { public function getPHIDType() {
return PhabricatorPHID::generateNewPHID( return PhrictionDocumentPHIDType::TYPECONST;
PhrictionDocumentPHIDType::TYPECONST);
} }
public static function initializeNewDocument(PhabricatorUser $actor, $slug) { public static function initializeNewDocument(PhabricatorUser $actor, $slug) {
$document = new PhrictionDocument(); $document = id(new self())
$document->setSlug($slug); ->setSlug($slug);
$content = new PhrictionContent(); $content = id(new PhrictionContent())
$content->setSlug($slug); ->setSlug($slug);
$default_title = PhabricatorSlug::getDefaultTitle($slug); $default_title = PhabricatorSlug::getDefaultTitle($slug);
$content->setTitle($default_title); $content->setTitle($default_title);
@ -95,6 +90,8 @@ final class PhrictionDocument extends PhrictionDAO
->setSpacePHID($actor->getDefaultSpacePHID()); ->setSpacePHID($actor->getDefaultSpacePHID());
} }
$document->setEditedEpoch(PhabricatorTime::getNow());
return $document; return $document;
} }

View file

@ -1,7 +1,7 @@
<?php <?php
final class PhrictionDocumentContentTransaction final class PhrictionDocumentContentTransaction
extends PhrictionDocumentTransactionType { extends PhrictionDocumentVersionTransaction {
const TRANSACTIONTYPE = 'content'; const TRANSACTIONTYPE = 'content';
@ -18,10 +18,9 @@ final class PhrictionDocumentContentTransaction
public function applyInternalEffects($object, $value) { public function applyInternalEffects($object, $value) {
$object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS);
}
public function applyExternalEffects($object, $value) { $content = $this->getNewDocumentContent($object);
$this->getEditor()->getNewContent()->setContent($value); $content->setContent($value);
} }
public function shouldHide() { public function shouldHide() {

View file

@ -1,7 +1,7 @@
<?php <?php
final class PhrictionDocumentDeleteTransaction final class PhrictionDocumentDeleteTransaction
extends PhrictionDocumentTransactionType { extends PhrictionDocumentVersionTransaction {
const TRANSACTIONTYPE = 'delete'; const TRANSACTIONTYPE = 'delete';
@ -11,12 +11,11 @@ final class PhrictionDocumentDeleteTransaction
public function applyInternalEffects($object, $value) { public function applyInternalEffects($object, $value) {
$object->setStatus(PhrictionDocumentStatus::STATUS_DELETED); $object->setStatus(PhrictionDocumentStatus::STATUS_DELETED);
}
public function applyExternalEffects($object, $value) { $content = $this->getNewDocumentContent($object);
$this->getEditor()->getNewContent()->setContent('');
$this->getEditor()->getNewContent()->setChangeType( $content->setContent('');
PhrictionChangeType::CHANGE_DELETE); $content->setChangeType(PhrictionChangeType::CHANGE_DELETE);
} }
public function getActionStrength() { public function getActionStrength() {

View file

@ -1,7 +1,7 @@
<?php <?php
final class PhrictionDocumentMoveAwayTransaction final class PhrictionDocumentMoveAwayTransaction
extends PhrictionDocumentTransactionType { extends PhrictionDocumentVersionTransaction {
const TRANSACTIONTYPE = 'move-away'; const TRANSACTIONTYPE = 'move-away';
@ -22,14 +22,12 @@ final class PhrictionDocumentMoveAwayTransaction
public function applyInternalEffects($object, $value) { public function applyInternalEffects($object, $value) {
$object->setStatus(PhrictionDocumentStatus::STATUS_MOVED); $object->setStatus(PhrictionDocumentStatus::STATUS_MOVED);
}
public function applyExternalEffects($object, $value) { $content = $this->getNewDocumentContent($object);
$dict = $value;
$this->getEditor()->getNewContent()->setContent(''); $content->setContent('');
$this->getEditor()->getNewContent()->setChangeType( $content->setChangeType(PhrictionChangeType::CHANGE_MOVE_AWAY);
PhrictionChangeType::CHANGE_MOVE_AWAY); $content->setChangeRef($value['id']);
$this->getEditor()->getNewContent()->setChangeRef($dict['id']);
} }
public function getActionName() { public function getActionName() {

View file

@ -1,7 +1,7 @@
<?php <?php
final class PhrictionDocumentMoveToTransaction final class PhrictionDocumentMoveToTransaction
extends PhrictionDocumentTransactionType { extends PhrictionDocumentVersionTransaction {
const TRANSACTIONTYPE = 'move-to'; const TRANSACTIONTYPE = 'move-to';
@ -11,6 +11,7 @@ final class PhrictionDocumentMoveToTransaction
public function generateNewValue($object, $value) { public function generateNewValue($object, $value) {
$document = $value; $document = $value;
$dict = array( $dict = array(
'id' => $document->getID(), 'id' => $document->getID(),
'phid' => $document->getPHID(), 'phid' => $document->getPHID(),
@ -26,15 +27,13 @@ final class PhrictionDocumentMoveToTransaction
public function applyInternalEffects($object, $value) { public function applyInternalEffects($object, $value) {
$object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS);
}
public function applyExternalEffects($object, $value) { $content = $this->getNewDocumentContent($object);
$dict = $value;
$this->getEditor()->getNewContent()->setContent($dict['content']); $content->setContent($value['content']);
$this->getEditor()->getNewContent()->setTitle($dict['title']); $content->setTitle($value['title']);
$this->getEditor()->getNewContent()->setChangeType( $content->setChangeType(PhrictionChangeType::CHANGE_MOVE_HERE);
PhrictionChangeType::CHANGE_MOVE_HERE); $content->setChangeRef($value['id']);
$this->getEditor()->getNewContent()->setChangeRef($dict['id']);
} }
public function getActionStrength() { public function getActionStrength() {

View file

@ -1,7 +1,7 @@
<?php <?php
final class PhrictionDocumentTitleTransaction final class PhrictionDocumentTitleTransaction
extends PhrictionDocumentTransactionType { extends PhrictionDocumentVersionTransaction {
const TRANSACTIONTYPE = 'title'; const TRANSACTIONTYPE = 'title';
@ -14,10 +14,10 @@ final class PhrictionDocumentTitleTransaction
public function applyInternalEffects($object, $value) { public function applyInternalEffects($object, $value) {
$object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS);
}
public function applyExternalEffects($object, $value) { $content = $this->getNewDocumentContent($object);
$this->getEditor()->getNewContent()->setTitle($value);
$content->setTitle($value);
} }
public function getActionStrength() { public function getActionStrength() {

View file

@ -0,0 +1,10 @@
<?php
abstract class PhrictionDocumentVersionTransaction
extends PhrictionDocumentTransactionType {
protected function getNewDocumentContent($object) {
return $this->getEditor()->getNewDocumentContent($object);
}
}