mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
Update Phriction Move Away transaction to modular transactions
Summary: Ref T12625 Test Plan: Move a document to a new location, verify the old and new document. Edit both. Grep for MOVE_AWAY Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T12625 Differential Revision: https://secure.phabricator.com/D17988
This commit is contained in:
parent
2325c61ad7
commit
b164d2d04b
4 changed files with 72 additions and 43 deletions
|
@ -4640,6 +4640,7 @@ phutil_register_library_map(array(
|
|||
'PhrictionDocumentHeraldAdapter' => 'applications/phriction/herald/PhrictionDocumentHeraldAdapter.php',
|
||||
'PhrictionDocumentHeraldField' => 'applications/phriction/herald/PhrictionDocumentHeraldField.php',
|
||||
'PhrictionDocumentHeraldFieldGroup' => 'applications/phriction/herald/PhrictionDocumentHeraldFieldGroup.php',
|
||||
'PhrictionDocumentMoveAwayTransaction' => 'applications/phriction/xaction/PhrictionDocumentMoveAwayTransaction.php',
|
||||
'PhrictionDocumentMoveToTransaction' => 'applications/phriction/xaction/PhrictionDocumentMoveToTransaction.php',
|
||||
'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php',
|
||||
'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php',
|
||||
|
@ -10303,6 +10304,7 @@ phutil_register_library_map(array(
|
|||
'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter',
|
||||
'PhrictionDocumentHeraldField' => 'HeraldField',
|
||||
'PhrictionDocumentHeraldFieldGroup' => 'HeraldFieldGroup',
|
||||
'PhrictionDocumentMoveAwayTransaction' => 'PhrictionDocumentTransactionType',
|
||||
'PhrictionDocumentMoveToTransaction' => 'PhrictionDocumentTransactionType',
|
||||
'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField',
|
||||
|
|
|
@ -86,7 +86,6 @@ final class PhrictionTransactionEditor
|
|||
$types = parent::getTransactionTypes();
|
||||
|
||||
$types[] = PhrictionTransaction::TYPE_CONTENT;
|
||||
$types[] = PhrictionTransaction::TYPE_MOVE_AWAY;
|
||||
|
||||
$types[] = PhabricatorTransactions::TYPE_EDGE;
|
||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||
|
@ -106,8 +105,6 @@ final class PhrictionTransactionEditor
|
|||
return null;
|
||||
}
|
||||
return $this->getOldContent()->getContent();
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,15 +115,6 @@ final class PhrictionTransactionEditor
|
|||
switch ($xaction->getTransactionType()) {
|
||||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
return $xaction->getNewValue();
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
$document = $xaction->getNewValue();
|
||||
$dict = array(
|
||||
'id' => $document->getID(),
|
||||
'phid' => $document->getPHID(),
|
||||
'content' => $document->getContent()->getContent(),
|
||||
'title' => $document->getContent()->getTitle(),
|
||||
);
|
||||
return $dict;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +128,7 @@ final class PhrictionTransactionEditor
|
|||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -163,9 +151,6 @@ final class PhrictionTransactionEditor
|
|||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
$object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS);
|
||||
return;
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
$object->setStatus(PhrictionDocumentStatus::STATUS_MOVED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,13 +198,6 @@ final class PhrictionTransactionEditor
|
|||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
$this->getNewContent()->setContent($xaction->getNewValue());
|
||||
break;
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
$dict = $xaction->getNewValue();
|
||||
$this->getNewContent()->setContent('');
|
||||
$this->getNewContent()->setChangeType(
|
||||
PhrictionChangeType::CHANGE_MOVE_AWAY);
|
||||
$this->getNewContent()->setChangeRef($dict['id']);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -234,9 +212,9 @@ final class PhrictionTransactionEditor
|
|||
switch ($xaction->getTransactionType()) {
|
||||
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
|
||||
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE:
|
||||
case PhrictionTransaction::TYPE_MOVE_AWAY:
|
||||
case PhrictionTransaction::TYPE_CONTENT:
|
||||
$save_content = true;
|
||||
break;
|
||||
default:
|
||||
|
@ -303,7 +281,8 @@ final class PhrictionTransactionEditor
|
|||
if ($this->moveAwayDocument !== null) {
|
||||
$move_away_xactions = array();
|
||||
$move_away_xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhrictionTransaction::TYPE_MOVE_AWAY)
|
||||
->setTransactionType(
|
||||
PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($object);
|
||||
$sub_editor = id(new PhrictionTransactionEditor())
|
||||
->setActor($this->getActor())
|
||||
|
|
|
@ -4,7 +4,6 @@ final class PhrictionTransaction
|
|||
extends PhabricatorModularTransaction {
|
||||
|
||||
const TYPE_CONTENT = 'content';
|
||||
const TYPE_MOVE_AWAY = 'move-away';
|
||||
|
||||
const MAILTAG_TITLE = 'phriction-title';
|
||||
const MAILTAG_CONTENT = 'phriction-content';
|
||||
|
@ -33,7 +32,7 @@ final class PhrictionTransaction
|
|||
$new = $this->getNewValue();
|
||||
switch ($this->getTransactionType()) {
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
|
||||
$phids[] = $new['phid'];
|
||||
break;
|
||||
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
|
||||
|
@ -75,7 +74,7 @@ final class PhrictionTransaction
|
|||
public function shouldHideForMail(array $xactions) {
|
||||
switch ($this->getTransactionType()) {
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
|
||||
return true;
|
||||
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
|
||||
return $this->getMetadataValue('stub:create:phid', false);
|
||||
|
@ -86,7 +85,7 @@ final class PhrictionTransaction
|
|||
public function shouldHideForFeed() {
|
||||
switch ($this->getTransactionType()) {
|
||||
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
|
||||
return true;
|
||||
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
|
||||
return $this->getMetadataValue('stub:create:phid', false);
|
||||
|
@ -98,8 +97,6 @@ final class PhrictionTransaction
|
|||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
return 1.3;
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return parent::getActionStrength();
|
||||
|
@ -112,8 +109,6 @@ final class PhrictionTransaction
|
|||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
return pht('Edited');
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return pht('Moved Away');
|
||||
}
|
||||
|
||||
return parent::getActionName();
|
||||
|
@ -126,8 +121,6 @@ final class PhrictionTransaction
|
|||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
return 'fa-pencil';
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return 'fa-arrows';
|
||||
}
|
||||
|
||||
return parent::getIcon();
|
||||
|
@ -145,13 +138,6 @@ final class PhrictionTransaction
|
|||
return pht(
|
||||
'%s edited the document content.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
|
||||
case self::TYPE_MOVE_AWAY:
|
||||
return pht(
|
||||
'%s moved this document to %s',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($new['phid']));
|
||||
|
||||
}
|
||||
|
||||
return parent::getTitle();
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
final class PhrictionDocumentMoveAwayTransaction
|
||||
extends PhrictionDocumentTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'move-away';
|
||||
|
||||
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_MOVED);
|
||||
}
|
||||
|
||||
public function applyExternalEffects($object, $value) {
|
||||
$dict = $value;
|
||||
$this->getEditor()->getNewContent()->setContent('');
|
||||
$this->getEditor()->getNewContent()->setChangeType(
|
||||
PhrictionChangeType::CHANGE_MOVE_AWAY);
|
||||
$this->getEditor()->getNewContent()->setChangeRef($dict['id']);
|
||||
}
|
||||
|
||||
public function getActionName() {
|
||||
return pht('Moved Away');
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$new = $this->getNewValue();
|
||||
|
||||
return pht(
|
||||
'%s moved this document to %s',
|
||||
$this->renderAuthor(),
|
||||
$this->renderHandleLink($new['phid']));
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$new = $this->getNewValue();
|
||||
|
||||
return pht(
|
||||
'%s moved %s to %s',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject(),
|
||||
$this->renderHandleLink($new['phid']));
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
return 'fa-arrows';
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue