Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phragment/controller/PhragmentUpdateController.php
- This file was added.
<?php | |||||
final class PhragmentUpdateController 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 = 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)) { | |||||
$existing = id(new PhragmentPatchQuery()) | |||||
->setViewer($viewer) | |||||
->withFragmentPHIDs(array($fragment->getPHID())) | |||||
->execute(); | |||||
$sequence = count($existing); | |||||
$patch = id(new PhragmentPatch()); | |||||
$patch->setSequence($sequence); | |||||
$patch->setFragmentPHID($fragment->getPHID()); // Can't set this yet... | |||||
$patch->setFilePHID($file->getPHID()); | |||||
epriestley: Bad copy/paste on the comment? | |||||
$patch->save(); | |||||
$fragment->setPatchPHID($patch->getPHID()); | |||||
$fragment->save(); | |||||
Not Done Inline ActionsMight be worth a : $fragment->openTransaction(); // ... save(); save(); $fragment->saveTransaction(); ...until we get ApplicationTransactions in, just to make sure the database stays consistent. epriestley: Might be worth a :
$fragment->openTransaction();
// ... save(); save();
$fragment… | |||||
return id(new AphrontRedirectResponse()) | |||||
->setURI('/phragment/browse/'.$fragment->getPath()); | |||||
} else { | |||||
$error_view = id(new AphrontErrorView()) | |||||
->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->addCrumb( | |||||
id(new PhabricatorCrumbView()) | |||||
->setName(pht('Update Fragment'))); | |||||
$box = id(new PHUIObjectBoxView()) | |||||
->setHeaderText(pht('Update Fragment: %s', $fragment->getPath())) | |||||
->setValidationException(null) | |||||
->setForm($form); | |||||
return $this->buildApplicationPage( | |||||
array( | |||||
$crumbs, | |||||
$box), | |||||
array( | |||||
'title' => pht('Update Fragment'), | |||||
'device' => true)); | |||||
} | |||||
} |
Bad copy/paste on the comment?