From 03e5d69817c91afde03615a475086044a7db7a33 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 19 Sep 2017 09:22:10 -0700 Subject: [PATCH] Fix an error in Diffusion when the Owners application is uninstalled Summary: See . When Owners is not installed, Diffusion can fatal with a bad `$view`. Test Plan: - Uninstall Owners. - View the content of any file in Diffusion. - Before: fatal on `$view` undefined. - After: Valid page with no owners information. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D18629 --- .../controller/DiffusionBrowseController.php | 116 +++++++++--------- 1 file changed, 60 insertions(+), 56 deletions(-) diff --git a/src/applications/diffusion/controller/DiffusionBrowseController.php b/src/applications/diffusion/controller/DiffusionBrowseController.php index 076e667dc4..d3223e64fd 100644 --- a/src/applications/diffusion/controller/DiffusionBrowseController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseController.php @@ -799,75 +799,79 @@ final class DiffusionBrowseController extends DiffusionController { } private function buildOwnersList(DiffusionRequest $drequest) { - $viewer = $this->getViewer(); + + $have_owners = PhabricatorApplication::isClassInstalledForViewer( + 'PhabricatorOwnersApplication', + $viewer); + if (!$have_owners) { + return null; + } + $repository = $drequest->getRepository(); - $owners = 'PhabricatorOwnersApplication'; - if (PhabricatorApplication::isClassInstalled($owners)) { - $package_query = id(new PhabricatorOwnersPackageQuery()) - ->setViewer($viewer) - ->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE)) - ->withControl( - $repository->getPHID(), - array( - $drequest->getPath(), - )); - - $package_query->execute(); - - $packages = $package_query->getControllingPackagesForPath( + $package_query = id(new PhabricatorOwnersPackageQuery()) + ->setViewer($viewer) + ->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE)) + ->withControl( $repository->getPHID(), - $drequest->getPath()); + array( + $drequest->getPath(), + )); - $ownership = id(new PHUIObjectItemListView()) - ->setUser($viewer) - ->setNoDataString(pht('No Owners')); + $package_query->execute(); - if ($packages) { - foreach ($packages as $package) { - $item = id(new PHUIObjectItemView()) - ->setObject($package) - ->setObjectName($package->getMonogram()) - ->setHeader($package->getName()) - ->setHref($package->getURI()); + $packages = $package_query->getControllingPackagesForPath( + $repository->getPHID(), + $drequest->getPath()); - $owners = $package->getOwners(); - if ($owners) { - $owner_list = $viewer->renderHandleList( - mpull($owners, 'getUserPHID')); - } else { - $owner_list = phutil_tag('em', array(), pht('None')); - } - $item->addAttribute(pht('Owners: %s', $owner_list)); + $ownership = id(new PHUIObjectItemListView()) + ->setUser($viewer) + ->setNoDataString(pht('No Owners')); - $auto = $package->getAutoReview(); - $autoreview_map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); - $spec = idx($autoreview_map, $auto, array()); - $name = idx($spec, 'name', $auto); - $item->addIcon('fa-code', $name); + if ($packages) { + foreach ($packages as $package) { + $item = id(new PHUIObjectItemView()) + ->setObject($package) + ->setObjectName($package->getMonogram()) + ->setHeader($package->getName()) + ->setHref($package->getURI()); - if ($package->getAuditingEnabled()) { - $item->addIcon('fa-check', pht('Auditing Enabled')); - } else { - $item->addIcon('fa-ban', pht('No Auditing')); - } - - if ($package->isArchived()) { - $item->setDisabled(true); - } - - $ownership->addItem($item); + $owners = $package->getOwners(); + if ($owners) { + $owner_list = $viewer->renderHandleList( + mpull($owners, 'getUserPHID')); + } else { + $owner_list = phutil_tag('em', array(), pht('None')); } - } + $item->addAttribute(pht('Owners: %s', $owner_list)); - $view = id(new PHUIObjectBoxView()) - ->setHeaderText(pht('Owner Packages')) - ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) - ->addClass('diffusion-mobile-view') - ->setObjectList($ownership); + $auto = $package->getAutoReview(); + $autoreview_map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); + $spec = idx($autoreview_map, $auto, array()); + $name = idx($spec, 'name', $auto); + $item->addIcon('fa-code', $name); + + if ($package->getAuditingEnabled()) { + $item->addIcon('fa-check', pht('Auditing Enabled')); + } else { + $item->addIcon('fa-ban', pht('No Auditing')); + } + + if ($package->isArchived()) { + $item->setDisabled(true); + } + + $ownership->addItem($item); + } } + $view = id(new PHUIObjectBoxView()) + ->setHeaderText(pht('Owner Packages')) + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) + ->addClass('diffusion-mobile-view') + ->setObjectList($ownership); + return $view; }