function update_do_one

Same name and namespace in other branches
  1. 11.x core/includes/update.inc \update_do_one()
  2. 10 core/includes/update.inc \update_do_one()
  3. 9 core/includes/update.inc \update_do_one()
  4. 8.9.x core/includes/update.inc \update_do_one()
  5. 7.x includes/update.inc \update_do_one()

Implements callback_batch_operation().

Performs one update and stores the results for display on the results page.

If an update function completes successfully, it should return a message as a string indicating success, for example:

return t('New index added successfully.');

Alternatively, it may return nothing. In that case, no message will be displayed at all.

If it fails for whatever reason, it should throw an instance of Drupal\Core\Utility\UpdateException with an appropriate error message, for example:

use Drupal\Core\Utility\UpdateException;
throw new UpdateException('Description of what went wrong');

If an exception is thrown, the current update and all updates that depend on it will be aborted. The schema version will not be updated in this case, and all the aborted updates will continue to appear on update.php as updates that have not yet been run.

If an update function needs to be re-run as part of a batch process, it should accept the $sandbox array by reference as its first parameter and set the #finished property to the percentage completed that it is, as a fraction of 1.

Parameters

string $module: The module whose update will be run.

string $number: The update number to run.

array $dependency_map: An array whose keys are the names of all update functions that will be performed during this batch process, and whose values are arrays of other update functions that each one depends on.

array $context: The batch context array.

Deprecated

in drupal:11.5.0 and is removed from drupal:13.0.0. Use \Drupal::service(DatabaseUpdate::class)->doOne() instead.

See also

https://www.drupal.org/node/3013060

\Drupal\Core\Update\DatabaseUpdate::doOne()

update_resolve_dependencies()

File

core/includes/update.inc, line 115

Code

function update_do_one($module, $number, $dependency_map, &$context) : void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use \\Drupal::service(DatabaseUpdate::class)->doOne() instead. See https://www.drupal.org/node/3013060', E_USER_DEPRECATED);
  \Drupal::service(DatabaseUpdate::class)->doOne($module, (int) $number, $dependency_map, $context);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.