diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 10b4450e65..6c4b09993b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1185,6 +1185,7 @@ phutil_register_library_map(array( 'PhabricatorFeedStoryStatus' => 'applications/feed/story/PhabricatorFeedStoryStatus.php', 'PhabricatorFeedStoryTypeConstants' => 'applications/feed/constants/PhabricatorFeedStoryTypeConstants.php', 'PhabricatorFile' => 'applications/files/storage/PhabricatorFile.php', + 'PhabricatorFileBundleLoader' => 'applications/files/query/PhabricatorFileBundleLoader.php', 'PhabricatorFileCommentController' => 'applications/files/controller/PhabricatorFileCommentController.php', 'PhabricatorFileController' => 'applications/files/controller/PhabricatorFileController.php', 'PhabricatorFileDAO' => 'applications/files/storage/PhabricatorFileDAO.php', diff --git a/src/applications/differential/controller/DifferentialRevisionViewController.php b/src/applications/differential/controller/DifferentialRevisionViewController.php index 8e59c2b380..59c645c746 100644 --- a/src/applications/differential/controller/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/DifferentialRevisionViewController.php @@ -875,27 +875,6 @@ final class DifferentialRevisionViewController extends DifferentialController { ->appendChild($view); } - /** - * Straight copy of the loadFileByPhid method in - * @{class:DifferentialReviewRequestMail}. - * - * This is because of the code similarity between the buildPatch method in - * @{class:DifferentialReviewRequestMail} and @{method:buildRawDiffResponse} - * in this class. Both of these methods end up using call_user_func and this - * piece of code is the lucky function. - * - * @return mixed (@{class:PhabricatorFile} if found, null if not) - */ - public function loadFileByPHID($phid) { - // TODO: (T603) Factor this and the other one out. - $file = id(new PhabricatorFile())->loadOneWhere( - 'phid = %s', - $phid); - if (!$file) { - return null; - } - return $file->loadFileData(); - } /** * Note this code is somewhat similar to the buildPatch method in @@ -912,6 +891,8 @@ final class DifferentialRevisionViewController extends DifferentialController { assert_instances_of($changesets, 'DifferentialChangeset'); assert_instances_of($vs_changesets, 'DifferentialChangeset'); + $viewer = $this->getRequest()->getUser(); + $engine = new PhabricatorDifferenceEngine(); $generated_changesets = array(); foreach ($changesets as $changeset) { @@ -954,9 +935,12 @@ final class DifferentialRevisionViewController extends DifferentialController { foreach ($raw_changes as $changedict) { $changes[] = ArcanistDiffChange::newFromDictionary($changedict); } - $bundle = ArcanistBundle::newFromChanges($changes); - $bundle->setLoadFileDataCallback(array($this, 'loadFileByPHID')); + $loader = id(new PhabricatorFileBundleLoader()) + ->setViewer($viewer); + + $bundle = ArcanistBundle::newFromChanges($changes); + $bundle->setLoadFileDataCallback(array($loader, 'loadFileData')); $vcs = $repository ? $repository->getVersionControlSystem() : null; switch ($vcs) { diff --git a/src/applications/differential/mail/DifferentialReviewRequestMail.php b/src/applications/differential/mail/DifferentialReviewRequestMail.php index 7a3f4523f5..e1e705510c 100644 --- a/src/applications/differential/mail/DifferentialReviewRequestMail.php +++ b/src/applications/differential/mail/DifferentialReviewRequestMail.php @@ -127,9 +127,15 @@ abstract class DifferentialReviewRequestMail extends DifferentialMail { foreach ($raw_changes as $changedict) { $changes[] = ArcanistDiffChange::newFromDictionary($changedict); } - $bundle = ArcanistBundle::newFromChanges($changes); - $bundle->setLoadFileDataCallback(array($this, 'loadFileByPHID')); + // TODO: It would be nice to have a real viewer here eventually, but + // in the meantime anyone we're sending mail to can certainly see the + // patch. + $loader = id(new PhabricatorFileBundleLoader()) + ->setViewer(PhabricatorUser::getOmnipotentUser()); + + $bundle = ArcanistBundle::newFromChanges($changes); + $bundle->setLoadFileDataCallback(array($loader, 'loadFileData')); $format = PhabricatorEnv::getEnvConfig('metamta.differential.patch-format'); switch ($format) { diff --git a/src/applications/files/query/PhabricatorFileBundleLoader.php b/src/applications/files/query/PhabricatorFileBundleLoader.php new file mode 100644 index 0000000000..0cc7603020 --- /dev/null +++ b/src/applications/files/query/PhabricatorFileBundleLoader.php @@ -0,0 +1,27 @@ +viewer = $viewer; + return $this; + } + + public function loadFileData($phid) { + $file = id(new PhabricatorFileQuery()) + ->setViewer($this->viewer) + ->withPHIDs(array($phid)) + ->executeOne(); + if (!$file) { + return null; + } + return $file->loadFileData(); + } + +}