Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phragment/controller/PhragmentUpdateController.php
Show All 25 Lines | if ($request->isFormPost()) { | ||||
$v_fileid = $request->getInt('fileID'); | $v_fileid = $request->getInt('fileID'); | ||||
$file = id(new PhabricatorFile())->load($v_fileid); | $file = id(new PhabricatorFile())->load($v_fileid); | ||||
if ($file === null) { | if ($file === null) { | ||||
$errors[] = pht('The specified file doesn\'t exist.'); | $errors[] = pht('The specified file doesn\'t exist.'); | ||||
} | } | ||||
if (!count($errors)) { | if (!count($errors)) { | ||||
$existing = id(new PhragmentFragmentVersionQuery()) | // If the file is a ZIP archive (has application/zip mimetype) | ||||
->setViewer($viewer) | // then we extract the zip and apply versions for each of the | ||||
->withFragmentPHIDs(array($fragment->getPHID())) | // individual fragments, creating and deleting files as needed. | ||||
->execute(); | if ($file->getMimeType() === "application/zip") { | ||||
$sequence = count($existing); | $fragment->updateFromZIP($viewer, $file); | ||||
} else { | |||||
$fragment->openTransaction(); | $fragment->updateFromFile($viewer, $file); | ||||
$version = id(new PhragmentFragmentVersion()); | } | ||||
$version->setSequence($sequence); | |||||
$version->setFragmentPHID($fragment->getPHID()); | |||||
$version->setFilePHID($file->getPHID()); | |||||
$version->save(); | |||||
$fragment->setLatestVersionPHID($version->getPHID()); | |||||
$fragment->save(); | |||||
$fragment->saveTransaction(); | |||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
->setURI('/phragment/browse/'.$fragment->getPath()); | ->setURI('/phragment/browse/'.$fragment->getPath()); | ||||
} else { | } else { | ||||
$error_view = id(new AphrontErrorView()) | $error_view = id(new AphrontErrorView()) | ||||
->setErrors($errors) | ->setErrors($errors) | ||||
->setTitle(pht('Errors while updating fragment')); | ->setTitle(pht('Errors while updating fragment')); | ||||
} | } | ||||
Show All 34 Lines |