Problem/Motivation
The documentation of hook_update_N() says:
The system will stop iterating this update when $sandbox['#finished'] is left unset or set to a number higher than 1.
This is only kind of true because
- Iteration also stops if $sandbox['#finished'] == 1
- The update process is properly closed only if $sandbox['#finished'] == 1 since in update_do_one() we have:
// Record the schema update if it was completed successfully.
if ($context['finished'] == 1 && empty($ret['#abort'])) {
drupal_set_installed_schema_version($module, $number);
}
which means if $sandbox['#finished'] is > 1 then the schema_version for the module won't be updated (even if the updates run successfully).
Proposed resolution
Since
- according to the documentation 'finished' values > 1 are already allowed and
- the batch API does not differentiate between 1 and >1 'finished' values
I think hook_update_N() should not differentiate between 1 and >1 'finished' values either.
Remaining tasks
Review patch.
API changes
Comments
Comment #1
czigor commentedComment #2
czigor commentedComment #3
czigor commentedComment #4
joachim commentedStill a bug on 8.3.x.
Comment #5
chanderbhushan commentedHi,
Added patch for 8.3.x.
thanks
Comment #6
chanderbhushan commentedComment #16
quietone commentedThis was fixed in 2015 in #2521776: Update documentation for hook_update_N() for Drupal 8. But this is still applicable to Drupal 7. Therefor changing version.
Thanks!
Comment #17
poker10 commentedThanks for working on this.
The patch #1 needs work. We should remove this change, as it was never committed to D8+ and D10 code still has the original code:
And then we need to compare and verify, if the comment changes are correct per #2521776: Update documentation for hook_update_N() for Drupal 8 (just for the relevant parts). Thanks!