Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This might not happen a lot but when I was doing a batch process with issues, I received the error Notice: Undefined variable: label in _batch_process().
There is a case that the $label variable will not get set.
Comments
Comment #2
albertski CreditAttribution: albertski at Xeno Media, Inc. commentedThe following patch fixes the issue by setting $label to blank by default.
Comment #3
longwaveA bit confused about the difference between $task_message and $label in this function, as they appear to basically be the same thing? It feels like this whole function needs a refactor as it is quite confusing to follow.
But, this is a simple fix, so RTBC.
Comment #4
alexpottAs we're not adding a test I'd rather do something that eliminates the
$label
. It is essential useless. We could initialise $task_message outside the first while loop and re-initialise it in the loop too and that way we can remove label and have no conditionality to test.Comment #5
alexpottAlso an update to the _batch_process return value would be great so we know what this is and that it should be there.
Comment #6
albertski CreditAttribution: albertski at Xeno Media, Inc. commentedGood point @alexpott.
Comment #7
alexpottI'm not sure that this removal is correct - I think the purposed is to reinitialize the variable for each loop. I'd leave
$task_message = '';
otherwise we'll be changing the inputs toComment #8
albertski CreditAttribution: albertski at Xeno Media, Inc. commentedMade the change.
Comment #9
longwaveWe still need to initialise it outside the loop, in case the loop is never entered.
Comment #10
dhirendra.mishra CreditAttribution: dhirendra.mishra at Srijan | A Material+ Company commentedThanks for update. Updated the correct patch with variable initialized out of loop.
Comment #11
albertski CreditAttribution: albertski at Xeno Media, Inc. commentedUpdated the patch to initialize outside the loop and inside the loop.
Comment #12
longwave#11 looks good, thanks.
Comment #13
catchCommitted f159bbd and pushed to 8.7.x. Thanks!