Moderize Phragment

Summary: Swap over to modern components, `newPage` and `handleRequest`.

Test Plan: `arc lint` :(

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, hach-que

Differential Revision: https://secure.phabricator.com/D15571
This commit is contained in:
Chad Little
2016-04-02 14:24:40 +00:00
committed by chad
parent 59efb7bdf3
commit e3daf598fb
13 changed files with 191 additions and 251 deletions

View File

@@ -2,21 +2,15 @@
final class PhragmentBrowseController extends PhragmentController { final class PhragmentBrowseController extends PhragmentController {
private $dblob;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->dblob = idx($data, 'dblob', ''); $viewer = $request->getViewer();
} $dblob = $request->getURIData('dblob');
public function processRequest() { $parents = $this->loadParentFragments($dblob);
$request = $this->getRequest();
$viewer = $request->getUser();
$parents = $this->loadParentFragments($this->dblob);
if ($parents === null) { if ($parents === null) {
return new Aphront404Response(); return new Aphront404Response();
} }
@@ -83,16 +77,19 @@ final class PhragmentBrowseController extends PhragmentController {
$list->addItem($item); $list->addItem($item);
} }
return $this->buildApplicationPage( $title = pht('Browse Fragments');
array(
$crumbs, $view = array(
$this->renderConfigurationWarningIfRequired(), $this->renderConfigurationWarningIfRequired(),
$current_box, $current_box,
$list, $list,
), );
array(
'title' => pht('Browse Fragments'), return $this->newPage()
)); ->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
} }
} }

View File

@@ -2,18 +2,12 @@
final class PhragmentCreateController extends PhragmentController { final class PhragmentCreateController extends PhragmentController {
private $dblob; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $dblob = $request->getURIData('dblob');
$this->dblob = idx($data, 'dblob', '');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$parent = null; $parent = null;
$parents = $this->loadParentFragments($this->dblob); $parents = $this->loadParentFragments($dblob);
if ($parents === null) { if ($parents === null) {
return new Aphront404Response(); return new Aphront404Response();
} }
@@ -124,15 +118,18 @@ final class PhragmentCreateController extends PhragmentController {
$box->setInfoView($error_view); $box->setInfoView($error_view);
} }
return $this->buildApplicationPage( $title = pht('Create Fragments');
array(
$crumbs, $view = array(
$this->renderConfigurationWarningIfRequired(), $this->renderConfigurationWarningIfRequired(),
$box, $box,
), );
array(
'title' => pht('Create Fragment'), return $this->newPage()
)); ->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
} }
} }

View File

@@ -2,21 +2,15 @@
final class PhragmentHistoryController extends PhragmentController { final class PhragmentHistoryController extends PhragmentController {
private $dblob;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->dblob = idx($data, 'dblob', ''); $viewer = $request->getViewer();
} $dblob = $request->getURIData('dblob');
public function processRequest() { $parents = $this->loadParentFragments($dblob);
$request = $this->getRequest();
$viewer = $request->getUser();
$parents = $this->loadParentFragments($this->dblob);
if ($parents === null) { if ($parents === null) {
return new Aphront404Response(); return new Aphront404Response();
} }
@@ -97,16 +91,19 @@ final class PhragmentHistoryController extends PhragmentController {
$first = false; $first = false;
} }
return $this->buildApplicationPage( $title = pht('Fragment History');
array(
$crumbs, $view = array(
$this->renderConfigurationWarningIfRequired(), $this->renderConfigurationWarningIfRequired(),
$current_box, $current_box,
$list, $list,
), );
array(
'title' => pht('Fragment History'), return $this->newPage()
)); ->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
} }
} }

View File

@@ -2,28 +2,21 @@
final class PhragmentPatchController extends PhragmentController { final class PhragmentPatchController extends PhragmentController {
private $aid;
private $bid;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->aid = idx($data, 'aid', 0); $viewer = $request->getViewer();
$this->bid = idx($data, 'bid', 0); $aid = $request->getURIData('aid');
} $bid = $request->getURIData('bid');
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
// If "aid" is "x", then it means the user wants to generate // If "aid" is "x", then it means the user wants to generate
// a patch of an empty file to the version specified by "bid". // a patch of an empty file to the version specified by "bid".
$ids = array($this->aid, $this->bid); $ids = array($aid, $bid);
if ($this->aid === 'x') { if ($aid === 'x') {
$ids = array($this->bid); $ids = array($bid);
} }
$versions = id(new PhragmentFragmentVersionQuery()) $versions = id(new PhragmentFragmentVersionQuery())
@@ -32,14 +25,14 @@ final class PhragmentPatchController extends PhragmentController {
->execute(); ->execute();
$version_a = null; $version_a = null;
if ($this->aid !== 'x') { if ($aid !== 'x') {
$version_a = idx($versions, $this->aid, null); $version_a = idx($versions, $aid, null);
if ($version_a === null) { if ($version_a === null) {
return new Aphront404Response(); return new Aphront404Response();
} }
} }
$version_b = idx($versions, $this->bid, null); $version_b = idx($versions, $bid, null);
if ($version_b === null) { if ($version_b === null) {
return new Aphront404Response(); return new Aphront404Response();
} }

View File

@@ -2,17 +2,11 @@
final class PhragmentPolicyController extends PhragmentController { final class PhragmentPolicyController extends PhragmentController {
private $dblob; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$dblob = $request->getURIData('dblob');
public function willProcessRequest(array $data) { $parents = $this->loadParentFragments($dblob);
$this->dblob = idx($data, 'dblob', '');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$parents = $this->loadParentFragments($this->dblob);
if ($parents === null) { if ($parents === null) {
return new Aphront404Response(); return new Aphront404Response();
} }
@@ -95,15 +89,18 @@ final class PhragmentPolicyController extends PhragmentController {
->setValidationException(null) ->setValidationException(null)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( $title = pht('Edit Fragment Policies');
array(
$crumbs, $view = array(
$this->renderConfigurationWarningIfRequired(), $this->renderConfigurationWarningIfRequired(),
$box, $box,
), );
array(
'title' => pht('Edit Fragment Policies'), return $this->newPage()
)); ->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
} }
} }

View File

@@ -2,21 +2,14 @@
final class PhragmentRevertController extends PhragmentController { final class PhragmentRevertController extends PhragmentController {
private $dblob; public function handleRequest(AphrontRequest $request) {
private $id; $viewer = $request->getViewer();
$id = $request->getURIData('id');
public function willProcessRequest(array $data) { $dblob = $request->getURIData('dblob');
$this->dblob = $data['dblob'];
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$fragment = id(new PhragmentFragmentQuery()) $fragment = id(new PhragmentFragmentQuery())
->setViewer($viewer) ->setViewer($viewer)
->withPaths(array($this->dblob)) ->withPaths(array($dblob))
->requireCapabilities( ->requireCapabilities(
array( array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
@@ -30,7 +23,7 @@ final class PhragmentRevertController extends PhragmentController {
$version = id(new PhragmentFragmentVersionQuery()) $version = id(new PhragmentFragmentVersionQuery())
->setViewer($viewer) ->setViewer($viewer)
->withFragmentPHIDs(array($fragment->getPHID())) ->withFragmentPHIDs(array($fragment->getPHID()))
->withIDs(array($this->id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if ($version === null) { if ($version === null) {
return new Aphront404Response(); return new Aphront404Response();
@@ -58,7 +51,7 @@ final class PhragmentRevertController extends PhragmentController {
} }
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI($this->getApplicationURI('/history/'.$this->dblob)); ->setURI($this->getApplicationURI('/history/'.$dblob));
} }
return $this->createDialog($fragment, $version); return $this->createDialog($fragment, $version);
@@ -68,12 +61,11 @@ final class PhragmentRevertController extends PhragmentController {
PhragmentFragment $fragment, PhragmentFragment $fragment,
PhragmentFragmentVersion $version) { PhragmentFragmentVersion $version) {
$request = $this->getRequest(); $viewer = $this->getViewer();
$viewer = $request->getUser();
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setTitle(pht('Really revert this fragment?')) ->setTitle(pht('Really revert this fragment?'))
->setUser($request->getUser()) ->setUser($this->getViewer())
->addSubmitButton(pht('Revert')) ->addSubmitButton(pht('Revert'))
->addCancelButton(pht('Cancel')) ->addCancelButton(pht('Cancel'))
->appendParagraph(pht( ->appendParagraph(pht(

View File

@@ -2,17 +2,11 @@
final class PhragmentSnapshotCreateController extends PhragmentController { final class PhragmentSnapshotCreateController extends PhragmentController {
private $dblob; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$dblob = $request->getURIData('dblob');
public function willProcessRequest(array $data) { $parents = $this->loadParentFragments($dblob);
$this->dblob = idx($data, 'dblob', '');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$parents = $this->loadParentFragments($this->dblob);
if ($parents === null) { if ($parents === null) {
return new Aphront404Response(); return new Aphront404Response();
} }
@@ -159,15 +153,18 @@ final class PhragmentSnapshotCreateController extends PhragmentController {
->setFormErrors($errors) ->setFormErrors($errors)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( $title = pht('Create Snapshot');
array(
$crumbs, $view = array(
$this->renderConfigurationWarningIfRequired(), $this->renderConfigurationWarningIfRequired(),
$box, $box,
), );
array(
'title' => pht('Create Fragment'), return $this->newPage()
)); ->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
} }
} }

View File

@@ -2,15 +2,9 @@
final class PhragmentSnapshotDeleteController extends PhragmentController { final class PhragmentSnapshotDeleteController extends PhragmentController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$snapshot = id(new PhragmentSnapshotQuery()) $snapshot = id(new PhragmentSnapshotQuery())
->setViewer($viewer) ->setViewer($viewer)
@@ -18,7 +12,7 @@ final class PhragmentSnapshotDeleteController extends PhragmentController {
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_EDIT,
)) ))
->withIDs(array($this->id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if ($snapshot === null) { if ($snapshot === null) {
return new Aphront404Response(); return new Aphront404Response();
@@ -37,12 +31,11 @@ final class PhragmentSnapshotDeleteController extends PhragmentController {
} }
public function createDialog() { public function createDialog() {
$request = $this->getRequest(); $viewer = $this->getViewer();
$viewer = $request->getUser();
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setTitle(pht('Really delete this snapshot?')) ->setTitle(pht('Really delete this snapshot?'))
->setUser($request->getUser()) ->setUser($this->getViewer())
->addSubmitButton(pht('Delete')) ->addSubmitButton(pht('Delete'))
->addCancelButton(pht('Cancel')) ->addCancelButton(pht('Cancel'))
->appendParagraph(pht( ->appendParagraph(pht(

View File

@@ -2,32 +2,26 @@
final class PhragmentSnapshotPromoteController extends PhragmentController { final class PhragmentSnapshotPromoteController extends PhragmentController {
private $dblob;
private $id;
private $targetSnapshot; private $targetSnapshot;
private $targetFragment; private $targetFragment;
private $snapshots; private $snapshots;
private $options; private $options;
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->dblob = idx($data, 'dblob', null); $viewer = $request->getViewer();
$this->id = idx($data, 'id', null); $id = $request->getURIData('id');
} $dblob = $request->getURIData('dblob');
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
// When the user is promoting a snapshot to the latest version, the // When the user is promoting a snapshot to the latest version, the
// identifier is a fragment path. // identifier is a fragment path.
if ($this->dblob !== null) { if ($dblob !== null) {
$this->targetFragment = id(new PhragmentFragmentQuery()) $this->targetFragment = id(new PhragmentFragmentQuery())
->setViewer($viewer) ->setViewer($viewer)
->requireCapabilities(array( ->requireCapabilities(array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_EDIT,
)) ))
->withPaths(array($this->dblob)) ->withPaths(array($dblob))
->executeOne(); ->executeOne();
if ($this->targetFragment === null) { if ($this->targetFragment === null) {
return new Aphront404Response(); return new Aphront404Response();
@@ -41,14 +35,14 @@ final class PhragmentSnapshotPromoteController extends PhragmentController {
// When the user is promoting a snapshot to another snapshot, the // When the user is promoting a snapshot to another snapshot, the
// identifier is another snapshot ID. // identifier is another snapshot ID.
if ($this->id !== null) { if ($id !== null) {
$this->targetSnapshot = id(new PhragmentSnapshotQuery()) $this->targetSnapshot = id(new PhragmentSnapshotQuery())
->setViewer($viewer) ->setViewer($viewer)
->requireCapabilities(array( ->requireCapabilities(array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_EDIT,
)) ))
->withIDs(array($this->id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if ($this->targetSnapshot === null) { if ($this->targetSnapshot === null) {
return new Aphront404Response(); return new Aphront404Response();
@@ -72,8 +66,8 @@ final class PhragmentSnapshotPromoteController extends PhragmentController {
$this->snapshots, $this->snapshots,
'getName', 'getName',
'getID'); 'getID');
if ($this->id !== null) { if ($id !== null) {
unset($this->options[$this->id]); unset($this->options[$id]);
} }
// If there's no options, show a dialog telling the // If there's no options, show a dialog telling the
@@ -84,7 +78,7 @@ final class PhragmentSnapshotPromoteController extends PhragmentController {
->setTitle(pht('No snapshots to promote')) ->setTitle(pht('No snapshots to promote'))
->appendParagraph(pht( ->appendParagraph(pht(
'There are no snapshots available to promote.')) 'There are no snapshots available to promote.'))
->setUser($request->getUser()) ->setUser($this->getViewer())
->addCancelButton(pht('Cancel'))); ->addCancelButton(pht('Cancel')));
} }
@@ -108,7 +102,7 @@ final class PhragmentSnapshotPromoteController extends PhragmentController {
$child->delete(); $child->delete();
} }
if ($this->id === null) { if ($id === null) {
// The user is promoting the snapshot to the latest version. // The user is promoting the snapshot to the latest version.
$children = id(new PhragmentFragmentQuery()) $children = id(new PhragmentFragmentQuery())
->setViewer($viewer) ->setViewer($viewer)
@@ -150,7 +144,7 @@ final class PhragmentSnapshotPromoteController extends PhragmentController {
} }
$snapshot->saveTransaction(); $snapshot->saveTransaction();
if ($this->id === null) { if ($id === null) {
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI($this->targetFragment->getURI()); ->setURI($this->targetFragment->getURI());
} else { } else {
@@ -159,20 +153,19 @@ final class PhragmentSnapshotPromoteController extends PhragmentController {
} }
} }
return $this->createDialog(); return $this->createDialog($id);
} }
public function createDialog() { public function createDialog($id) {
$request = $this->getRequest(); $viewer = $this->getViewer();
$viewer = $request->getUser();
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setTitle(pht('Promote which snapshot?')) ->setTitle(pht('Promote which snapshot?'))
->setUser($request->getUser()) ->setUser($this->getViewer())
->addSubmitButton(pht('Promote')) ->addSubmitButton(pht('Promote'))
->addCancelButton(pht('Cancel')); ->addCancelButton(pht('Cancel'));
if ($this->id === null) { if ($id === null) {
// The user is promoting a snapshot to the latest version. // The user is promoting a snapshot to the latest version.
$dialog->appendParagraph(pht( $dialog->appendParagraph(pht(
'Select the snapshot you want to promote to the latest version:')); 'Select the snapshot you want to promote to the latest version:'));

View File

@@ -2,23 +2,17 @@
final class PhragmentSnapshotViewController extends PhragmentController { final class PhragmentSnapshotViewController extends PhragmentController {
private $id;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->id = idx($data, 'id', ''); $viewer = $request->getViewer();
} $id = $request->getURIData('id');
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$snapshot = id(new PhragmentSnapshotQuery()) $snapshot = id(new PhragmentSnapshotQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if ($snapshot === null) { if ($snapshot === null) {
return new Aphront404Response(); return new Aphront404Response();
@@ -71,16 +65,18 @@ final class PhragmentSnapshotViewController extends PhragmentController {
$list->addItem($item); $list->addItem($item);
} }
return $this->buildApplicationPage( $title = pht('View Snapshot');
array(
$crumbs, $view = array(
$this->renderConfigurationWarningIfRequired(), $this->renderConfigurationWarningIfRequired(),
$box, $box,
$list, $list,
), );
array(
'title' => pht('View Snapshot'), return $this->newPage()
)); ->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
} }
protected function createSnapshotView($snapshot) { protected function createSnapshotView($snapshot) {

View File

@@ -2,17 +2,11 @@
final class PhragmentUpdateController extends PhragmentController { final class PhragmentUpdateController extends PhragmentController {
private $dblob; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$dblob = $request->getURIData('dblob');
public function willProcessRequest(array $data) { $parents = $this->loadParentFragments($dblob);
$this->dblob = idx($data, 'dblob', '');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$parents = $this->loadParentFragments($this->dblob);
if ($parents === null) { if ($parents === null) {
return new Aphront404Response(); return new Aphront404Response();
} }
@@ -69,15 +63,18 @@ final class PhragmentUpdateController extends PhragmentController {
->setValidationException(null) ->setValidationException(null)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( $title = pht('Update Fragment');
array(
$crumbs, $view = array(
$this->renderConfigurationWarningIfRequired(), $this->renderConfigurationWarningIfRequired(),
$box, $box,
), );
array(
'title' => pht('Update Fragment'), return $this->newPage()
)); ->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
} }
} }

View File

@@ -2,23 +2,17 @@
final class PhragmentVersionController extends PhragmentController { final class PhragmentVersionController extends PhragmentController {
private $id;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->id = idx($data, 'id', 0); $viewer = $request->getViewer();
} $id = $request->getURIData('id');
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$version = id(new PhragmentFragmentVersionQuery()) $version = id(new PhragmentFragmentVersionQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if ($version === null) { if ($version === null) {
return new Aphront404Response(); return new Aphront404Response();
@@ -71,23 +65,23 @@ final class PhragmentVersionController extends PhragmentController {
->setHeader($header) ->setHeader($header)
->addPropertyList($properties); ->addPropertyList($properties);
return $this->buildApplicationPage( $title = pht('View Version');
array(
$crumbs, $view = array(
$this->renderConfigurationWarningIfRequired(), $this->renderConfigurationWarningIfRequired(),
$box, $box,
$this->renderPreviousVersionList($version), $this->renderPreviousVersionList($version),
), );
array(
'title' => pht('View Version'), return $this->newPage()
)); ->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
} }
private function renderPreviousVersionList( private function renderPreviousVersionList(
PhragmentFragmentVersion $version) { PhragmentFragmentVersion $version) {
$viewer = $this->getViewer();
$request = $this->getRequest();
$viewer = $request->getUser();
$previous_versions = id(new PhragmentFragmentVersionQuery()) $previous_versions = id(new PhragmentFragmentVersionQuery())
->setViewer($viewer) ->setViewer($viewer)

View File

@@ -2,35 +2,28 @@
final class PhragmentZIPController extends PhragmentController { final class PhragmentZIPController extends PhragmentController {
private $dblob;
private $snapshot;
private $snapshotCache; private $snapshotCache;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->dblob = idx($data, 'dblob', ''); $viewer = $request->getViewer();
$this->snapshot = idx($data, 'snapshot', null); $dblob = $request->getURIData('dblob');
} $snapshot = $request->getURIData('snapshot');
public function processRequest() { $parents = $this->loadParentFragments($dblob);
$request = $this->getRequest();
$viewer = $request->getUser();
$parents = $this->loadParentFragments($this->dblob);
if ($parents === null) { if ($parents === null) {
return new Aphront404Response(); return new Aphront404Response();
} }
$fragment = idx($parents, count($parents) - 1, null); $fragment = idx($parents, count($parents) - 1, null);
if ($this->snapshot !== null) { if ($snapshot !== null) {
$snapshot = id(new PhragmentSnapshotQuery()) $snapshot = id(new PhragmentSnapshotQuery())
->setViewer($viewer) ->setViewer($viewer)
->withPrimaryFragmentPHIDs(array($fragment->getPHID())) ->withPrimaryFragmentPHIDs(array($fragment->getPHID()))
->withNames(array($this->snapshot)) ->withNames(array($snapshot))
->executeOne(); ->executeOne();
if ($snapshot === null) { if ($snapshot === null) {
return new Aphront404Response(); return new Aphront404Response();
@@ -63,7 +56,7 @@ final class PhragmentZIPController extends PhragmentController {
$dialog->setTitle(pht('ZIP Extension Not Installed')); $dialog->setTitle(pht('ZIP Extension Not Installed'));
$dialog->appendParagraph($inst); $dialog->appendParagraph($inst);
$dialog->addCancelButton('/phragment/browse/'.$this->dblob); $dialog->addCancelButton('/phragment/browse/'.$dblob);
return id(new AphrontDialogResponse())->setDialog($dialog); return id(new AphrontDialogResponse())->setDialog($dialog);
} }
@@ -71,7 +64,8 @@ final class PhragmentZIPController extends PhragmentController {
throw new Exception(pht('Unable to create ZIP archive!')); throw new Exception(pht('Unable to create ZIP archive!'));
} }
$mappings = $this->getFragmentMappings($fragment, $fragment->getPath()); $mappings = $this->getFragmentMappings(
$fragment, $fragment->getPath(), $snapshot);
$phids = array(); $phids = array();
foreach ($mappings as $path => $file_phid) { foreach ($mappings as $path => $file_phid) {
@@ -130,14 +124,17 @@ final class PhragmentZIPController extends PhragmentController {
/** /**
* Returns a list of mappings like array('some/path.txt' => 'file PHID'); * Returns a list of mappings like array('some/path.txt' => 'file PHID');
*/ */
private function getFragmentMappings(PhragmentFragment $current, $base_path) { private function getFragmentMappings(
PhragmentFragment $current,
$base_path,
$snapshot) {
$mappings = $current->getFragmentMappings( $mappings = $current->getFragmentMappings(
$this->getRequest()->getUser(), $this->getRequest()->getUser(),
$base_path); $base_path);
$result = array(); $result = array();
foreach ($mappings as $path => $fragment) { foreach ($mappings as $path => $fragment) {
$version = $this->getVersion($fragment); $version = $this->getVersion($fragment, $snapshot);
if ($version !== null) { if ($version !== null) {
$result[$path] = $version->getFilePHID(); $result[$path] = $version->getFilePHID();
} }
@@ -145,8 +142,8 @@ final class PhragmentZIPController extends PhragmentController {
return $result; return $result;
} }
private function getVersion($fragment) { private function getVersion($fragment, $snapshot) {
if ($this->snapshot === null) { if ($snapshot === null) {
return $fragment->getLatestVersion(); return $fragment->getLatestVersion();
} else { } else {
return idx($this->snapshotCache, $fragment->getPHID(), null); return idx($this->snapshotCache, $fragment->getPHID(), null);