@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement update and history controllers in Phragment

Summary: Depends on D7726. This adds a history controller (for viewing a list of patches associated with a fragment) and an update controller, for creating a new patch of a fragment.

Test Plan: Updated and viewed history of fragments.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Maniphest Tasks: T4205

Differential Revision: https://secure.phabricator.com/D7727

+248 -30
+4
src/__phutil_library_map__.php
··· 2182 2182 'PhragmentFragmentQuery' => 'applications/phragment/query/PhragmentFragmentQuery.php', 2183 2183 'PhragmentFragmentVersion' => 'applications/phragment/storage/PhragmentFragmentVersion.php', 2184 2184 'PhragmentFragmentVersionQuery' => 'applications/phragment/query/PhragmentFragmentVersionQuery.php', 2185 + 'PhragmentHistoryController' => 'applications/phragment/controller/PhragmentHistoryController.php', 2185 2186 'PhragmentPHIDTypeFragment' => 'applications/phragment/phid/PhragmentPHIDTypeFragment.php', 2186 2187 'PhragmentPHIDTypeFragmentVersion' => 'applications/phragment/phid/PhragmentPHIDTypeFragmentVersion.php', 2187 2188 'PhragmentPatchUtil' => 'applications/phragment/util/PhragmentPatchUtil.php', 2189 + 'PhragmentUpdateController' => 'applications/phragment/controller/PhragmentUpdateController.php', 2188 2190 'PhrequentController' => 'applications/phrequent/controller/PhrequentController.php', 2189 2191 'PhrequentDAO' => 'applications/phrequent/storage/PhrequentDAO.php', 2190 2192 'PhrequentListController' => 'applications/phrequent/controller/PhrequentListController.php', ··· 4778 4780 1 => 'PhabricatorPolicyInterface', 4779 4781 ), 4780 4782 'PhragmentFragmentVersionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4783 + 'PhragmentHistoryController' => 'PhragmentController', 4781 4784 'PhragmentPHIDTypeFragment' => 'PhabricatorPHIDType', 4782 4785 'PhragmentPHIDTypeFragmentVersion' => 'PhabricatorPHIDType', 4783 4786 'PhragmentPatchUtil' => 'Phobject', 4787 + 'PhragmentUpdateController' => 'PhragmentController', 4784 4788 'PhrequentController' => 'PhabricatorController', 4785 4789 'PhrequentDAO' => 'PhabricatorLiskDAO', 4786 4790 'PhrequentListController' =>
+2
src/applications/phragment/application/PhabricatorApplicationPhragment.php
··· 36 36 '' => 'PhragmentBrowseController', 37 37 'browse/(?P<dblob>.*)' => 'PhragmentBrowseController', 38 38 'create/(?P<dblob>.*)' => 'PhragmentCreateController', 39 + 'update/(?P<dblob>.*)' => 'PhragmentUpdateController', 40 + 'history/(?P<dblob>.*)' => 'PhragmentHistoryController', 39 41 ), 40 42 ); 41 43 }
+2 -29
src/applications/phragment/controller/PhragmentBrowseController.php
··· 30 30 ->setHref($this->getApplicationURI('/create/'.$path)) 31 31 ->setIcon('create')); 32 32 33 - $current_box = $this->createCurrentFragmentView($current); 33 + $current_box = $this->createCurrentFragmentView($current, false); 34 34 35 35 $list = id(new PHUIObjectItemListView()) 36 36 ->setUser($viewer); ··· 74 74 $current_box, 75 75 $list), 76 76 array( 77 - 'title' => pht('Browse Phragments'), 77 + 'title' => pht('Browse Fragments'), 78 78 'device' => true)); 79 - } 80 - 81 - private function createCurrentFragmentView($fragment) { 82 - if ($fragment === null) { 83 - return null; 84 - } 85 - 86 - $viewer = $this->getRequest()->getUser(); 87 - 88 - $header = id(new PHUIHeaderView()) 89 - ->setHeader($fragment->getName()) 90 - ->setPolicyObject($fragment) 91 - ->setUser($viewer); 92 - $properties = new PHUIPropertyListView(); 93 - 94 - $phids = array(); 95 - $phids[] = $fragment->getLatestVersionPHID(); 96 - 97 - $this->loadHandles($phids); 98 - 99 - $properties->addProperty( 100 - pht('Latest Version'), 101 - $this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID()))); 102 - 103 - return id(new PHUIObjectBoxView()) 104 - ->setHeader($header) 105 - ->addPropertyList($properties); 106 79 } 107 80 108 81 }
+71
src/applications/phragment/controller/PhragmentController.php
··· 20 20 $fragments = array(); 21 21 $results = id(new PhragmentFragmentQuery()) 22 22 ->setViewer($this->getRequest()->getUser()) 23 + ->needLatestVersion(true) 23 24 ->withPaths($combinations) 24 25 ->execute(); 25 26 foreach ($combinations as $combination) { ··· 51 52 ->setHref('/phragment/browse/'.$parent->getPath())); 52 53 } 53 54 return $crumbs; 55 + } 56 + 57 + protected function createCurrentFragmentView($fragment, $is_history_view) { 58 + if ($fragment === null) { 59 + return null; 60 + } 61 + 62 + $viewer = $this->getRequest()->getUser(); 63 + 64 + $phids = array(); 65 + $phids[] = $fragment->getLatestVersionPHID(); 66 + 67 + $this->loadHandles($phids); 68 + 69 + $file = id(new PhabricatorFileQuery()) 70 + ->setViewer($viewer) 71 + ->withPHIDs(array($fragment->getLatestVersion()->getFilePHID())) 72 + ->executeOne(); 73 + $file_uri = null; 74 + if ($file !== null) { 75 + $file_uri = $file->getBestURI(); 76 + } 77 + 78 + $header = id(new PHUIHeaderView()) 79 + ->setHeader($fragment->getName()) 80 + ->setPolicyObject($fragment) 81 + ->setUser($viewer); 82 + 83 + $actions = id(new PhabricatorActionListView()) 84 + ->setUser($viewer) 85 + ->setObject($fragment) 86 + ->setObjectURI($fragment->getURI()); 87 + $actions->addAction( 88 + id(new PhabricatorActionView()) 89 + ->setName(pht('Download Fragment')) 90 + ->setHref($file_uri) 91 + ->setDisabled($file === null) 92 + ->setIcon('download')); 93 + $actions->addAction( 94 + id(new PhabricatorActionView()) 95 + ->setName(pht('Update Fragment')) 96 + ->setHref($this->getApplicationURI("update/".$fragment->getPath())) 97 + ->setDisabled(false) // TODO: Policy 98 + ->setIcon('edit')); 99 + if ($is_history_view) { 100 + $actions->addAction( 101 + id(new PhabricatorActionView()) 102 + ->setName(pht('View Child Fragments')) 103 + ->setHref($this->getApplicationURI("browse/".$fragment->getPath())) 104 + ->setIcon('browse')); 105 + } else { 106 + $actions->addAction( 107 + id(new PhabricatorActionView()) 108 + ->setName(pht('View History')) 109 + ->setHref($this->getApplicationURI("history/".$fragment->getPath())) 110 + ->setIcon('history')); 111 + } 112 + 113 + $properties = id(new PHUIPropertyListView()) 114 + ->setUser($viewer) 115 + ->setObject($fragment) 116 + ->setActionList($actions); 117 + 118 + $properties->addProperty( 119 + pht('Latest Version'), 120 + $this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID()))); 121 + 122 + return id(new PHUIObjectBoxView()) 123 + ->setHeader($header) 124 + ->addPropertyList($properties); 54 125 } 55 126 56 127 }
+1 -1
src/applications/phragment/controller/PhragmentCreateController.php
··· 134 134 $crumbs, 135 135 $box), 136 136 array( 137 - 'title' => pht('Create Phragment'), 137 + 'title' => pht('Create Fragment'), 138 138 'device' => true)); 139 139 } 140 140
+77
src/applications/phragment/controller/PhragmentHistoryController.php
··· 1 + <?php 2 + 3 + final class PhragmentHistoryController extends PhragmentController { 4 + 5 + private $dblob; 6 + 7 + public function willProcessRequest(array $data) { 8 + $this->dblob = idx($data, "dblob", ""); 9 + } 10 + 11 + public function processRequest() { 12 + $request = $this->getRequest(); 13 + $viewer = $request->getUser(); 14 + 15 + $parents = $this->loadParentFragments($this->dblob); 16 + if ($parents === null) { 17 + return new Aphront404Response(); 18 + } 19 + $current = idx($parents, count($parents) - 1, null); 20 + 21 + $path = $current->getPath(); 22 + 23 + $crumbs = $this->buildApplicationCrumbsWithPath($parents); 24 + $crumbs->addAction( 25 + id(new PHUIListItemView()) 26 + ->setName(pht('Create Fragment')) 27 + ->setHref($this->getApplicationURI('/create/'.$path)) 28 + ->setIcon('create')); 29 + 30 + $current_box = $this->createCurrentFragmentView($current, true); 31 + 32 + $versions = id(new PhragmentFragmentVersionQuery()) 33 + ->setViewer($viewer) 34 + ->withFragmentPHIDs(array($current->getPHID())) 35 + ->execute(); 36 + 37 + $list = id(new PHUIObjectItemListView()) 38 + ->setUser($viewer); 39 + 40 + $file_phids = mpull($versions, 'getFilePHID'); 41 + $files = id(new PhabricatorFileQuery()) 42 + ->setViewer($viewer) 43 + ->withPHIDs($file_phids) 44 + ->execute(); 45 + $files = mpull($files, null, 'getPHID'); 46 + 47 + foreach ($versions as $version) { 48 + $item = id(new PHUIObjectItemView()); 49 + $item->setHeader('Version '.$version->getSequence()); 50 + $item->addAttribute(phabricator_datetime( 51 + $version->getDateCreated(), 52 + $viewer)); 53 + 54 + $disabled = !isset($files[$version->getFilePHID()]); 55 + $action = id(new PHUIListItemView()) 56 + ->setIcon('download') 57 + ->setDisabled($disabled) 58 + ->setRenderNameAsTooltip(true) 59 + ->setName(pht("Download")); 60 + if (!$disabled) { 61 + $action->setHref($files[$version->getFilePHID()]->getBestURI()); 62 + } 63 + $item->addAction($action); 64 + $list->addItem($item); 65 + } 66 + 67 + return $this->buildApplicationPage( 68 + array( 69 + $crumbs, 70 + $current_box, 71 + $list), 72 + array( 73 + 'title' => pht('Fragment History'), 74 + 'device' => true)); 75 + } 76 + 77 + }
+91
src/applications/phragment/controller/PhragmentUpdateController.php
··· 1 + <?php 2 + 3 + final class PhragmentUpdateController extends PhragmentController { 4 + 5 + private $dblob; 6 + 7 + public function willProcessRequest(array $data) { 8 + $this->dblob = idx($data, "dblob", ""); 9 + } 10 + 11 + public function processRequest() { 12 + $request = $this->getRequest(); 13 + $viewer = $request->getUser(); 14 + 15 + $parents = $this->loadParentFragments($this->dblob); 16 + if ($parents === null) { 17 + return new Aphront404Response(); 18 + } 19 + $fragment = idx($parents, count($parents) - 1, null); 20 + 21 + $error_view = null; 22 + 23 + if ($request->isFormPost()) { 24 + $errors = array(); 25 + 26 + $v_fileid = $request->getInt('fileID'); 27 + 28 + $file = id(new PhabricatorFile())->load($v_fileid); 29 + if ($file === null) { 30 + $errors[] = pht('The specified file doesn\'t exist.'); 31 + } 32 + 33 + if (!count($errors)) { 34 + $existing = id(new PhragmentFragmentVersionQuery()) 35 + ->setViewer($viewer) 36 + ->withFragmentPHIDs(array($fragment->getPHID())) 37 + ->execute(); 38 + $sequence = count($existing); 39 + 40 + $fragment->openTransaction(); 41 + $version = id(new PhragmentFragmentVersion()); 42 + $version->setSequence($sequence); 43 + $version->setFragmentPHID($fragment->getPHID()); 44 + $version->setFilePHID($file->getPHID()); 45 + $version->save(); 46 + 47 + $fragment->setLatestVersionPHID($version->getPHID()); 48 + $fragment->save(); 49 + $fragment->saveTransaction(); 50 + 51 + return id(new AphrontRedirectResponse()) 52 + ->setURI('/phragment/browse/'.$fragment->getPath()); 53 + } else { 54 + $error_view = id(new AphrontErrorView()) 55 + ->setErrors($errors) 56 + ->setTitle(pht('Errors while updating fragment')); 57 + } 58 + } 59 + 60 + $form = id(new AphrontFormView()) 61 + ->setUser($viewer) 62 + ->appendChild( 63 + id(new AphrontFormTextControl()) 64 + ->setLabel(pht('File ID')) 65 + ->setName('fileID')) 66 + ->appendChild( 67 + id(new AphrontFormSubmitControl()) 68 + ->setValue(pht('Update Fragment')) 69 + ->addCancelButton( 70 + $this->getApplicationURI('browse/'.$fragment->getPath()))); 71 + 72 + $crumbs = $this->buildApplicationCrumbsWithPath($parents); 73 + $crumbs->addCrumb( 74 + id(new PhabricatorCrumbView()) 75 + ->setName(pht('Update Fragment'))); 76 + 77 + $box = id(new PHUIObjectBoxView()) 78 + ->setHeaderText(pht('Update Fragment: %s', $fragment->getPath())) 79 + ->setValidationException(null) 80 + ->setForm($form); 81 + 82 + return $this->buildApplicationPage( 83 + array( 84 + $crumbs, 85 + $box), 86 + array( 87 + 'title' => pht('Update Fragment'), 88 + 'device' => true)); 89 + } 90 + 91 + }