mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-28 12:08:14 +01:00
Move Phriction MOVE_TO transaction to Modular Transactions
Summary: Moves this transaction over to modular transactions. Test Plan: Move a document, re-title a document, try to move over an existing document. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D17918
This commit is contained in:
parent
0ed496de22
commit
abc9bc77b2
5 changed files with 119 additions and 66 deletions
|
@ -4617,6 +4617,7 @@ phutil_register_library_map(array(
|
|||
'PhrictionDocumentHeraldAdapter' => 'applications/phriction/herald/PhrictionDocumentHeraldAdapter.php',
|
||||
'PhrictionDocumentHeraldField' => 'applications/phriction/herald/PhrictionDocumentHeraldField.php',
|
||||
'PhrictionDocumentHeraldFieldGroup' => 'applications/phriction/herald/PhrictionDocumentHeraldFieldGroup.php',
|
||||
'PhrictionDocumentMoveToTransaction' => 'applications/phriction/xaction/PhrictionDocumentMoveToTransaction.php',
|
||||
'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php',
|
||||
'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php',
|
||||
'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php',
|
||||
|
@ -10256,6 +10257,7 @@ phutil_register_library_map(array(
|
|||
'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter',
|
||||
'PhrictionDocumentHeraldField' => 'HeraldField',
|
||||
'PhrictionDocumentHeraldFieldGroup' => 'HeraldFieldGroup',
|
||||
'PhrictionDocumentMoveToTransaction' => 'PhrictionDocumentTransactionType',
|
||||
'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField',
|
||||
'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
|
|
|
@ -64,7 +64,8 @@ final class PhrictionMoveController extends PhrictionController {
|
|||
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhrictionTransaction::TYPE_MOVE_TO)
|
||||
->setTransactionType(
|
||||
PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($document);
|
||||
$target_document = id(new PhrictionDocumentQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
|
@ -88,7 +89,8 @@ final class PhrictionMoveController extends PhrictionController {
|
|||
return id(new AphrontRedirectResponse())->setURI($redir_uri);
|
||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||
$validation_exception = $ex;
|
||||
$e_slug = $ex->getShortMessage(PhrictionTransaction::TYPE_MOVE_TO);
|
||||
$e_slug = $ex->getShortMessage(
|
||||
PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,6 @@ final class PhrictionTransactionEditor
|
|||
|
||||
$types[] = PhrictionTransaction::TYPE_CONTENT;
|
||||
$types[] = PhrictionTransaction::TYPE_DELETE;
|
||||
$types[] = PhrictionTransaction::TYPE_MOVE_TO;
|
||||
$types[] = PhrictionTransaction::TYPE_MOVE_AWAY;
|
||||
|
||||
$types[] = PhabricatorTransactions::TYPE_EDGE;
|
||||
|
@ -104,7 +103,6 @@ final class PhrictionTransactionEditor
|
|||
}
|
||||
return $this->getOldContent()->getContent();
|
||||
case PhrictionTransaction::TYPE_DELETE:
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
return null;
|
||||
}
|
||||
|
@ -118,17 +116,11 @@ final class PhrictionTransactionEditor
|
|||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
case PhrictionTransaction::TYPE_DELETE:
|
||||
return $xaction->getNewValue();
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
$document = $xaction->getNewValue();
|
||||
// grab the real object now for the sub-editor to come
|
||||
$this->moveAwayDocument = $document;
|
||||
$dict = array(
|
||||
'id' => $document->getID(),
|
||||
'phid' => $document->getPHID(),
|
||||
'content' => $document->getContent()->getContent(),
|
||||
'title' => $document->getContent()->getTitle(),
|
||||
);
|
||||
return $dict;
|
||||
return;
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
$document = $xaction->getNewValue();
|
||||
$dict = array(
|
||||
|
@ -150,7 +142,7 @@ final class PhrictionTransactionEditor
|
|||
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
|
||||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
case PhrictionTransaction::TYPE_DELETE:
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
return true;
|
||||
}
|
||||
|
@ -172,9 +164,6 @@ final class PhrictionTransactionEditor
|
|||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
$object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS);
|
||||
return;
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
$object->setStatus(PhrictionDocumentStatus::STATUS_MOVED);
|
||||
return;
|
||||
|
@ -202,7 +191,7 @@ final class PhrictionTransactionEditor
|
|||
->setMetadataValue('contentDelete', true);
|
||||
}
|
||||
break;
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
$document = $xaction->getNewValue();
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
||||
|
@ -232,14 +221,6 @@ final class PhrictionTransactionEditor
|
|||
$this->getNewContent()->setChangeType(
|
||||
PhrictionChangeType::CHANGE_DELETE);
|
||||
break;
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
$dict = $xaction->getNewValue();
|
||||
$this->getNewContent()->setContent($dict['content']);
|
||||
$this->getNewContent()->setTitle($dict['title']);
|
||||
$this->getNewContent()->setChangeType(
|
||||
PhrictionChangeType::CHANGE_MOVE_HERE);
|
||||
$this->getNewContent()->setChangeRef($dict['id']);
|
||||
break;
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
$dict = $xaction->getNewValue();
|
||||
$this->getNewContent()->setContent('');
|
||||
|
@ -263,7 +244,7 @@ final class PhrictionTransactionEditor
|
|||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
case PhrictionTransaction::TYPE_DELETE:
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
$save_content = true;
|
||||
break;
|
||||
default:
|
||||
|
@ -448,7 +429,7 @@ final class PhrictionTransactionEditor
|
|||
|
||||
foreach ($xactions as $xaction) {
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
$dict = $xaction->getNewValue();
|
||||
$phids[] = $dict['phid'];
|
||||
break;
|
||||
|
@ -510,31 +491,8 @@ final class PhrictionTransactionEditor
|
|||
|
||||
break;
|
||||
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
$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;
|
||||
}
|
||||
|
||||
$ancestry_errors = $this->validateAncestry(
|
||||
$object,
|
||||
|
@ -611,7 +569,7 @@ final class PhrictionTransactionEditor
|
|||
return $errors;
|
||||
}
|
||||
|
||||
private function validateAncestry(
|
||||
public function validateAncestry(
|
||||
PhabricatorLiskDAO $object,
|
||||
$type,
|
||||
PhabricatorApplicationTransaction $xaction,
|
||||
|
|
|
@ -5,7 +5,6 @@ final class PhrictionTransaction
|
|||
|
||||
const TYPE_CONTENT = 'content';
|
||||
const TYPE_DELETE = 'delete';
|
||||
const TYPE_MOVE_TO = 'move-to';
|
||||
const TYPE_MOVE_AWAY = 'move-away';
|
||||
|
||||
const MAILTAG_TITLE = 'phriction-title';
|
||||
|
@ -34,7 +33,7 @@ final class PhrictionTransaction
|
|||
$phids = parent::getRequiredHandlePHIDs();
|
||||
$new = $this->getNewValue();
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_MOVE_TO:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
$phids[] = $new['phid'];
|
||||
break;
|
||||
|
@ -76,7 +75,7 @@ final class PhrictionTransaction
|
|||
|
||||
public function shouldHideForMail(array $xactions) {
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_MOVE_TO:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return true;
|
||||
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
|
||||
|
@ -87,7 +86,7 @@ final class PhrictionTransaction
|
|||
|
||||
public function shouldHideForFeed() {
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_MOVE_TO:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return true;
|
||||
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
|
||||
|
@ -102,7 +101,6 @@ final class PhrictionTransaction
|
|||
return 1.3;
|
||||
case self::TYPE_DELETE:
|
||||
return 1.5;
|
||||
case self::TYPE_MOVE_TO:
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return 1.0;
|
||||
}
|
||||
|
@ -119,8 +117,6 @@ final class PhrictionTransaction
|
|||
return pht('Edited');
|
||||
case self::TYPE_DELETE:
|
||||
return pht('Deleted');
|
||||
case self::TYPE_MOVE_TO:
|
||||
return pht('Moved');
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return pht('Moved Away');
|
||||
}
|
||||
|
@ -137,7 +133,6 @@ final class PhrictionTransaction
|
|||
return 'fa-pencil';
|
||||
case self::TYPE_DELETE:
|
||||
return 'fa-times';
|
||||
case self::TYPE_MOVE_TO:
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return 'fa-arrows';
|
||||
}
|
||||
|
@ -163,12 +158,6 @@ final class PhrictionTransaction
|
|||
'%s deleted this document.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
|
||||
case self::TYPE_MOVE_TO:
|
||||
return pht(
|
||||
'%s moved this document from %s',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($new['phid']));
|
||||
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return pht(
|
||||
'%s moved this document to %s',
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
final class PhrictionDocumentMoveToTransaction
|
||||
extends PhrictionDocumentTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'move-to';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function generateNewValue($object, $value) {
|
||||
$document = $value;
|
||||
$dict = array(
|
||||
'id' => $document->getID(),
|
||||
'phid' => $document->getPHID(),
|
||||
'content' => $document->getContent()->getContent(),
|
||||
'title' => $document->getContent()->getTitle(),
|
||||
);
|
||||
return $dict;
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS);
|
||||
$this->getEditor()->getNewContent()->setTitle($value);
|
||||
}
|
||||
|
||||
public function applyExternalEffects($object, $value) {
|
||||
$dict = $value;
|
||||
$this->getEditor()->getNewContent()->setContent($dict['content']);
|
||||
$this->getEditor()->getNewContent()->setTitle($dict['title']);
|
||||
$this->getEditor()->getNewContent()->setChangeType(
|
||||
PhrictionChangeType::CHANGE_MOVE_HERE);
|
||||
$this->getEditor()->getNewContent()->setChangeRef($dict['id']);
|
||||
}
|
||||
|
||||
public function getActionStrength() {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
public function getActionName() {
|
||||
return pht('Moved');
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
return pht(
|
||||
'%s moved this document from %s',
|
||||
$this->renderAuthor(),
|
||||
$this->renderHandle($new['phid']));
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
return pht(
|
||||
'%s moved %s from %s',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject(),
|
||||
$this->renderHandle($new['phid']));
|
||||
}
|
||||
|
||||
public function validateTransactions($object, array $xactions) {
|
||||
$errors = array();
|
||||
|
||||
$e_text = null;
|
||||
foreach ($xactions as $xaction) {
|
||||
$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 !== null) {
|
||||
$errors[] = $this->newInvalidError($e_text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO: Move Ancestry validation here once all types are converted.
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
return 'fa-arrows';
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue