1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01: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');
}
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() {
$data = $this->getStoryData();
@ -17,14 +26,45 @@ final class PhabricatorFeedStoryPhriction extends PhabricatorFeedStory {
$action = $data->getValue('action');
$verb = PhrictionActionConstants::getActionPastTenseVerb($action);
$view->setTitle(hsprintf(
'%s %s the document %s.',
$this->linkTo($author_phid),
$verb,
$this->linkTo($document_phid)));
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.',
$this->linkTo($author_phid),
$verb,
$this->linkTo($document_phid)));
break;
}
$view->setEpoch($data->getEpoch());
$action = $data->getValue('action');
switch ($action) {
case PhrictionActionConstants::ACTION_CREATE:
$full_size = true;

View file

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

View file

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

View file

@ -14,6 +14,9 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
private $newContent;
private $description;
// For the Feed Story when moving documents
private $fromDocumentPHID;
private function __construct() {
// <restricted>
}
@ -71,7 +74,8 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
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(
PhrictionChangeType::CHANGE_MOVE_HERE, false, $old_doc_id);
}
@ -181,11 +185,11 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
break;
case PhrictionChangeType::CHANGE_MOVE_AWAY:
$doc_status = PhrictionDocumentStatus::STATUS_MOVED;
$feed_action = PhrictionActionConstants::ACTION_MOVE_AWAY;
$feed_action = null;
break;
case PhrictionChangeType::CHANGE_MOVE_HERE:
$doc_status = PhrictionDocumentStatus::STATUS_EXISTS;
$feed_action = null;
$feed_action = PhrictionActionConstants::ACTION_MOVE_HERE;
break;
default:
throw new Exception(
@ -253,6 +257,10 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
$related_phids[] = $project_phid;
}
if ($this->fromDocumentPHID) {
$related_phids[] = $this->fromDocumentPHID;
}
if ($feed_action) {
id(new PhabricatorFeedStoryPublisher())
->setRelatedPHIDs($related_phids)
@ -261,10 +269,11 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_PHRICTION)
->setStoryData(
array(
'phid' => $document->getPHID(),
'action' => $feed_action,
'content' => phutil_utf8_shorten($new_content->getContent(), 140),
'project' => $project_phid,
'phid' => $document->getPHID(),
'action' => $feed_action,
'content' => phutil_utf8_shorten($new_content->getContent(), 140),
'project' => $project_phid,
'movedFromPHID' => $this->fromDocumentPHID,
))
->publish();
}