Problem/Motivation
This is a small issue of the documentation for the core batch system.
The sample function of batch-finished callback is defined with three parameters.
Sample callback_batch_finished():
function my_finished_callback($success, $results, $operations) {
https://api.drupal.org/api/drupal/core%21includes%21form.inc/group/batch...
But actually four parameters are passed to batch-finished callbacks as below.
function _batch_finished() {
// ...
$batch_set_result = call_user_func_array($batch_set['finished'], [$batch_set['success'], $batch_set['results'], $operations, \Drupal::service('date.formatter')->formatInterval($batch_set['elapsed'] / 1000)]);
// ...
}
https://api.drupal.org/api/drupal/core%21includes%21batch.inc/function/_...
The fourth parameter which stores a string for elapsed time is passed to the callback function but not documented there.
Proposed resolution
Add the fourth parameter to the document.
In addition, I'd like to add the parameter to callback functions for tests in batch_test module.
Remaining tasks
- Create patch
- Review patch
User interface changes
(None)
API changes
(None)
Data model changes
(None)
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | 2939645-27.patch | 10.68 KB | jungle |
| #27 | interdiff-25-27.txt | 727 bytes | jungle |
Comments
Comment #2
hgoto commentedHere's a simple patch.
Comment #3
hgoto commentedI believe this is also the case for D7.
https://api.drupal.org/api/drupal/includes%21form.inc/group/batch/7.x
Comment #4
john cook commentedThanks for the patch @hgoto.
There are a couple of points.
The calls to
_batch_test_finished_helper()have been changed to add the$elapsedparameter, but the function specification hasn't been updated to receive it (incore/modules/system/tests/modules/batch_test/batch_test.callbacks.incline 90).Also
callback_batch_finished()(incore/lib/Drupal/Core/Form/form.api.php) should be updated to include the$elapsedparameter and the code comment updated.Comment #5
hgoto commentedJohn, thanks for your kind review.
> but the function specification hasn't been updated to receive it (in
core/modules/system/tests/modules/batch_test/batch_test.callbacks.incline 90).I didn't think it's important to change the behavior when I made the patch, but I agree with you. It's better to use the
$elapsedin the function.I adjusted the points you pointed. And we need to update some tests with this change and I update them, too.
Comment #6
hgoto commentedOops. I didn't update any file in the previous comment.
Comment #8
john cook commentedThe patch in #6 look great. Both points from #4 have been addressed.
It just needs a re-roll and then I think it will be ready for RTBC.
Comment #9
kostyashupenkoreroll + fix
Comment #10
john cook commentedThe re-rolled patch applied cleanly and look good.
A
drupal_set_message()was changed to\Drupal::messenger()->addMessage()but that was just changing deprecated code.I'm happy with this so changing to RTBC.
Comment #12
alexpottI've read the docs of
_batch_finished()they don;t seem to be helpful. How about pointing tocallback_batch_finished()as those are helpful.This could do with an example - eg.
1 min 30 sec. Also this should be@param string $elapsedcode do with a comment explaining the looseness of the regex is to cope with variable amounts of elapsed time.
Comment #13
dhirendra.mishra commentedWe will work in ContributionWeekend2019
Comment #14
dhirendra.mishra commentedHere is the patch.
Comment #15
john cook commented@dhirendra.mishra, thank you for the patch.
In future can you add an interdiff when you create a new patch - I helps with reviewing the patch. I've added an interdiff for 9 to 14.
Following on from @alexpott's comments in #12, there are still a few changes needed.
There is a spelling mistake in "parameters".
The comment now goes beyond 80 characters - although it wouldn't if the code was pasted as a function. I'm not not sure of the standards for this maybe @alexpott can advise?
Examples are still missing as requested by @alexpott in #12 point 2.
The comment should be an explanation of what the regex does. Something like
The elapsed time should be either in minutes and seconds or seconds alone.Could the elapsed time be in multiple minutes (like "2 mins 10 secs")? Do the parts get pluralised (adding 's')? Would the regex match in these cases?
Comment #16
dhirendra.mishra commentedi will work on your comment. Thanks @John Cook
Comment #17
dhirendra.mishra commentedHere is the interdiff and updated patch as per #15 comment.
Comment #18
john cook commentedThanks for the new patch and interdiff, @ dhirendra.mishra
All the points from #15 have been addressed.
But applying the patch gives the following error:
This seems to be a coding standards error.
The next step is to check the coding standards error. These can be viewed on the test results page (click the green/gray/red element near the patch file) and there will be a coding standards messages link.
Comment #19
govind.maloo commentedFixed trailing space issue.
Comment #20
john cook commentedThank you for the patch @govind.maloo.
The only change between patches #17 and #19 is the removal of white space. and patch #19 applies cleanly.
As the issues pointed out in previous comments are also fixed, I'm setting this issue to RTBC.
Comment #21
gábor hojtsyThis review point from @alexpott was not covered AFAIS, however it looks important to avoid random fails.
Comment #24
quietone commentedReroll and modify the regex pattern mentioned in #21.
Comment #25
quietone commentedThere are two versions of e.g. instead of one.
Comment #27
jungle#12.1 addressed
#12.2 addressed. BUT, I think it should be
30 secs.Suggestion:
Do not separate 1 min and 30 sec(s) due to over 80 chars. Instead, treat them together as ONE, surrounding with single quotes, stays at the 2nd line. Neither over chars, nor wrapped early.
Addressed #12.3, and the reg looks good.
In all, this is RTBC to me.
Comment #28
alexpottCommitted and pushed 7ca98bac22 to 9.1.x and 28c8fbe32e to 9.0.x. Thanks!