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

[SettingsBundle] Add validation when saving parameters to guarantee database integrity #1193

Merged
merged 5 commits into from
Mar 21, 2014

Conversation

ruudkobes
Copy link
Contributor

Because of #1114, I've looked into the settings management in the SettingsBundle. The error in question results from an incomplete serialized value in the database, which in turn triggers a PHP notice when unserializing. I've added validation to at least prevent corrupt values in the parameters table.

I'm not yet satisfied how this code handles the error, though. Would it be an improvement to add a new ValidatorException which contains the complete ConstraintViolationList that's returned by $validator->validate()? This would also allow the caller of saveSettings (the SettingsController) to display which parameters failed and on which constraints (instead of only the first failing constraint of one parameter.

@stloyd stloyd added this to the 1.0.0-BETA1 milestone Mar 12, 2014
@ruudkobes
Copy link
Contributor Author

I think this is a bugfix, rather than an enhancement.
Without this patch simply entering any settings value longer than about 250 characters results in a fatal problem the next time the settings are retrieved.

$request->getSession()->getFlashBag()->add('success', $message);
} catch (ValidatorException $exception) {
$message = $this->getTranslator()->trans($exception->getMessage(), array(), 'flashes');
$request->getSession()->getFlashBag()->add('error', $message);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this below, and add variable $type = 'error', and $type = 'success'.

@ruudkobes
Copy link
Contributor Author

Will fix. I should read code guidelines better next time :)

@pjedrzejewski
Copy link
Member

Thanks for figuring this out... How about changing the Parameter.value field to text doctrine type? I'm surprised I've used 255 string... It definitely should be a text field...

@QuingKhaos
Copy link
Contributor

@pjedrzejewski why not object so Doctrine uses automatically serialize() and unserialize().

@ruudkobes
Copy link
Contributor Author

Object indeed seems to be exactly the type that fits this requirement

@ruudkobes
Copy link
Contributor Author

Validation would than only need to be applied on the namespace and name fields

@pjedrzejewski
Copy link
Member

Sorry, I meant object doctrine type of course. I was thinking about sql field.

@ruudkobes
Copy link
Contributor Author

I can integrate this in this PR (change get/set in Parameter entity and update mapping). The database migrates without problems when running doctrine:schema:update manually. Does everyone who gets this update have to do this schema update manually? How do they know they have to?

@ruudkobes
Copy link
Contributor Author

How can it be that Travis fails on simply removing a line in a comment?

The command "bin/phpspec run -f dot" exited with 0.

Done. Your build exited with 1.

@ruudkobes
Copy link
Contributor Author

@pjedrzejewski @stloyd I have added the Doctrine type change in this PR.

Don't know why Travis fails though. There are no errors in the scenarios and the last commit only removes one comment line. Can anyone shed some light on this?

@stloyd
Copy link
Contributor

stloyd commented Mar 21, 2014

@pjedrzejewski Without some trivial CS issues, it looks ok for me, what do you think about this?

pjedrzejewski pushed a commit that referenced this pull request Mar 21, 2014
[SettingsBundle] Add validation when saving parameters to guarantee database integrity
@pjedrzejewski pjedrzejewski merged commit 1691b7f into Sylius:master Mar 21, 2014
@pjedrzejewski
Copy link
Member

Thanks Ruud! Nice work. 👍

@ruudkobes ruudkobes deleted the parameter-fix branch March 21, 2014 10:03
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.

None yet

4 participants