Pholio - robustify submission errors to retain image edits
Summary: we should build all the image stuff on every post and use that posted image data if there's an error. this diff makes that so. Fixes T4380. Test Plan: made a mock with no title, tried to save it, and was delighted to see my images still there. edited a mock - removing the title and adding images - verified edits showed up after erroneous submission. added a title and submitted and changes were saved. Reviewers: epriestley Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T4380 Differential Revision: https://secure.phabricator.com/D8197
This commit is contained in:
@@ -50,6 +50,7 @@ final class PholioMockEditController extends PholioController {
|
||||
$e_name = true;
|
||||
$e_images = true;
|
||||
$errors = array();
|
||||
$posted_mock_images = array();
|
||||
|
||||
$v_name = $mock->getName();
|
||||
$v_desc = $mock->getDescription();
|
||||
@@ -100,7 +101,6 @@ final class PholioMockEditController extends PholioController {
|
||||
$mock->setCoverPHID(head($files)->getPHID());
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
foreach ($mock_xactions as $type => $value) {
|
||||
$xactions[$type] = id(new PholioTransaction())
|
||||
->setTransactionType($type)
|
||||
@@ -137,6 +137,7 @@ final class PholioMockEditController extends PholioController {
|
||||
$replace_image = id(new PholioImage())
|
||||
->setReplacesImagePHID($replaces_image_phid)
|
||||
->setFilePhid($file_phid)
|
||||
->attachFile($file)
|
||||
->setName(strlen($title) ? $title : $file->getName())
|
||||
->setDescription($description)
|
||||
->setSequence($sequence);
|
||||
@@ -144,9 +145,11 @@ final class PholioMockEditController extends PholioController {
|
||||
->setTransactionType(
|
||||
PholioTransactionType::TYPE_IMAGE_REPLACE)
|
||||
->setNewValue($replace_image);
|
||||
$posted_mock_images[] = $replace_image;
|
||||
} else if (!$existing_image) { // this is an add
|
||||
$add_image = id(new PholioImage())
|
||||
->setFilePhid($file_phid)
|
||||
->attachFile($file)
|
||||
->setName(strlen($title) ? $title : $file->getName())
|
||||
->setDescription($description)
|
||||
->setSequence($sequence);
|
||||
@@ -154,6 +157,7 @@ final class PholioMockEditController extends PholioController {
|
||||
->setTransactionType(PholioTransactionType::TYPE_IMAGE_FILE)
|
||||
->setNewValue(
|
||||
array('+' => array($add_image)));
|
||||
$posted_mock_images[] = $add_image;
|
||||
} else {
|
||||
$xactions[] = id(new PholioTransaction())
|
||||
->setTransactionType(PholioTransactionType::TYPE_IMAGE_NAME)
|
||||
@@ -169,6 +173,7 @@ final class PholioMockEditController extends PholioController {
|
||||
PholioTransactionType::TYPE_IMAGE_SEQUENCE)
|
||||
->setNewValue(
|
||||
array($existing_image->getPHID() => $sequence));
|
||||
$posted_mock_images[] = $existing_image;
|
||||
}
|
||||
}
|
||||
foreach ($mock_images as $file_phid => $mock_image) {
|
||||
@@ -181,6 +186,7 @@ final class PholioMockEditController extends PholioController {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
$mock->openTransaction();
|
||||
$editor = id(new PholioMockEditor())
|
||||
->setContentSourceFromRequest($request)
|
||||
@@ -220,10 +226,16 @@ final class PholioMockEditController extends PholioController {
|
||||
->execute();
|
||||
|
||||
$image_elements = array();
|
||||
foreach ($mock_images as $mock_image) {
|
||||
if ($posted_mock_images) {
|
||||
$display_mock_images = $posted_mock_images;
|
||||
} else {
|
||||
$display_mock_images = $mock_images;
|
||||
}
|
||||
foreach ($display_mock_images as $mock_image) {
|
||||
$image_elements[] = id(new PholioUploadedImageView())
|
||||
->setUser($user)
|
||||
->setImage($mock_image);
|
||||
->setImage($mock_image)
|
||||
->setReplacesPHID($mock_image->getReplacesImagePHID());
|
||||
}
|
||||
|
||||
$list_id = celerity_generate_unique_node_id();
|
||||
|
||||
Reference in New Issue
Block a user