-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
FIX(modulebuilder): validate after creation #33105
Conversation
@BenjaminFlr and what is the impact of renaming a variable "$resultcreate" into "$resultvalidate" in a comment that is not returned in the end?
|
I suggest a more complete fix that handle both create and validate: Is it ok for you @BenjaminFlr |
That's where my limits are! |
To answer to both of you @eldy and @hregis Also, if you return the result of That's why I proposed to just change the name of the variable and, then, everybody can make his own tests depending on his needs. Because in my case, if the validation fails, I don't want to delete the object. But another developer could. |
@BenjaminFlr excuse moi, quand je ne comprend rien je préfère le faire en français... je n'ai rien compris à ce que tu as dis ! :-) |
@hregis en français : Si je ne veux pas faire une grosse réécriture de code, on ne peut pas retourner le résultat de Donc si tu retournes toujours le résultat de C'est pour ça que j'ai proposé de ne changer que le nom de la variable pour le |
@BenjaminFlr et ce qu'a envoyé Laurent comme correction ce n'est pas ok ? |
@hregis si je suis pas passé à côté de quelque chose, non : public function create(User $user, $notrigger = 0)
{
$result = $this->createCommon($user, $notrigger);
// uncomment lines below if you want to validate object after creation
// if ($result > 0) {
// $this->fetch($this->id); // needed to retrieve some fields (ie date_creation for masked ref)
// $result= $this->validate($user, $notrigger);
// }
return $result;
} Si on fait ça, ça ne change rien, on remplace juste |
@BenjaminFlr peut-être ajouter un test sur le "$resultvalidate" et si ok on renvoi le "$resultcreate" avec l'id de l'object ? |
CommonObject::createCommon()
returns the id of the newly created object, and we store it in$resultcreate
.MyObject::validate()
returns an integer between -1 and 1.If we overwrite the value of $resultcreate with -1, 0 or 1 instead of the object's id, the return of
MyObject::create()
is necessarily false. That's why I changed the name of the variable for the result of$this->validate()
.