API page: http://api.drupal.org/api/drupal/includes%21database%21query.inc/functio...
It's quite important to know what the execute() method returns here. Reading the code (which BTW doesn't seem to be visible on the api site), it looks like that's one of:
- return MergeQuery::STATUS_UPDATE;
- return MergeQuery::STATUS_INSERT;
- I'm not sure if it's possible to get to the end of the function body and return NULL
Comment | File | Size | Author |
---|---|---|---|
#21 | 1479220-21.patch | 1.08 KB | paulocs |
#21 | interdiff-20-21.txt | 698 bytes | paulocs |
Issue fork drupal-1479220
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
jhodgdonCode not being visible - That's a known/fixed bug in the API module (the fix just hasn't been deployed to api.drupal.org yet, but should be in a few days).
Lack of return value - agreed, should be fixed. Thanks for reporting!
Comment #2
David Jeyachandran CreditAttribution: David Jeyachandran commentedHere's a new patch where we've added documentation for the execute method found in the file: core/lib/Drupal/Core/Merge.php .
Thanks to Josimar, Julio and David.
Comment #3
jhodgdonThanks for the patch! There are a few problems:
a) The exceptions -- it should specifically document which exceptions it can throw, and under what circumstances, rather than a generic "@throws Exception".
b)
Can this be turned around to be clearer? Maybe something like "If there is a problem with the query and $this->queryOptions['throw_exception'] is TRUE (default), an exception will be thrown. Otherwise, a NULL value will be returned.
c) The @return section has a few problems:
- First line: Marge -> Merge
- First line: exists -> exist
- There should be a line introducing the list. Something like "One of the following values:"
- Last line needs to be indented two spaces and end with .
- We shouldn't have NOT be all-caps.
- Can we make the first two items more parallel in their grammatical structure? How about "If the entry already exists, and an UPDATE query is executed" and "If the entry does not already exist, and an INSERT query is executed"?
Thanks!
Comment #4
InternetDevels CreditAttribution: InternetDevels commentedAdded new patch.
Comment #5
jhodgdonThanks for the new patch!
There are a few things to clean up:
a)
Can this be wrapped into one paragraph, closer to 80-character lines? Also, I think the last line "Otherwise..." is a bit ambiguous, because the if() in the first sentence is compound. Can it be more explicit like "If ... is FALSE and there is a problem with the query, a NULL value will be returned." rather than just saying "Otherwise"?
b)
This list is not formatted correctly. See https://drupal.org/coding-standards/docs#lists
I also don't like the last item -- "if there is an exception" when above you said "if there is a problem".
c)
Not having a description on the first two exceptions is probably fine, because they are self-documenting. But for the last one, you need to describe when the generic "Exception" could be thrown. See
https://drupal.org/coding-standards/docs#throws
Comment #14
catchThis is still valid, we should start with addressing #5.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%...
Comment #15
mondrakeComment #16
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedNot able to apply patch given in #4, reroll needed.
Comment #17
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedFeedback from #5 addressed.
Comment #18
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedFixed PHPCBF issue.
Comment #19
mondrakeThe 'throw_exception' option is deprecated now, so I think we can just remove this piece.
I do not think we would ever throw a generic \Exception nowadays.
We can take from the comments in code and the exception messages and add here the occasion when the exceptions are thrown.
Comment #20
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedFeedback addressed mentioned in #19.
Please review.
Comment #21
paulocsFixing code standard.
Comment #22
daffie CreditAttribution: daffie commentedThe docblock looks good to me.
All the points of @mondrake are addressed.
For me it is RTBC.
Comment #23
mondrakeSorry to put it back, I read the actual code and have a couple more points.
Since
queryOptions['throw_exception']
is deprecated, I think it'd be better to reflect in the comment:Actually I think this is never thrown outside the method. This exception is used within the method to catch INSERT failures and in that case resolve to UPDATE instead.
Comment #24
guilhermevp CreditAttribution: guilhermevp at CI&T commentedComment #26
guilhermevp CreditAttribution: guilhermevp at CI&T commentedCreated a MR based on the feedback in #23, but I'm not exactly sure in what to do about
@throws \Drupal\Core\Database\IntegrityConstraintViolationException
, moving to NR for feedback.Comment #27
mondrake#26 just remove it. The purpose of listing the @throws in the docblock is to let developers know what exceptions they could expect to have to deal with. If its use is within the method, then this is not relevant.
Comment #28
guilhermevp CreditAttribution: guilhermevp at CI&T commentedThanks @mondrake!
Removed, please review!
Comment #29
mondrakeLooks good to me now, thanks!
Comment #30
mondrakeComment #33
catchCommitted/pushed to 9.3.x and cherry-picked to 9.2.x, thanks!