1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Fix an error in Diffusion when the Owners application is uninstalled

Summary:
See <https://discourse.phabricator-community.org/t/undefined-view-when-owners-is-uninstalled/451>.

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
This commit is contained in:
epriestley 2017-09-19 09:22:10 -07:00
parent 23867c1487
commit 03e5d69817

View file

@ -799,75 +799,79 @@ final class DiffusionBrowseController extends DiffusionController {
} }
private function buildOwnersList(DiffusionRequest $drequest) { private function buildOwnersList(DiffusionRequest $drequest) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$have_owners = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorOwnersApplication',
$viewer);
if (!$have_owners) {
return null;
}
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$owners = 'PhabricatorOwnersApplication'; $package_query = id(new PhabricatorOwnersPackageQuery())
if (PhabricatorApplication::isClassInstalled($owners)) { ->setViewer($viewer)
$package_query = id(new PhabricatorOwnersPackageQuery()) ->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->setViewer($viewer) ->withControl(
->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->withControl(
$repository->getPHID(),
array(
$drequest->getPath(),
));
$package_query->execute();
$packages = $package_query->getControllingPackagesForPath(
$repository->getPHID(), $repository->getPHID(),
$drequest->getPath()); array(
$drequest->getPath(),
));
$ownership = id(new PHUIObjectItemListView()) $package_query->execute();
->setUser($viewer)
->setNoDataString(pht('No Owners'));
if ($packages) { $packages = $package_query->getControllingPackagesForPath(
foreach ($packages as $package) { $repository->getPHID(),
$item = id(new PHUIObjectItemView()) $drequest->getPath());
->setObject($package)
->setObjectName($package->getMonogram())
->setHeader($package->getName())
->setHref($package->getURI());
$owners = $package->getOwners(); $ownership = id(new PHUIObjectItemListView())
if ($owners) { ->setUser($viewer)
$owner_list = $viewer->renderHandleList( ->setNoDataString(pht('No Owners'));
mpull($owners, 'getUserPHID'));
} else {
$owner_list = phutil_tag('em', array(), pht('None'));
}
$item->addAttribute(pht('Owners: %s', $owner_list));
$auto = $package->getAutoReview(); if ($packages) {
$autoreview_map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); foreach ($packages as $package) {
$spec = idx($autoreview_map, $auto, array()); $item = id(new PHUIObjectItemView())
$name = idx($spec, 'name', $auto); ->setObject($package)
$item->addIcon('fa-code', $name); ->setObjectName($package->getMonogram())
->setHeader($package->getName())
->setHref($package->getURI());
if ($package->getAuditingEnabled()) { $owners = $package->getOwners();
$item->addIcon('fa-check', pht('Auditing Enabled')); if ($owners) {
} else { $owner_list = $viewer->renderHandleList(
$item->addIcon('fa-ban', pht('No Auditing')); mpull($owners, 'getUserPHID'));
} } else {
$owner_list = phutil_tag('em', array(), pht('None'));
if ($package->isArchived()) {
$item->setDisabled(true);
}
$ownership->addItem($item);
} }
} $item->addAttribute(pht('Owners: %s', $owner_list));
$view = id(new PHUIObjectBoxView()) $auto = $package->getAutoReview();
->setHeaderText(pht('Owner Packages')) $autoreview_map = PhabricatorOwnersPackage::getAutoreviewOptionsMap();
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) $spec = idx($autoreview_map, $auto, array());
->addClass('diffusion-mobile-view') $name = idx($spec, 'name', $auto);
->setObjectList($ownership); $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; return $view;
} }