Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore original value of the field when upload failed. #391

Merged
merged 1 commit into from
Jul 12, 2016
Merged

Restore original value of the field when upload failed. #391

merged 1 commit into from
Jul 12, 2016

Conversation

satanTime
Copy link
Contributor

It helps to keep original value if we just have file field on form and don't want to upload it but keep original file.

@josegonzalez, could you review?


- ``restoreValueOnFailure``: Restores original value of the current field when uploaded file has error

- Defaults: (boolean) ``false``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting to true would make more sense imo. No one want to lose existing data :)

@josegonzalez
Copy link
Member

@Michael-Gusev can you adjust to @ADmad's suggestion? Sane defaults are great :)

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling aeb3606 on Michael-Gusev:restore-original-value-on-failure into ff3801f on josegonzalez:master.

@satanTime
Copy link
Contributor Author

@josegonzalez @ADmad, code has been updated.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 765f3fc on Michael-Gusev:restore-original-value-on-failure into e6eb080 on josegonzalez:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 765f3fc on Michael-Gusev:restore-original-value-on-failure into e6eb080 on josegonzalez:master.

@josegonzalez
Copy link
Member

Looks good to me, thoughts @ADmad before I merge this?

@ADmad
Copy link
Member

ADmad commented Jun 9, 2016

LGTM but even with current code I don't see how your existing values would be overwritten. The beforeMarshal() ensures that field is unset from data when no file is uploaded.

@Michael-Gusev Have you actually experienced existing values being lost when editing record without uploading a file?

@satanTime
Copy link
Contributor Author

@ADmad, I have simple form.

echo $this->Form-input('image', ['type' => 'file'])

in controller

$this->Products->patchEntity($entity, $this-request->data);
$this->Products->save($entity);

so when I save form without choosing file it sets value of image to null.

@ADmad
Copy link
Member

ADmad commented Jun 9, 2016

I am unable to reproduce the behavior you mention. Though I do get an error

Notice (8): Array to string conversion [CORE/src/Database/Statement/PDOStatement.php, line 72]

and field gets saved with value "Array", when an upload error like UPLOAD_ERR_INI_SIZE is set for the field and validation rules are not set to check for upload errors. So restoring original value seems reasonable.

Personally after restoring original value I would also set the field as not dirty so as to avoid unnecessarily re-saving existing value.

It helps to keep original value if we just have file field on form and don't want to upload it but keep original file.
@satanTime
Copy link
Contributor Author

@ADmad, you're right, also updated dirty.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 66f092d on Michael-Gusev:restore-original-value-on-failure into e6eb080 on josegonzalez:master.

@josegonzalez josegonzalez merged commit aa01f01 into FriendsOfCake:master Jul 12, 2016
@josegonzalez josegonzalez changed the title Possibility to restore original value of the field when upload failed. Restore original value of the field when upload failed. Jul 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants