1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-20 05:42:40 +01:00

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:
Bob Trahan 2014-02-11 11:38:10 -08:00
parent 305fb3fbd9
commit fec5ea8f9d

View file

@ -50,6 +50,7 @@ final class PholioMockEditController extends PholioController {
$e_name = true; $e_name = true;
$e_images = true; $e_images = true;
$errors = array(); $errors = array();
$posted_mock_images = array();
$v_name = $mock->getName(); $v_name = $mock->getName();
$v_desc = $mock->getDescription(); $v_desc = $mock->getDescription();
@ -100,7 +101,6 @@ final class PholioMockEditController extends PholioController {
$mock->setCoverPHID(head($files)->getPHID()); $mock->setCoverPHID(head($files)->getPHID());
} }
if (!$errors) {
foreach ($mock_xactions as $type => $value) { foreach ($mock_xactions as $type => $value) {
$xactions[$type] = id(new PholioTransaction()) $xactions[$type] = id(new PholioTransaction())
->setTransactionType($type) ->setTransactionType($type)
@ -137,6 +137,7 @@ final class PholioMockEditController extends PholioController {
$replace_image = id(new PholioImage()) $replace_image = id(new PholioImage())
->setReplacesImagePHID($replaces_image_phid) ->setReplacesImagePHID($replaces_image_phid)
->setFilePhid($file_phid) ->setFilePhid($file_phid)
->attachFile($file)
->setName(strlen($title) ? $title : $file->getName()) ->setName(strlen($title) ? $title : $file->getName())
->setDescription($description) ->setDescription($description)
->setSequence($sequence); ->setSequence($sequence);
@ -144,9 +145,11 @@ final class PholioMockEditController extends PholioController {
->setTransactionType( ->setTransactionType(
PholioTransactionType::TYPE_IMAGE_REPLACE) PholioTransactionType::TYPE_IMAGE_REPLACE)
->setNewValue($replace_image); ->setNewValue($replace_image);
$posted_mock_images[] = $replace_image;
} else if (!$existing_image) { // this is an add } else if (!$existing_image) { // this is an add
$add_image = id(new PholioImage()) $add_image = id(new PholioImage())
->setFilePhid($file_phid) ->setFilePhid($file_phid)
->attachFile($file)
->setName(strlen($title) ? $title : $file->getName()) ->setName(strlen($title) ? $title : $file->getName())
->setDescription($description) ->setDescription($description)
->setSequence($sequence); ->setSequence($sequence);
@ -154,6 +157,7 @@ final class PholioMockEditController extends PholioController {
->setTransactionType(PholioTransactionType::TYPE_IMAGE_FILE) ->setTransactionType(PholioTransactionType::TYPE_IMAGE_FILE)
->setNewValue( ->setNewValue(
array('+' => array($add_image))); array('+' => array($add_image)));
$posted_mock_images[] = $add_image;
} else { } else {
$xactions[] = id(new PholioTransaction()) $xactions[] = id(new PholioTransaction())
->setTransactionType(PholioTransactionType::TYPE_IMAGE_NAME) ->setTransactionType(PholioTransactionType::TYPE_IMAGE_NAME)
@ -169,6 +173,7 @@ final class PholioMockEditController extends PholioController {
PholioTransactionType::TYPE_IMAGE_SEQUENCE) PholioTransactionType::TYPE_IMAGE_SEQUENCE)
->setNewValue( ->setNewValue(
array($existing_image->getPHID() => $sequence)); array($existing_image->getPHID() => $sequence));
$posted_mock_images[] = $existing_image;
} }
} }
foreach ($mock_images as $file_phid => $mock_image) { foreach ($mock_images as $file_phid => $mock_image) {
@ -181,6 +186,7 @@ final class PholioMockEditController extends PholioController {
} }
} }
if (!$errors) {
$mock->openTransaction(); $mock->openTransaction();
$editor = id(new PholioMockEditor()) $editor = id(new PholioMockEditor())
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
@ -220,10 +226,16 @@ final class PholioMockEditController extends PholioController {
->execute(); ->execute();
$image_elements = array(); $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()) $image_elements[] = id(new PholioUploadedImageView())
->setUser($user) ->setUser($user)
->setImage($mock_image); ->setImage($mock_image)
->setReplacesPHID($mock_image->getReplacesImagePHID());
} }
$list_id = celerity_generate_unique_node_id(); $list_id = celerity_generate_unique_node_id();