diff --git a/src/applications/phragment/controller/PhragmentBrowseController.php b/src/applications/phragment/controller/PhragmentBrowseController.php index 7b0a16cc52..d511835ce9 100644 --- a/src/applications/phragment/controller/PhragmentBrowseController.php +++ b/src/applications/phragment/controller/PhragmentBrowseController.php @@ -1,98 +1,95 @@ 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'); - $parents = $this->loadParentFragments($this->dblob); + $parents = $this->loadParentFragments($dblob); if ($parents === null) { return new Aphront404Response(); } $current = nonempty(last($parents), null); $path = ''; if ($current !== null) { $path = $current->getPath(); } $crumbs = $this->buildApplicationCrumbsWithPath($parents); if ($this->hasApplicationCapability( PhragmentCanCreateCapability::CAPABILITY)) { $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Create Fragment')) ->setHref($this->getApplicationURI('/create/'.$path)) ->setIcon('fa-plus-square')); } $current_box = $this->createCurrentFragmentView($current, false); $list = id(new PHUIObjectItemListView()) ->setUser($viewer); $fragments = null; if ($current === null) { // Find all root fragments. $fragments = id(new PhragmentFragmentQuery()) ->setViewer($this->getRequest()->getUser()) ->needLatestVersion(true) ->withDepths(array(1)) ->execute(); } else { // Find all child fragments. $fragments = id(new PhragmentFragmentQuery()) ->setViewer($this->getRequest()->getUser()) ->needLatestVersion(true) ->withLeadingPath($current->getPath().'/') ->withDepths(array($current->getDepth() + 1)) ->execute(); } foreach ($fragments as $fragment) { $item = id(new PHUIObjectItemView()); $item->setHeader($fragment->getName()); $item->setHref($fragment->getURI()); if (!$fragment->isDirectory()) { $item->addAttribute(pht( 'Last Updated %s', phabricator_datetime( $fragment->getLatestVersion()->getDateCreated(), $viewer))); $item->addAttribute(pht( 'Latest Version %s', $fragment->getLatestVersion()->getSequence())); if ($fragment->isDeleted()) { $item->setDisabled(true); $item->addAttribute(pht('Deleted')); } } else { $item->addAttribute(pht('Directory')); } $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); + } } diff --git a/src/applications/phragment/controller/PhragmentCreateController.php b/src/applications/phragment/controller/PhragmentCreateController.php index 2a5b54538c..946d7cc332 100644 --- a/src/applications/phragment/controller/PhragmentCreateController.php +++ b/src/applications/phragment/controller/PhragmentCreateController.php @@ -1,138 +1,135 @@ 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(); } if (count($parents) !== 0) { $parent = idx($parents, count($parents) - 1, null); } $parent_path = ''; if ($parent !== null) { $parent_path = $parent->getPath(); } $parent_path = trim($parent_path, '/'); $fragment = id(new PhragmentFragment()); $error_view = null; if ($request->isFormPost()) { $errors = array(); $v_name = $request->getStr('name'); $v_fileid = $request->getInt('fileID'); $v_viewpolicy = $request->getStr('viewPolicy'); $v_editpolicy = $request->getStr('editPolicy'); if (strpos($v_name, '/') !== false) { $errors[] = pht("The fragment name can not contain '/'."); } $file = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withIDs(array($v_fileid)) ->executeOne(); if (!$file) { $errors[] = pht("The specified file doesn't exist."); } if (!count($errors)) { $depth = 1; if ($parent !== null) { $depth = $parent->getDepth() + 1; } PhragmentFragment::createFromFile( $viewer, $file, trim($parent_path.'/'.$v_name, '/'), $v_viewpolicy, $v_editpolicy); return id(new AphrontRedirectResponse()) ->setURI('/phragment/browse/'.trim($parent_path.'/'.$v_name, '/')); } else { $error_view = id(new PHUIInfoView()) ->setErrors($errors) ->setTitle(pht('Errors while creating fragment')); } } $policies = id(new PhabricatorPolicyQuery()) ->setViewer($viewer) ->setObject($fragment) ->execute(); $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Parent Path')) ->setDisabled(true) ->setValue('/'.trim($parent_path.'/', '/'))) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Name')) ->setName('name')) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('File ID')) ->setName('fileID')) ->appendChild( id(new AphrontFormPolicyControl()) ->setUser($viewer) ->setName('viewPolicy') ->setPolicyObject($fragment) ->setPolicies($policies) ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)) ->appendChild( id(new AphrontFormPolicyControl()) ->setUser($viewer) ->setName('editPolicy') ->setPolicyObject($fragment) ->setPolicies($policies) ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Create Fragment')) ->addCancelButton( $this->getApplicationURI('browse/'.$parent_path))); $crumbs = $this->buildApplicationCrumbsWithPath($parents); $crumbs->addTextCrumb(pht('Create Fragment')); $box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Create Fragment')) ->setForm($form); if ($error_view) { $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); + } } diff --git a/src/applications/phragment/controller/PhragmentHistoryController.php b/src/applications/phragment/controller/PhragmentHistoryController.php index 72e0000b80..4e16deb43d 100644 --- a/src/applications/phragment/controller/PhragmentHistoryController.php +++ b/src/applications/phragment/controller/PhragmentHistoryController.php @@ -1,112 +1,109 @@ 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'); - $parents = $this->loadParentFragments($this->dblob); + $parents = $this->loadParentFragments($dblob); if ($parents === null) { return new Aphront404Response(); } $current = idx($parents, count($parents) - 1, null); $path = $current->getPath(); $crumbs = $this->buildApplicationCrumbsWithPath($parents); if ($this->hasApplicationCapability( PhragmentCanCreateCapability::CAPABILITY)) { $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Create Fragment')) ->setHref($this->getApplicationURI('/create/'.$path)) ->setIcon('fa-plus-square')); } $current_box = $this->createCurrentFragmentView($current, true); $versions = id(new PhragmentFragmentVersionQuery()) ->setViewer($viewer) ->withFragmentPHIDs(array($current->getPHID())) ->execute(); $list = id(new PHUIObjectItemListView()) ->setUser($viewer); $file_phids = mpull($versions, 'getFilePHID'); $files = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs($file_phids) ->execute(); $files = mpull($files, null, 'getPHID'); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $current, PhabricatorPolicyCapability::CAN_EDIT); $first = true; foreach ($versions as $version) { $item = id(new PHUIObjectItemView()); $item->setHeader(pht('Version %s', $version->getSequence())); $item->setHref($version->getURI()); $item->addAttribute(phabricator_datetime( $version->getDateCreated(), $viewer)); if ($version->getFilePHID() === null) { $item->setDisabled(true); $item->addAttribute(pht('Deletion')); } if (!$first && $can_edit) { $item->addAction(id(new PHUIListItemView()) ->setIcon('fa-refresh') ->setRenderNameAsTooltip(true) ->setWorkflow(true) ->setName(pht('Revert to Here')) ->setHref($this->getApplicationURI( 'revert/'.$version->getID().'/'.$current->getPath()))); } $disabled = !isset($files[$version->getFilePHID()]); $action = id(new PHUIListItemView()) ->setIcon('fa-download') ->setDisabled($disabled || !$this->isCorrectlyConfigured()) ->setRenderNameAsTooltip(true) ->setName(pht('Download')); if (!$disabled && $this->isCorrectlyConfigured()) { $action->setHref($files[$version->getFilePHID()] ->getDownloadURI($version->getURI())); } $item->addAction($action); $list->addItem($item); $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); + } } diff --git a/src/applications/phragment/controller/PhragmentPatchController.php b/src/applications/phragment/controller/PhragmentPatchController.php index 5a04403898..5ad4b6dfec 100644 --- a/src/applications/phragment/controller/PhragmentPatchController.php +++ b/src/applications/phragment/controller/PhragmentPatchController.php @@ -1,104 +1,97 @@ 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()) ->setViewer($viewer) ->withIDs($ids) ->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(); } $file_phids = array(); if ($version_a !== null) { $file_phids[] = $version_a->getFilePHID(); } $file_phids[] = $version_b->getFilePHID(); $files = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs($file_phids) ->execute(); $files = mpull($files, null, 'getPHID'); $file_a = null; if ($version_a != null) { $file_a = idx($files, $version_a->getFilePHID(), null); } $file_b = idx($files, $version_b->getFilePHID(), null); $patch = PhragmentPatchUtil::calculatePatch($file_a, $file_b); if ($patch === null) { // There are no differences between the two files, so we output // an empty patch. $patch = ''; } $a_sequence = 'x'; if ($version_a !== null) { $a_sequence = $version_a->getSequence(); } $name = $version_b->getFragment()->getName().'.'. $a_sequence.'.'. $version_b->getSequence().'.patch'; $return = $version_b->getURI(); if ($request->getExists('return')) { $return = $request->getStr('return'); } $result = PhabricatorFile::buildFromFileDataOrHash( $patch, array( 'name' => $name, 'mime-type' => 'text/plain', 'ttl' => time() + 60 * 60 * 24, )); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $result->attachToObject($version_b->getFragmentPHID()); unset($unguarded); return id(new AphrontRedirectResponse()) ->setURI($result->getDownloadURI($return)); } } diff --git a/src/applications/phragment/controller/PhragmentPolicyController.php b/src/applications/phragment/controller/PhragmentPolicyController.php index 700c3edb5b..edcde80990 100644 --- a/src/applications/phragment/controller/PhragmentPolicyController.php +++ b/src/applications/phragment/controller/PhragmentPolicyController.php @@ -1,109 +1,106 @@ 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(); } $fragment = idx($parents, count($parents) - 1, null); $error_view = null; if ($request->isFormPost()) { $errors = array(); $v_view_policy = $request->getStr('viewPolicy'); $v_edit_policy = $request->getStr('editPolicy'); $v_replace_children = $request->getBool('replacePoliciesOnChildren'); $fragment->setViewPolicy($v_view_policy); $fragment->setEditPolicy($v_edit_policy); $fragment->save(); if ($v_replace_children) { // If you can edit a fragment, you can forcibly set the policies // on child fragments, regardless of whether you can see them or not. $children = id(new PhragmentFragmentQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withLeadingPath($fragment->getPath().'/') ->execute(); $children_phids = mpull($children, 'getPHID'); $fragment->openTransaction(); foreach ($children as $child) { $child->setViewPolicy($v_view_policy); $child->setEditPolicy($v_edit_policy); $child->save(); } $fragment->saveTransaction(); } return id(new AphrontRedirectResponse()) ->setURI('/phragment/browse/'.$fragment->getPath()); } $policies = id(new PhabricatorPolicyQuery()) ->setViewer($viewer) ->setObject($fragment) ->execute(); $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormPolicyControl()) ->setName('viewPolicy') ->setPolicyObject($fragment) ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) ->setPolicies($policies)) ->appendChild( id(new AphrontFormPolicyControl()) ->setName('editPolicy') ->setPolicyObject($fragment) ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) ->setPolicies($policies)) ->appendChild( id(new AphrontFormCheckboxControl()) ->addCheckbox( 'replacePoliciesOnChildren', 'true', pht( 'Replace policies on child fragments with '. 'the policies above.'))) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Save Fragment Policies')) ->addCancelButton( $this->getApplicationURI('browse/'.$fragment->getPath()))); $crumbs = $this->buildApplicationCrumbsWithPath($parents); $crumbs->addTextCrumb(pht('Edit Fragment Policies')); $box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Edit Fragment Policies: %s', $fragment->getPath())) ->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); + } } diff --git a/src/applications/phragment/controller/PhragmentRevertController.php b/src/applications/phragment/controller/PhragmentRevertController.php index 92da1f27a3..e9d56eb112 100644 --- a/src/applications/phragment/controller/PhragmentRevertController.php +++ b/src/applications/phragment/controller/PhragmentRevertController.php @@ -1,87 +1,79 @@ 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, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if ($fragment === null) { return new Aphront404Response(); } $version = id(new PhragmentFragmentVersionQuery()) ->setViewer($viewer) ->withFragmentPHIDs(array($fragment->getPHID())) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->executeOne(); if ($version === null) { return new Aphront404Response(); } if ($request->isDialogFormPost()) { $file_phid = $version->getFilePHID(); $file = null; if ($file_phid !== null) { $file = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs(array($file_phid)) ->executeOne(); if ($file === null) { throw new Exception( pht('The file associated with this version was not found.')); } } if ($file === null) { $fragment->deleteFile($viewer); } else { $fragment->updateFromFile($viewer, $file); } return id(new AphrontRedirectResponse()) - ->setURI($this->getApplicationURI('/history/'.$this->dblob)); + ->setURI($this->getApplicationURI('/history/'.$dblob)); } return $this->createDialog($fragment, $version); } public function createDialog( 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( 'Reverting this fragment to version %d will create a new version of '. 'the fragment. It will not delete any version history.', $version->getSequence(), $version->getSequence())); return id(new AphrontDialogResponse())->setDialog($dialog); } } diff --git a/src/applications/phragment/controller/PhragmentSnapshotCreateController.php b/src/applications/phragment/controller/PhragmentSnapshotCreateController.php index e135819280..c32be32cd7 100644 --- a/src/applications/phragment/controller/PhragmentSnapshotCreateController.php +++ b/src/applications/phragment/controller/PhragmentSnapshotCreateController.php @@ -1,173 +1,170 @@ 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(); } $fragment = nonempty(last($parents), null); if ($fragment === null) { return new Aphront404Response(); } PhabricatorPolicyFilter::requireCapability( $viewer, $fragment, PhabricatorPolicyCapability::CAN_EDIT); $children = id(new PhragmentFragmentQuery()) ->setViewer($viewer) ->needLatestVersion(true) ->withLeadingPath($fragment->getPath().'/') ->execute(); $errors = array(); if ($request->isFormPost()) { $v_name = $request->getStr('name'); if (strlen($v_name) === 0) { $errors[] = pht('You must specify a name.'); } if (strpos($v_name, '/') !== false) { $errors[] = pht('Snapshot names can not contain "/".'); } if (!count($errors)) { $snapshot = null; try { // Create the snapshot. $snapshot = id(new PhragmentSnapshot()) ->setPrimaryFragmentPHID($fragment->getPHID()) ->setName($v_name) ->save(); } catch (AphrontDuplicateKeyQueryException $e) { $errors[] = pht('A snapshot with this name already exists.'); } if (!count($errors)) { // Add the primary fragment. id(new PhragmentSnapshotChild()) ->setSnapshotPHID($snapshot->getPHID()) ->setFragmentPHID($fragment->getPHID()) ->setFragmentVersionPHID($fragment->getLatestVersionPHID()) ->save(); // Add all of the child fragments. foreach ($children as $child) { id(new PhragmentSnapshotChild()) ->setSnapshotPHID($snapshot->getPHID()) ->setFragmentPHID($child->getPHID()) ->setFragmentVersionPHID($child->getLatestVersionPHID()) ->save(); } return id(new AphrontRedirectResponse()) ->setURI('/phragment/snapshot/view/'.$snapshot->getID()); } } } $fragment_sequence = '-'; if ($fragment->getLatestVersion() !== null) { $fragment_sequence = $fragment->getLatestVersion()->getSequence(); } $rows = array(); $rows[] = phutil_tag( 'tr', array(), array( phutil_tag('th', array(), pht('Fragment')), phutil_tag('th', array(), pht('Version')), )); $rows[] = phutil_tag( 'tr', array(), array( phutil_tag('td', array(), $fragment->getPath()), phutil_tag('td', array(), $fragment_sequence), )); foreach ($children as $child) { $sequence = '-'; if ($child->getLatestVersion() !== null) { $sequence = $child->getLatestVersion()->getSequence(); } $rows[] = phutil_tag( 'tr', array(), array( phutil_tag('td', array(), $child->getPath()), phutil_tag('td', array(), $sequence), )); } $table = phutil_tag( 'table', array('class' => 'remarkup-table'), $rows); $container = phutil_tag( 'div', array('class' => 'phabricator-remarkup'), array( phutil_tag( 'p', array(), pht( 'The snapshot will contain the following fragments at '. 'the specified versions: ')), $table, )); $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Fragment Path')) ->setDisabled(true) ->setValue('/'.$fragment->getPath())) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Snapshot Name')) ->setName('name')) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Create Snapshot')) ->addCancelButton( $this->getApplicationURI('browse/'.$fragment->getPath()))) ->appendChild( id(new PHUIFormDividerControl())) ->appendInstructions($container); $crumbs = $this->buildApplicationCrumbsWithPath($parents); $crumbs->addTextCrumb(pht('Create Snapshot')); $box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Create Snapshot of %s', $fragment->getName())) ->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); + } } diff --git a/src/applications/phragment/controller/PhragmentSnapshotDeleteController.php b/src/applications/phragment/controller/PhragmentSnapshotDeleteController.php index 715280a2c2..8f112585d0 100644 --- a/src/applications/phragment/controller/PhragmentSnapshotDeleteController.php +++ b/src/applications/phragment/controller/PhragmentSnapshotDeleteController.php @@ -1,54 +1,47 @@ 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) ->requireCapabilities(array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->executeOne(); if ($snapshot === null) { return new Aphront404Response(); } if ($request->isDialogFormPost()) { $fragment_uri = $snapshot->getPrimaryFragment()->getURI(); $snapshot->delete(); return id(new AphrontRedirectResponse()) ->setURI($fragment_uri); } return $this->createDialog(); } 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( 'Deleting this snapshot is a permanent operation. You can not '. 'recover the state of the snapshot.')); return id(new AphrontDialogResponse())->setDialog($dialog); } } diff --git a/src/applications/phragment/controller/PhragmentSnapshotPromoteController.php b/src/applications/phragment/controller/PhragmentSnapshotPromoteController.php index 18d7df6a5a..981d139742 100644 --- a/src/applications/phragment/controller/PhragmentSnapshotPromoteController.php +++ b/src/applications/phragment/controller/PhragmentSnapshotPromoteController.php @@ -1,195 +1,188 @@ 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(); } $this->snapshots = id(new PhragmentSnapshotQuery()) ->setViewer($viewer) ->withPrimaryFragmentPHIDs(array($this->targetFragment->getPHID())) ->execute(); } // 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(); } $this->snapshots = id(new PhragmentSnapshotQuery()) ->setViewer($viewer) ->withPrimaryFragmentPHIDs(array( $this->targetSnapshot->getPrimaryFragmentPHID(), )) ->execute(); } // If there's no identifier, just 404. if ($this->snapshots === null) { return new Aphront404Response(); } // Work out what options the user has. $this->options = mpull( $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 // user there are no snapshots to promote. if (count($this->options) === 0) { return id(new AphrontDialogResponse())->setDialog( id(new AphrontDialogView()) ->setTitle(pht('No snapshots to promote')) ->appendParagraph(pht( 'There are no snapshots available to promote.')) - ->setUser($request->getUser()) + ->setUser($this->getViewer()) ->addCancelButton(pht('Cancel'))); } // Handle snapshot promotion. if ($request->isDialogFormPost()) { $snapshot = id(new PhragmentSnapshotQuery()) ->setViewer($viewer) ->withIDs(array($request->getStr('snapshot'))) ->executeOne(); if ($snapshot === null) { return new Aphront404Response(); } $snapshot->openTransaction(); // Delete all existing child entries. $children = id(new PhragmentSnapshotChildQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withSnapshotPHIDs(array($snapshot->getPHID())) ->execute(); foreach ($children as $child) { $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) ->needLatestVersion(true) ->withLeadingPath($this->targetFragment->getPath().'/') ->execute(); // Add the primary fragment. id(new PhragmentSnapshotChild()) ->setSnapshotPHID($snapshot->getPHID()) ->setFragmentPHID($this->targetFragment->getPHID()) ->setFragmentVersionPHID( $this->targetFragment->getLatestVersionPHID()) ->save(); // Add all of the child fragments. foreach ($children as $child) { id(new PhragmentSnapshotChild()) ->setSnapshotPHID($snapshot->getPHID()) ->setFragmentPHID($child->getPHID()) ->setFragmentVersionPHID($child->getLatestVersionPHID()) ->save(); } } else { // The user is promoting the snapshot to another snapshot. We just // copy the other snapshot's child entries and change the snapshot // PHID to make it identical. $children = id(new PhragmentSnapshotChildQuery()) ->setViewer($viewer) ->withSnapshotPHIDs(array($this->targetSnapshot->getPHID())) ->execute(); foreach ($children as $child) { id(new PhragmentSnapshotChild()) ->setSnapshotPHID($snapshot->getPHID()) ->setFragmentPHID($child->getFragmentPHID()) ->setFragmentVersionPHID($child->getFragmentVersionPHID()) ->save(); } } $snapshot->saveTransaction(); - if ($this->id === null) { + if ($id === null) { return id(new AphrontRedirectResponse()) ->setURI($this->targetFragment->getURI()); } else { return id(new AphrontRedirectResponse()) ->setURI($this->targetSnapshot->getURI()); } } - 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:')); } else { // The user is promoting a snapshot to another snapshot. $dialog->appendParagraph(pht( "Select the snapshot you want to promote to '%s':", $this->targetSnapshot->getName())); } $dialog->appendChild( id(new AphrontFormSelectControl()) ->setUser($viewer) ->setName('snapshot') ->setOptions($this->options)); return id(new AphrontDialogResponse())->setDialog($dialog); } } diff --git a/src/applications/phragment/controller/PhragmentSnapshotViewController.php b/src/applications/phragment/controller/PhragmentSnapshotViewController.php index fe499fffa1..052b5036fb 100644 --- a/src/applications/phragment/controller/PhragmentSnapshotViewController.php +++ b/src/applications/phragment/controller/PhragmentSnapshotViewController.php @@ -1,149 +1,145 @@ 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(); } $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); $crumbs->addTextCrumb(pht('"%s" Snapshot', $snapshot->getName())); $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, - $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) { if ($snapshot === null) { return null; } $viewer = $this->getRequest()->getUser(); $header = id(new PHUIHeaderView()) ->setHeader(pht('"%s" Snapshot', $snapshot->getName())) ->setPolicyObject($snapshot) ->setUser($viewer); $zip_uri = $this->getApplicationURI( 'zip@'.$snapshot->getName(). '/'.$snapshot->getPrimaryFragment()->getPath()); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $snapshot, PhabricatorPolicyCapability::CAN_EDIT); $actions = id(new PhabricatorActionListView()) ->setUser($viewer) ->setObject($snapshot); $actions->addAction( id(new PhabricatorActionView()) ->setName(pht('Download Snapshot as ZIP')) ->setHref($this->isCorrectlyConfigured() ? $zip_uri : null) ->setDisabled(!$this->isCorrectlyConfigured()) ->setIcon('fa-floppy-o')); $actions->addAction( id(new PhabricatorActionView()) ->setName(pht('Delete Snapshot')) ->setHref($this->getApplicationURI( 'snapshot/delete/'.$snapshot->getID().'/')) ->setDisabled(!$can_edit) ->setWorkflow(true) ->setIcon('fa-times')); $actions->addAction( id(new PhabricatorActionView()) ->setName(pht('Promote Another Snapshot to Here')) ->setHref($this->getApplicationURI( 'snapshot/promote/'.$snapshot->getID().'/')) ->setDisabled(!$can_edit) ->setWorkflow(true) ->setIcon('fa-arrow-up')); $properties = id(new PHUIPropertyListView()) ->setUser($viewer) ->setObject($snapshot) ->setActionList($actions); $properties->addProperty( pht('Name'), $snapshot->getName()); $properties->addProperty( pht('Fragment'), $viewer->renderHandle($snapshot->getPrimaryFragmentPHID())); return id(new PHUIObjectBoxView()) ->setHeader($header) ->addPropertyList($properties); } } diff --git a/src/applications/phragment/controller/PhragmentUpdateController.php b/src/applications/phragment/controller/PhragmentUpdateController.php index 1b8d10e91f..7fb91ccd4e 100644 --- a/src/applications/phragment/controller/PhragmentUpdateController.php +++ b/src/applications/phragment/controller/PhragmentUpdateController.php @@ -1,83 +1,80 @@ 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(); } $fragment = idx($parents, count($parents) - 1, null); $error_view = null; if ($request->isFormPost()) { $errors = array(); $v_fileid = $request->getInt('fileID'); $file = id(new PhabricatorFile())->load($v_fileid); if ($file === null) { $errors[] = pht('The specified file doesn\'t exist.'); } if (!count($errors)) { // If the file is a ZIP archive (has application/zip mimetype) // then we extract the zip and apply versions for each of the // individual fragments, creating and deleting files as needed. if ($file->getMimeType() === 'application/zip') { $fragment->updateFromZIP($viewer, $file); } else { $fragment->updateFromFile($viewer, $file); } return id(new AphrontRedirectResponse()) ->setURI('/phragment/browse/'.$fragment->getPath()); } else { $error_view = id(new PHUIInfoView()) ->setErrors($errors) ->setTitle(pht('Errors while updating fragment')); } } $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('File ID')) ->setName('fileID')) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Update Fragment')) ->addCancelButton( $this->getApplicationURI('browse/'.$fragment->getPath()))); $crumbs = $this->buildApplicationCrumbsWithPath($parents); $crumbs->addTextCrumb(pht('Update Fragment')); $box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Update Fragment: %s', $fragment->getPath())) ->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); + } } diff --git a/src/applications/phragment/controller/PhragmentVersionController.php b/src/applications/phragment/controller/PhragmentVersionController.php index 29b920a4e5..2b1ae2bdf0 100644 --- a/src/applications/phragment/controller/PhragmentVersionController.php +++ b/src/applications/phragment/controller/PhragmentVersionController.php @@ -1,131 +1,125 @@ 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(); } $parents = $this->loadParentFragments($version->getFragment()->getPath()); if ($parents === null) { return new Aphront404Response(); } $current = idx($parents, count($parents) - 1, null); $crumbs = $this->buildApplicationCrumbsWithPath($parents); $crumbs->addTextCrumb(pht('View Version %d', $version->getSequence())); $file = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs(array($version->getFilePHID())) ->executeOne(); if ($file !== null) { $file_uri = $file->getDownloadURI(); } $header = id(new PHUIHeaderView()) ->setHeader(pht( '%s at version %d', $version->getFragment()->getName(), $version->getSequence())) ->setPolicyObject($version) ->setUser($viewer); $actions = id(new PhabricatorActionListView()) ->setUser($viewer) ->setObject($version); $actions->addAction( id(new PhabricatorActionView()) ->setName(pht('Download Version')) ->setDisabled($file === null || !$this->isCorrectlyConfigured()) ->setHref($this->isCorrectlyConfigured() ? $file_uri : null) ->setIcon('fa-download')); $properties = id(new PHUIPropertyListView()) ->setUser($viewer) ->setObject($version) ->setActionList($actions); $properties->addProperty( pht('File'), $viewer->renderHandle($version->getFilePHID())); $box = id(new PHUIObjectBoxView()) ->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) ->withFragmentPHIDs(array($version->getFragmentPHID())) ->withSequenceBefore($version->getSequence()) ->execute(); $list = id(new PHUIObjectItemListView()) ->setUser($viewer); foreach ($previous_versions as $previous_version) { $item = id(new PHUIObjectItemView()); $item->setHeader(pht('Version %s', $previous_version->getSequence())); $item->setHref($previous_version->getURI()); $item->addAttribute(phabricator_datetime( $previous_version->getDateCreated(), $viewer)); $patch_uri = $this->getApplicationURI( 'patch/'.$previous_version->getID().'/'.$version->getID()); $item->addAction(id(new PHUIListItemView()) ->setIcon('fa-file-o') ->setName(pht('Get Patch')) ->setHref($this->isCorrectlyConfigured() ? $patch_uri : null) ->setDisabled(!$this->isCorrectlyConfigured())); $list->addItem($item); } $item = id(new PHUIObjectItemView()); $item->setHeader(pht('Prior to Version 0')); $item->addAttribute(pht('Prior to any content (empty file)')); $item->addAction(id(new PHUIListItemView()) ->setIcon('fa-file-o') ->setName(pht('Get Patch')) ->setHref($this->getApplicationURI( 'patch/x/'.$version->getID()))); $list->addItem($item); return $list; } } diff --git a/src/applications/phragment/controller/PhragmentZIPController.php b/src/applications/phragment/controller/PhragmentZIPController.php index 0de9f4d344..75d464d9c8 100644 --- a/src/applications/phragment/controller/PhragmentZIPController.php +++ b/src/applications/phragment/controller/PhragmentZIPController.php @@ -1,156 +1,153 @@ dblob = idx($data, 'dblob', ''); - $this->snapshot = idx($data, 'snapshot', null); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $dblob = $request->getURIData('dblob'); + $snapshot = $request->getURIData('snapshot'); - $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(); } $cache = id(new PhragmentSnapshotChildQuery()) ->setViewer($viewer) ->needFragmentVersions(true) ->withSnapshotPHIDs(array($snapshot->getPHID())) ->execute(); $this->snapshotCache = mpull( $cache, 'getFragmentVersion', 'getFragmentPHID'); } $temp = new TempFile(); $zip = null; try { $zip = new ZipArchive(); } catch (Exception $e) { $dialog = new AphrontDialogView(); $dialog->setUser($viewer); $inst = pht( 'This system does not have the ZIP PHP extension installed. This '. 'is required to download ZIPs from Phragment.'); $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); } if (!$zip->open((string)$temp, ZipArchive::CREATE)) { 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) { $phids[] = $file_phid; } $files = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs($phids) ->execute(); $files = mpull($files, null, 'getPHID'); foreach ($mappings as $path => $file_phid) { if (!isset($files[$file_phid])) { // The path is most likely pointing to a deleted fragment, which // hence no longer has a file associated with it. unset($mappings[$path]); continue; } $mappings[$path] = $files[$file_phid]; } foreach ($mappings as $path => $file) { if ($file !== null) { $zip->addFromString($path, $file->loadFileData()); } } $zip->close(); $zip_name = $fragment->getName(); if (substr($zip_name, -4) !== '.zip') { $zip_name .= '.zip'; } $data = Filesystem::readFile((string)$temp); $file = PhabricatorFile::buildFromFileDataOrHash( $data, array( 'name' => $zip_name, 'ttl' => time() + 60 * 60 * 24, )); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $file->attachToObject($fragment->getPHID()); unset($unguarded); $return = $fragment->getURI(); if ($request->getExists('return')) { $return = $request->getStr('return'); } return id(new AphrontRedirectResponse()) ->setIsExternal(true) ->setURI($file->getDownloadURI($return)); } /** * 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(); } } 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); } } }