@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 108 lines 2.6 kB view raw
1<?php 2 3final class PhrictionDocumentMoveToTransaction 4 extends PhrictionDocumentVersionTransaction { 5 6 const TRANSACTIONTYPE = 'move-to'; 7 8 public function generateOldValue($object) { 9 return null; 10 } 11 12 public function generateNewValue($object, $value) { 13 $document = $value; 14 15 $dict = array( 16 'id' => $document->getID(), 17 'phid' => $document->getPHID(), 18 'content' => $document->getContent()->getContent(), 19 'title' => $document->getContent()->getTitle(), 20 ); 21 22 $editor = $this->getEditor(); 23 $editor->setMoveAwayDocument($document); 24 25 return $dict; 26 } 27 28 public function applyInternalEffects($object, $value) { 29 $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS); 30 31 $content = $this->getNewDocumentContent($object); 32 33 $content->setContent($value['content']); 34 $content->setTitle($value['title']); 35 $content->setChangeType(PhrictionChangeType::CHANGE_MOVE_HERE); 36 $content->setChangeRef($value['id']); 37 } 38 39 public function getActionStrength() { 40 return 100; 41 } 42 43 public function getActionName() { 44 return pht('Moved'); 45 } 46 47 public function getTitle() { 48 $old = $this->getOldValue(); 49 $new = $this->getNewValue(); 50 51 return pht( 52 '%s moved this document from %s.', 53 $this->renderAuthor(), 54 $this->renderHandle($new['phid'])); 55 } 56 57 public function getTitleForFeed() { 58 $old = $this->getOldValue(); 59 $new = $this->getNewValue(); 60 61 return pht( 62 '%s moved %s from %s', 63 $this->renderAuthor(), 64 $this->renderObject(), 65 $this->renderHandle($new['phid'])); 66 } 67 68 public function validateTransactions($object, array $xactions) { 69 $errors = array(); 70 71 $e_text = null; 72 foreach ($xactions as $xaction) { 73 $source_document = $xaction->getNewValue(); 74 switch ($source_document->getStatus()) { 75 case PhrictionDocumentStatus::STATUS_DELETED: 76 $e_text = pht('A deleted document can not be moved.'); 77 break; 78 case PhrictionDocumentStatus::STATUS_MOVED: 79 $e_text = pht('A moved document can not be moved again.'); 80 break; 81 case PhrictionDocumentStatus::STATUS_STUB: 82 $e_text = pht('A stub document can not be moved.'); 83 break; 84 default: 85 $e_text = null; 86 break; 87 } 88 89 if ($e_text !== null) { 90 $errors[] = $this->newInvalidError($e_text); 91 } 92 93 } 94 95 // TODO: Move Ancestry validation here once all types are converted. 96 97 return $errors; 98 } 99 100 public function getIcon() { 101 return 'fa-arrows'; 102 } 103 104 public function shouldHideForFeed() { 105 return true; 106 } 107 108}