1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Adding a proper story feed for moving a Phriction Document

Summary: Display a proper feed title when moving Phriction Documents.

Test Plan:
{F36112, size=full}

Descriptions for the feeds you see in the image.

 # New and cool story feed
 # Fallback for the boring old ones
 # Normal story feed, unchanged

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2686

Differential Revision: https://secure.phabricator.com/D5352
This commit is contained in:
Anh Nhan Nguyen 2013-03-19 14:22:26 -07:00 committed by epriestley
parent e3a9ddfc4f
commit 3b801fa567
4 changed files with 65 additions and 16 deletions

View file

@ -6,6 +6,15 @@ final class PhabricatorFeedStoryPhriction extends PhabricatorFeedStory {
return $this->getValue('phid'); return $this->getValue('phid');
} }
public function getRequiredHandlePHIDs() {
$required_phids = parent::getRequiredHandlePHIDs();
$from_phid = $this->getStoryData()->getValue('movedFromPHID');
if ($from_phid) {
$required_phids[] = $from_phid;
}
return $required_phids;
}
public function renderView() { public function renderView() {
$data = $this->getStoryData(); $data = $this->getStoryData();
@ -17,14 +26,45 @@ final class PhabricatorFeedStoryPhriction extends PhabricatorFeedStory {
$action = $data->getValue('action'); $action = $data->getValue('action');
$verb = PhrictionActionConstants::getActionPastTenseVerb($action); $verb = PhrictionActionConstants::getActionPastTenseVerb($action);
$view->setTitle(hsprintf( switch ($action) {
case PhrictionActionConstants::ACTION_MOVE_HERE:
$from_phid = $data->getValue('movedFromPHID');
// Older feed stories may not have 'moved_from_phid', in that case
// we fall back to the default behaviour (hence the fallthrough)
if ($from_phid) {
$document_handle = $this->getHandle($document_phid);
$from_handle = $this->getHandle($from_phid);
$view->setTitle(pht(
'%s moved the document %s from %s to %s.',
$this->linkTo($author_phid),
$document_handle->renderLink(),
phutil_tag(
'a',
array(
'href' => $from_handle->getURI(),
),
$from_handle->getURI()),
phutil_tag(
'a',
array(
'href' => $document_handle->getURI(),
),
$document_handle->getURI())));
break;
}
/* Fallthrough */
default:
$view->setTitle(pht(
'%s %s the document %s.', '%s %s the document %s.',
$this->linkTo($author_phid), $this->linkTo($author_phid),
$verb, $verb,
$this->linkTo($document_phid))); $this->linkTo($document_phid)));
break;
}
$view->setEpoch($data->getEpoch()); $view->setEpoch($data->getEpoch());
$action = $data->getValue('action');
switch ($action) { switch ($action) {
case PhrictionActionConstants::ACTION_CREATE: case PhrictionActionConstants::ACTION_CREATE:
$full_size = true; $full_size = true;

View file

@ -16,8 +16,8 @@ final class PhrictionActionConstants extends PhrictionConstants {
self::ACTION_CREATE => 'created', self::ACTION_CREATE => 'created',
self::ACTION_EDIT => 'edited', self::ACTION_EDIT => 'edited',
self::ACTION_DELETE => 'deleted', self::ACTION_DELETE => 'deleted',
self::ACTION_MOVE_AWAY => 'moved a document to', self::ACTION_MOVE_AWAY => 'moved',
self::ACTION_MOVE_HERE => 'moved a document from', self::ACTION_MOVE_HERE => 'moved',
); );
return idx($map, $action, "brazenly {$action}'d"); return idx($map, $action, "brazenly {$action}'d");

View file

@ -102,7 +102,7 @@ final class PhrictionMoveController
->setDescription($content->getDescription()); ->setDescription($content->getDescription());
// Move it! // Move it!
$target_editor->moveHere($document->getID()); $target_editor->moveHere($document->getID(), $document->getPHID());
// Retrieve the target doc directly from the editor // Retrieve the target doc directly from the editor
// No need to load it per Sql again // No need to load it per Sql again

View file

@ -14,6 +14,9 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
private $newContent; private $newContent;
private $description; private $description;
// For the Feed Story when moving documents
private $fromDocumentPHID;
private function __construct() { private function __construct() {
// <restricted> // <restricted>
} }
@ -71,7 +74,8 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
PhrictionChangeType::CHANGE_MOVE_AWAY, true, $new_doc_id); PhrictionChangeType::CHANGE_MOVE_AWAY, true, $new_doc_id);
} }
public function moveHere($old_doc_id) { public function moveHere($old_doc_id, $old_doc_phid) {
$this->fromDocumentPHID = $old_doc_phid;
return $this->execute( return $this->execute(
PhrictionChangeType::CHANGE_MOVE_HERE, false, $old_doc_id); PhrictionChangeType::CHANGE_MOVE_HERE, false, $old_doc_id);
} }
@ -181,11 +185,11 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
break; break;
case PhrictionChangeType::CHANGE_MOVE_AWAY: case PhrictionChangeType::CHANGE_MOVE_AWAY:
$doc_status = PhrictionDocumentStatus::STATUS_MOVED; $doc_status = PhrictionDocumentStatus::STATUS_MOVED;
$feed_action = PhrictionActionConstants::ACTION_MOVE_AWAY; $feed_action = null;
break; break;
case PhrictionChangeType::CHANGE_MOVE_HERE: case PhrictionChangeType::CHANGE_MOVE_HERE:
$doc_status = PhrictionDocumentStatus::STATUS_EXISTS; $doc_status = PhrictionDocumentStatus::STATUS_EXISTS;
$feed_action = null; $feed_action = PhrictionActionConstants::ACTION_MOVE_HERE;
break; break;
default: default:
throw new Exception( throw new Exception(
@ -253,6 +257,10 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
$related_phids[] = $project_phid; $related_phids[] = $project_phid;
} }
if ($this->fromDocumentPHID) {
$related_phids[] = $this->fromDocumentPHID;
}
if ($feed_action) { if ($feed_action) {
id(new PhabricatorFeedStoryPublisher()) id(new PhabricatorFeedStoryPublisher())
->setRelatedPHIDs($related_phids) ->setRelatedPHIDs($related_phids)
@ -265,6 +273,7 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
'action' => $feed_action, 'action' => $feed_action,
'content' => phutil_utf8_shorten($new_content->getContent(), 140), 'content' => phutil_utf8_shorten($new_content->getContent(), 140),
'project' => $project_phid, 'project' => $project_phid,
'movedFromPHID' => $this->fromDocumentPHID,
)) ))
->publish(); ->publish();
} }