diff --git a/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php b/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php index 7f680ebdbd..29702c8dc1 100644 --- a/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php +++ b/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php @@ -30,8 +30,9 @@ final class MacroQueryConduitAPIMethod extends MacroConduitAPIMethod { } protected function execute(ConduitAPIRequest $request) { - $query = new PhabricatorMacroQuery(); - $query->setViewer($request->getUser()); + $query = id(new PhabricatorMacroQuery()) + ->setViewer($request->getUser()) + ->needFiles(true); $author_phids = $request->getValue('authorPHIDs'); $phids = $request->getValue('phids'); diff --git a/src/applications/macro/controller/PhabricatorMacroEditController.php b/src/applications/macro/controller/PhabricatorMacroEditController.php index 5442754e42..074b7e5a7f 100644 --- a/src/applications/macro/controller/PhabricatorMacroEditController.php +++ b/src/applications/macro/controller/PhabricatorMacroEditController.php @@ -19,6 +19,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController { $macro = id(new PhabricatorMacroQuery()) ->setViewer($user) ->withIDs(array($this->id)) + ->needFiles(true) ->executeOne(); if (!$macro) { return new Aphront404Response(); diff --git a/src/applications/macro/controller/PhabricatorMacroMemeController.php b/src/applications/macro/controller/PhabricatorMacroMemeController.php index d8b9d5c441..badb1759ad 100644 --- a/src/applications/macro/controller/PhabricatorMacroMemeController.php +++ b/src/applications/macro/controller/PhabricatorMacroMemeController.php @@ -29,6 +29,7 @@ final class PhabricatorMacroMemeController $macro = id(new PhabricatorMacroQuery()) ->setViewer($user) ->withNames(array($macro_name)) + ->needFiles(true) ->executeOne(); if (!$macro) { return false; diff --git a/src/applications/macro/controller/PhabricatorMacroViewController.php b/src/applications/macro/controller/PhabricatorMacroViewController.php index 01a3e9a926..da9bc83260 100644 --- a/src/applications/macro/controller/PhabricatorMacroViewController.php +++ b/src/applications/macro/controller/PhabricatorMacroViewController.php @@ -20,6 +20,7 @@ final class PhabricatorMacroViewController $macro = id(new PhabricatorMacroQuery()) ->setViewer($user) ->withIDs(array($this->id)) + ->needFiles(true) ->executeOne(); if (!$macro) { return new Aphront404Response(); diff --git a/src/applications/macro/query/PhabricatorMacroQuery.php b/src/applications/macro/query/PhabricatorMacroQuery.php index f07f308585..c7f9534499 100644 --- a/src/applications/macro/query/PhabricatorMacroQuery.php +++ b/src/applications/macro/query/PhabricatorMacroQuery.php @@ -12,6 +12,8 @@ final class PhabricatorMacroQuery private $dateCreatedBefore; private $flagColor; + private $needFiles; + private $status = 'status-any'; const STATUS_ANY = 'status-any'; const STATUS_ACTIVE = 'status-active'; @@ -83,6 +85,11 @@ final class PhabricatorMacroQuery return $this; } + public function needFiles($need_files) { + $this->needFiles = $need_files; + return $this; + } + protected function loadPage() { $macro_table = new PhabricatorFileImageMacro(); $conn = $macro_table->establishConnection('r'); @@ -196,21 +203,23 @@ final class PhabricatorMacroQuery } protected function didFilterPage(array $macros) { - $file_phids = mpull($macros, 'getFilePHID'); - $files = id(new PhabricatorFileQuery()) - ->setViewer($this->getViewer()) - ->setParentQuery($this) - ->withPHIDs($file_phids) - ->execute(); - $files = mpull($files, null, 'getPHID'); + if ($this->needFiles) { + $file_phids = mpull($macros, 'getFilePHID'); + $files = id(new PhabricatorFileQuery()) + ->setViewer($this->getViewer()) + ->setParentQuery($this) + ->withPHIDs($file_phids) + ->execute(); + $files = mpull($files, null, 'getPHID'); - foreach ($macros as $key => $macro) { - $file = idx($files, $macro->getFilePHID()); - if (!$file) { - unset($macros[$key]); - continue; + foreach ($macros as $key => $macro) { + $file = idx($files, $macro->getFilePHID()); + if (!$file) { + unset($macros[$key]); + continue; + } + $macro->attachFile($file); } - $macro->attachFile($file); } return $macros; diff --git a/src/applications/macro/query/PhabricatorMacroSearchEngine.php b/src/applications/macro/query/PhabricatorMacroSearchEngine.php index 48d2a2c5b7..45390b13b1 100644 --- a/src/applications/macro/query/PhabricatorMacroSearchEngine.php +++ b/src/applications/macro/query/PhabricatorMacroSearchEngine.php @@ -29,6 +29,7 @@ final class PhabricatorMacroSearchEngine public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { $query = id(new PhabricatorMacroQuery()) + ->needFiles(true) ->withIDs($saved->getParameter('ids', array())) ->withPHIDs($saved->getParameter('phids', array())) ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));