1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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