1
0
Fork 0
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:
Chad Little 2017-05-22 15:40:16 -07:00
parent 2325c61ad7
commit b164d2d04b
4 changed files with 72 additions and 43 deletions

View file

@ -4640,6 +4640,7 @@ phutil_register_library_map(array(
'PhrictionDocumentHeraldAdapter' => 'applications/phriction/herald/PhrictionDocumentHeraldAdapter.php', 'PhrictionDocumentHeraldAdapter' => 'applications/phriction/herald/PhrictionDocumentHeraldAdapter.php',
'PhrictionDocumentHeraldField' => 'applications/phriction/herald/PhrictionDocumentHeraldField.php', 'PhrictionDocumentHeraldField' => 'applications/phriction/herald/PhrictionDocumentHeraldField.php',
'PhrictionDocumentHeraldFieldGroup' => 'applications/phriction/herald/PhrictionDocumentHeraldFieldGroup.php', 'PhrictionDocumentHeraldFieldGroup' => 'applications/phriction/herald/PhrictionDocumentHeraldFieldGroup.php',
'PhrictionDocumentMoveAwayTransaction' => 'applications/phriction/xaction/PhrictionDocumentMoveAwayTransaction.php',
'PhrictionDocumentMoveToTransaction' => 'applications/phriction/xaction/PhrictionDocumentMoveToTransaction.php', 'PhrictionDocumentMoveToTransaction' => 'applications/phriction/xaction/PhrictionDocumentMoveToTransaction.php',
'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php', 'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php',
'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php', 'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php',
@ -10303,6 +10304,7 @@ phutil_register_library_map(array(
'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter', 'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter',
'PhrictionDocumentHeraldField' => 'HeraldField', 'PhrictionDocumentHeraldField' => 'HeraldField',
'PhrictionDocumentHeraldFieldGroup' => 'HeraldFieldGroup', 'PhrictionDocumentHeraldFieldGroup' => 'HeraldFieldGroup',
'PhrictionDocumentMoveAwayTransaction' => 'PhrictionDocumentTransactionType',
'PhrictionDocumentMoveToTransaction' => 'PhrictionDocumentTransactionType', 'PhrictionDocumentMoveToTransaction' => 'PhrictionDocumentTransactionType',
'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType', 'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType',
'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField',

View file

@ -86,7 +86,6 @@ final class PhrictionTransactionEditor
$types = parent::getTransactionTypes(); $types = parent::getTransactionTypes();
$types[] = PhrictionTransaction::TYPE_CONTENT; $types[] = PhrictionTransaction::TYPE_CONTENT;
$types[] = PhrictionTransaction::TYPE_MOVE_AWAY;
$types[] = PhabricatorTransactions::TYPE_EDGE; $types[] = PhabricatorTransactions::TYPE_EDGE;
$types[] = PhabricatorTransactions::TYPE_COMMENT; $types[] = PhabricatorTransactions::TYPE_COMMENT;
@ -106,8 +105,6 @@ final class PhrictionTransactionEditor
return null; return null;
} }
return $this->getOldContent()->getContent(); return $this->getOldContent()->getContent();
case PhrictionTransaction::TYPE_MOVE_AWAY:
return null;
} }
} }
@ -118,15 +115,6 @@ final class PhrictionTransactionEditor
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhrictionTransaction::TYPE_CONTENT: case PhrictionTransaction::TYPE_CONTENT:
return $xaction->getNewValue(); 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 PhrictionTransaction::TYPE_CONTENT:
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE:
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
case PhrictionTransaction::TYPE_MOVE_AWAY: case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
return true; return true;
} }
} }
@ -163,9 +151,6 @@ final class PhrictionTransactionEditor
case PhrictionTransaction::TYPE_CONTENT: case PhrictionTransaction::TYPE_CONTENT:
$object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS);
return; return;
case PhrictionTransaction::TYPE_MOVE_AWAY:
$object->setStatus(PhrictionDocumentStatus::STATUS_MOVED);
return;
} }
} }
@ -213,13 +198,6 @@ final class PhrictionTransactionEditor
case PhrictionTransaction::TYPE_CONTENT: case PhrictionTransaction::TYPE_CONTENT:
$this->getNewContent()->setContent($xaction->getNewValue()); $this->getNewContent()->setContent($xaction->getNewValue());
break; 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: default:
break; break;
} }
@ -234,9 +212,9 @@ final class PhrictionTransactionEditor
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
case PhrictionTransaction::TYPE_CONTENT: case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE: case PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE:
case PhrictionTransaction::TYPE_MOVE_AWAY: case PhrictionTransaction::TYPE_CONTENT:
$save_content = true; $save_content = true;
break; break;
default: default:
@ -303,7 +281,8 @@ final class PhrictionTransactionEditor
if ($this->moveAwayDocument !== null) { if ($this->moveAwayDocument !== null) {
$move_away_xactions = array(); $move_away_xactions = array();
$move_away_xactions[] = id(new PhrictionTransaction()) $move_away_xactions[] = id(new PhrictionTransaction())
->setTransactionType(PhrictionTransaction::TYPE_MOVE_AWAY) ->setTransactionType(
PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE)
->setNewValue($object); ->setNewValue($object);
$sub_editor = id(new PhrictionTransactionEditor()) $sub_editor = id(new PhrictionTransactionEditor())
->setActor($this->getActor()) ->setActor($this->getActor())

View file

@ -4,7 +4,6 @@ final class PhrictionTransaction
extends PhabricatorModularTransaction { extends PhabricatorModularTransaction {
const TYPE_CONTENT = 'content'; const TYPE_CONTENT = 'content';
const TYPE_MOVE_AWAY = 'move-away';
const MAILTAG_TITLE = 'phriction-title'; const MAILTAG_TITLE = 'phriction-title';
const MAILTAG_CONTENT = 'phriction-content'; const MAILTAG_CONTENT = 'phriction-content';
@ -33,7 +32,7 @@ final class PhrictionTransaction
$new = $this->getNewValue(); $new = $this->getNewValue();
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
case self::TYPE_MOVE_AWAY: case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
$phids[] = $new['phid']; $phids[] = $new['phid'];
break; break;
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
@ -75,7 +74,7 @@ final class PhrictionTransaction
public function shouldHideForMail(array $xactions) { public function shouldHideForMail(array $xactions) {
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
case self::TYPE_MOVE_AWAY: case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
return true; return true;
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
return $this->getMetadataValue('stub:create:phid', false); return $this->getMetadataValue('stub:create:phid', false);
@ -86,7 +85,7 @@ final class PhrictionTransaction
public function shouldHideForFeed() { public function shouldHideForFeed() {
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE: case PhrictionDocumentMoveToTransaction::TRANSACTIONTYPE:
case self::TYPE_MOVE_AWAY: case PhrictionDocumentMoveAwayTransaction::TRANSACTIONTYPE:
return true; return true;
case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE: case PhrictionDocumentTitleTransaction::TRANSACTIONTYPE:
return $this->getMetadataValue('stub:create:phid', false); return $this->getMetadataValue('stub:create:phid', false);
@ -98,8 +97,6 @@ final class PhrictionTransaction
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_CONTENT: case self::TYPE_CONTENT:
return 1.3; return 1.3;
case self::TYPE_MOVE_AWAY:
return 1.0;
} }
return parent::getActionStrength(); return parent::getActionStrength();
@ -112,8 +109,6 @@ final class PhrictionTransaction
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_CONTENT: case self::TYPE_CONTENT:
return pht('Edited'); return pht('Edited');
case self::TYPE_MOVE_AWAY:
return pht('Moved Away');
} }
return parent::getActionName(); return parent::getActionName();
@ -126,8 +121,6 @@ final class PhrictionTransaction
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_CONTENT: case self::TYPE_CONTENT:
return 'fa-pencil'; return 'fa-pencil';
case self::TYPE_MOVE_AWAY:
return 'fa-arrows';
} }
return parent::getIcon(); return parent::getIcon();
@ -145,13 +138,6 @@ final class PhrictionTransaction
return pht( return pht(
'%s edited the document content.', '%s edited the document content.',
$this->renderHandleLink($author_phid)); $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(); return parent::getTitle();

View file

@ -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';
}
}