mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 01:10:58 +01:00
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
This commit is contained in:
parent
13dae05193
commit
dd206a5b69
4 changed files with 43 additions and 25 deletions
|
@ -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',
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
27
src/applications/files/query/PhabricatorFileBundleLoader.php
Normal file
27
src/applications/files/query/PhabricatorFileBundleLoader.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Callback provider for loading @{class@arcanist:ArcanistBundle} file data
|
||||
* stored in the Files application.
|
||||
*/
|
||||
final class PhabricatorFileBundleLoader {
|
||||
|
||||
private $viewer;
|
||||
|
||||
public function setViewer(PhabricatorUser $viewer) {
|
||||
$this->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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue