Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14828846
D7738.id17485.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D7738.id17485.diff
View Options
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -2186,6 +2186,7 @@
'PhragmentPHIDTypeFragment' => 'applications/phragment/phid/PhragmentPHIDTypeFragment.php',
'PhragmentPHIDTypeFragmentVersion' => 'applications/phragment/phid/PhragmentPHIDTypeFragmentVersion.php',
'PhragmentPatchUtil' => 'applications/phragment/util/PhragmentPatchUtil.php',
+ 'PhragmentRevertController' => 'applications/phragment/controller/PhragmentRevertController.php',
'PhragmentUpdateController' => 'applications/phragment/controller/PhragmentUpdateController.php',
'PhragmentZIPController' => 'applications/phragment/controller/PhragmentZIPController.php',
'PhrequentController' => 'applications/phrequent/controller/PhrequentController.php',
@@ -4785,6 +4786,7 @@
'PhragmentPHIDTypeFragment' => 'PhabricatorPHIDType',
'PhragmentPHIDTypeFragmentVersion' => 'PhabricatorPHIDType',
'PhragmentPatchUtil' => 'Phobject',
+ 'PhragmentRevertController' => 'PhragmentController',
'PhragmentUpdateController' => 'PhragmentController',
'PhragmentZIPController' => 'PhragmentController',
'PhrequentController' => 'PhabricatorController',
Index: src/applications/phragment/application/PhabricatorApplicationPhragment.php
===================================================================
--- src/applications/phragment/application/PhabricatorApplicationPhragment.php
+++ src/applications/phragment/application/PhabricatorApplicationPhragment.php
@@ -39,6 +39,7 @@
'update/(?P<dblob>.*)' => 'PhragmentUpdateController',
'history/(?P<dblob>.*)' => 'PhragmentHistoryController',
'zip/(?P<dblob>.*)' => 'PhragmentZIPController',
+ 'revert/(?P<id>[0-9]*)/(?P<dblob>.*)' => 'PhragmentRevertController',
),
);
}
Index: src/applications/phragment/controller/PhragmentHistoryController.php
===================================================================
--- src/applications/phragment/controller/PhragmentHistoryController.php
+++ src/applications/phragment/controller/PhragmentHistoryController.php
@@ -44,6 +44,7 @@
->execute();
$files = mpull($files, null, 'getPHID');
+ $first = true;
foreach ($versions as $version) {
$item = id(new PHUIObjectItemView());
$item->setHeader('Version '.$version->getSequence());
@@ -51,6 +52,16 @@
$version->getDateCreated(),
$viewer));
+ if (!$first) {
+ $item->addAction(id(new PHUIListItemView())
+ ->setIcon('undo')
+ ->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('download')
@@ -62,6 +73,8 @@
}
$item->addAction($action);
$list->addItem($item);
+
+ $first = false;
}
return $this->buildApplicationPage(
Index: src/applications/phragment/controller/PhragmentRevertController.php
===================================================================
--- /dev/null
+++ src/applications/phragment/controller/PhragmentRevertController.php
@@ -0,0 +1,81 @@
+<?php
+
+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();
+
+ $fragment = id(new PhragmentFragmentQuery())
+ ->setViewer($viewer)
+ ->withPaths(array($this->dblob))
+ ->executeOne();
+ if ($fragment === null) {
+ return new Aphront404Response();
+ }
+
+ $version = id(new PhragmentFragmentVersionQuery())
+ ->setViewer($viewer)
+ ->withFragmentPHIDs(array($fragment->getPHID()))
+ ->withIDs(array($this->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(
+ "The file associated with this version was not found.");
+ }
+ }
+
+ if ($file === null) {
+ $fragment->deleteFile($viewer);
+ } else {
+ $fragment->updateFromFile($viewer, $file);
+ }
+
+ return id(new AphrontRedirectResponse());
+ }
+
+ return $this->createDialog($fragment, $version);
+ }
+
+ function createDialog(
+ PhragmentFragment $fragment,
+ PhragmentFragmentVersion $version) {
+
+ $request = $this->getRequest();
+ $viewer = $request->getUser();
+
+ $dialog = id(new AphrontDialogView())
+ ->setTitle(pht('Really revert this fragment?'))
+ ->setUser($request->getUser())
+ ->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);
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 30, 2:10 PM (55 m, 22 s)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7074787
Default Alt Text
D7738.id17485.diff (5 KB)
Attached To
Mode
D7738: Implement "Revert to Version" functionality in Phragment
Attached
Detach File
Event Timeline
Log In to Comment