mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-03 07:59:15 +01:00
Summary: Ref T4212. This implements snapshots in Phragment, which allows you to take a snapshot of a fragment at a given point in time, and download a ZIP of the snapshot as it was in this state. There's also functionality for deleting and promoting snapshots. You can promote a snapshot to either the latest version or any other snapshot of the fragment. Test Plan: Clicked around, took some snapshots, promoted them to different points and deleted snapshots. Also downloaded ZIPs of the snapshots and saw the right versions coming through for all the files downloaded. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T4205, T4212 Differential Revision: https://secure.phabricator.com/D7741
170 lines
4.8 KiB
PHP
170 lines
4.8 KiB
PHP
<?php
|
|
|
|
final class PhragmentSnapshotCreateController extends PhragmentController {
|
|
|
|
private $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);
|
|
if ($parents === null) {
|
|
return new Aphront404Response();
|
|
}
|
|
$fragment = nonempty(last($parents), null);
|
|
if ($fragment === null) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$children = id(new PhragmentFragmentQuery())
|
|
->setViewer($viewer)
|
|
->needLatestVersion(true)
|
|
->withLeadingPath($fragment->getPath().'/')
|
|
->execute();
|
|
|
|
$error_view = null;
|
|
|
|
if ($request->isFormPost()) {
|
|
$errors = array();
|
|
|
|
$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 (AphrontQueryDuplicateKeyException $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());
|
|
}
|
|
}
|
|
|
|
$error_view = id(new AphrontErrorView())
|
|
->setErrors($errors)
|
|
->setTitle(pht('Errors while creating snapshot'));
|
|
}
|
|
|
|
$fragment_sequence = "-";
|
|
if ($fragment->getLatestVersion() !== null) {
|
|
$fragment_sequence = $fragment->getLatestVersion()->getSequence();
|
|
}
|
|
|
|
$rows = array();
|
|
$rows[] = phutil_tag(
|
|
'tr',
|
|
array(),
|
|
array(
|
|
phutil_tag('th', array(), 'Fragment'),
|
|
phutil_tag('th', array(), '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->addCrumb(
|
|
id(new PhabricatorCrumbView())
|
|
->setName(pht('Create Snapshot')));
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
->setHeaderText(pht('Create Snapshot of %s', $fragment->getName()))
|
|
->setFormError($error_view)
|
|
->setForm($form);
|
|
|
|
return $this->buildApplicationPage(
|
|
array(
|
|
$crumbs,
|
|
$box),
|
|
array(
|
|
'title' => pht('Create Fragment'),
|
|
'device' => true));
|
|
}
|
|
|
|
}
|