2013-12-08 22:24:50 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhragmentSnapshotViewController extends PhragmentController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
2013-12-13 04:42:12 +01:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-08 22:24:50 +01:00
|
|
|
public function willProcessRequest(array $data) {
|
2014-06-09 20:36:49 +02:00
|
|
|
$this->id = idx($data, 'id', '');
|
2013-12-08 22:24:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$snapshot = id(new PhragmentSnapshotQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
if ($snapshot === null) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$box = $this->createSnapshotView($snapshot);
|
|
|
|
|
|
|
|
$fragment = id(new PhragmentFragmentQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($snapshot->getPrimaryFragmentPHID()))
|
|
|
|
->executeOne();
|
|
|
|
if ($fragment === null) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$parents = $this->loadParentFragments($fragment->getPath());
|
|
|
|
if ($parents === null) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbsWithPath($parents);
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('"%s" Snapshot', $snapshot->getName()));
|
2013-12-08 22:24:50 +01:00
|
|
|
|
|
|
|
$children = id(new PhragmentSnapshotChildQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->needFragments(true)
|
|
|
|
->needFragmentVersions(true)
|
|
|
|
->withSnapshotPHIDs(array($snapshot->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$list = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
foreach ($children as $child) {
|
|
|
|
$item = id(new PHUIObjectItemView())
|
|
|
|
->setHeader($child->getFragment()->getPath());
|
|
|
|
|
|
|
|
if ($child->getFragmentVersion() !== null) {
|
|
|
|
$item
|
|
|
|
->setHref($child->getFragmentVersion()->getURI())
|
|
|
|
->addAttribute(pht(
|
|
|
|
'Version %s',
|
|
|
|
$child->getFragmentVersion()->getSequence()));
|
|
|
|
} else {
|
|
|
|
$item
|
|
|
|
->setHref($child->getFragment()->getURI())
|
|
|
|
->addAttribute(pht('Directory'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$list->addItem($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-12-13 04:42:12 +01:00
|
|
|
$this->renderConfigurationWarningIfRequired(),
|
2013-12-08 22:24:50 +01:00
|
|
|
$box,
|
|
|
|
$list),
|
|
|
|
array(
|
|
|
|
'title' => pht('View Snapshot'),
|
|
|
|
'device' => true));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function createSnapshotView($snapshot) {
|
|
|
|
if ($snapshot === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
$phids[] = $snapshot->getPrimaryFragmentPHID();
|
|
|
|
|
|
|
|
$this->loadHandles($phids);
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('"%s" Snapshot', $snapshot->getName()))
|
|
|
|
->setPolicyObject($snapshot)
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$zip_uri = $this->getApplicationURI(
|
2014-06-09 20:36:49 +02:00
|
|
|
'zip@'.$snapshot->getName().
|
|
|
|
'/'.$snapshot->getPrimaryFragment()->getPath());
|
2013-12-08 22:24:50 +01:00
|
|
|
|
2013-12-13 04:42:12 +01:00
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$snapshot,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
2013-12-08 22:24:50 +01:00
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($snapshot)
|
|
|
|
->setObjectURI($snapshot->getURI());
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Download Snapshot as ZIP'))
|
2013-12-13 04:42:12 +01:00
|
|
|
->setHref($this->isCorrectlyConfigured() ? $zip_uri : null)
|
|
|
|
->setDisabled(!$this->isCorrectlyConfigured())
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-floppy-o'));
|
2013-12-08 22:24:50 +01:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Delete Snapshot'))
|
|
|
|
->setHref($this->getApplicationURI(
|
2014-06-09 20:36:49 +02:00
|
|
|
'snapshot/delete/'.$snapshot->getID().'/'))
|
2013-12-13 04:42:12 +01:00
|
|
|
->setDisabled(!$can_edit)
|
2013-12-08 22:24:50 +01:00
|
|
|
->setWorkflow(true)
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-times'));
|
2013-12-08 22:24:50 +01:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Promote Another Snapshot to Here'))
|
|
|
|
->setHref($this->getApplicationURI(
|
2014-06-09 20:36:49 +02:00
|
|
|
'snapshot/promote/'.$snapshot->getID().'/'))
|
2013-12-13 04:42:12 +01:00
|
|
|
->setDisabled(!$can_edit)
|
2013-12-08 22:24:50 +01:00
|
|
|
->setWorkflow(true)
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-arrow-up'));
|
2013-12-08 22:24:50 +01:00
|
|
|
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($snapshot)
|
|
|
|
->setActionList($actions);
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Name'),
|
|
|
|
$snapshot->getName());
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Fragment'),
|
|
|
|
$this->renderHandlesForPHIDs(array($snapshot->getPrimaryFragmentPHID())));
|
|
|
|
|
|
|
|
return id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addPropertyList($properties);
|
|
|
|
}
|
|
|
|
}
|