@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.

Viewerize ArcBundle file loading callbacks

Summary: Ref T603. Clean these up and move them to a single place.

Test Plan:
- Downloaded a raw diff.
- Enabled "attach diffs", created a revision, got an email with a diff.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

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

+43 -25
+1
src/__phutil_library_map__.php
··· 1185 1185 'PhabricatorFeedStoryStatus' => 'applications/feed/story/PhabricatorFeedStoryStatus.php', 1186 1186 'PhabricatorFeedStoryTypeConstants' => 'applications/feed/constants/PhabricatorFeedStoryTypeConstants.php', 1187 1187 'PhabricatorFile' => 'applications/files/storage/PhabricatorFile.php', 1188 + 'PhabricatorFileBundleLoader' => 'applications/files/query/PhabricatorFileBundleLoader.php', 1188 1189 'PhabricatorFileCommentController' => 'applications/files/controller/PhabricatorFileCommentController.php', 1189 1190 'PhabricatorFileController' => 'applications/files/controller/PhabricatorFileController.php', 1190 1191 'PhabricatorFileDAO' => 'applications/files/storage/PhabricatorFileDAO.php',
+7 -23
src/applications/differential/controller/DifferentialRevisionViewController.php
··· 875 875 ->appendChild($view); 876 876 } 877 877 878 - /** 879 - * Straight copy of the loadFileByPhid method in 880 - * @{class:DifferentialReviewRequestMail}. 881 - * 882 - * This is because of the code similarity between the buildPatch method in 883 - * @{class:DifferentialReviewRequestMail} and @{method:buildRawDiffResponse} 884 - * in this class. Both of these methods end up using call_user_func and this 885 - * piece of code is the lucky function. 886 - * 887 - * @return mixed (@{class:PhabricatorFile} if found, null if not) 888 - */ 889 - public function loadFileByPHID($phid) { 890 - // TODO: (T603) Factor this and the other one out. 891 - $file = id(new PhabricatorFile())->loadOneWhere( 892 - 'phid = %s', 893 - $phid); 894 - if (!$file) { 895 - return null; 896 - } 897 - return $file->loadFileData(); 898 - } 899 878 900 879 /** 901 880 * Note this code is somewhat similar to the buildPatch method in ··· 911 890 912 891 assert_instances_of($changesets, 'DifferentialChangeset'); 913 892 assert_instances_of($vs_changesets, 'DifferentialChangeset'); 893 + 894 + $viewer = $this->getRequest()->getUser(); 914 895 915 896 $engine = new PhabricatorDifferenceEngine(); 916 897 $generated_changesets = array(); ··· 954 935 foreach ($raw_changes as $changedict) { 955 936 $changes[] = ArcanistDiffChange::newFromDictionary($changedict); 956 937 } 938 + 939 + $loader = id(new PhabricatorFileBundleLoader()) 940 + ->setViewer($viewer); 941 + 957 942 $bundle = ArcanistBundle::newFromChanges($changes); 958 - 959 - $bundle->setLoadFileDataCallback(array($this, 'loadFileByPHID')); 943 + $bundle->setLoadFileDataCallback(array($loader, 'loadFileData')); 960 944 961 945 $vcs = $repository ? $repository->getVersionControlSystem() : null; 962 946 switch ($vcs) {
+8 -2
src/applications/differential/mail/DifferentialReviewRequestMail.php
··· 127 127 foreach ($raw_changes as $changedict) { 128 128 $changes[] = ArcanistDiffChange::newFromDictionary($changedict); 129 129 } 130 - $bundle = ArcanistBundle::newFromChanges($changes); 131 130 132 - $bundle->setLoadFileDataCallback(array($this, 'loadFileByPHID')); 131 + // TODO: It would be nice to have a real viewer here eventually, but 132 + // in the meantime anyone we're sending mail to can certainly see the 133 + // patch. 134 + $loader = id(new PhabricatorFileBundleLoader()) 135 + ->setViewer(PhabricatorUser::getOmnipotentUser()); 136 + 137 + $bundle = ArcanistBundle::newFromChanges($changes); 138 + $bundle->setLoadFileDataCallback(array($loader, 'loadFileData')); 133 139 134 140 $format = PhabricatorEnv::getEnvConfig('metamta.differential.patch-format'); 135 141 switch ($format) {
+27
src/applications/files/query/PhabricatorFileBundleLoader.php
··· 1 + <?php 2 + 3 + /** 4 + * Callback provider for loading @{class@arcanist:ArcanistBundle} file data 5 + * stored in the Files application. 6 + */ 7 + final class PhabricatorFileBundleLoader { 8 + 9 + private $viewer; 10 + 11 + public function setViewer(PhabricatorUser $viewer) { 12 + $this->viewer = $viewer; 13 + return $this; 14 + } 15 + 16 + public function loadFileData($phid) { 17 + $file = id(new PhabricatorFileQuery()) 18 + ->setViewer($this->viewer) 19 + ->withPHIDs(array($phid)) 20 + ->executeOne(); 21 + if (!$file) { 22 + return null; 23 + } 24 + return $file->loadFileData(); 25 + } 26 + 27 + }