You are here

function update_do_one in Drupal 6

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

Perform one update and store the results which will later be displayed on the finished page.

An update function can force the current and all later updates for this module to abort by returning a $ret array with an element like: $ret['#abort'] = array('success' => FALSE, 'query' => 'What went wrong'); 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.

Parameters

$module: The module whose update will be run.

$number: The update number to run.

$context: The batch context array

1 string reference to 'update_do_one'
update_batch in ./update.php

File

./update.php, line 150
Administrative page for handling updates from one Drupal version to another.

Code

function update_do_one($module, $number, &$context) {

  // If updates for this module have been aborted
  // in a previous step, go no further.
  if (!empty($context['results'][$module]['#abort'])) {
    return;
  }
  $function = $module . '_update_' . $number;
  if (function_exists($function)) {
    $ret = $function($context['sandbox']);
  }
  if (isset($ret['#finished'])) {
    $context['finished'] = $ret['#finished'];
    unset($ret['#finished']);
  }
  if (!isset($context['results'][$module])) {
    $context['results'][$module] = array();
  }
  if (!isset($context['results'][$module][$number])) {
    $context['results'][$module][$number] = array();
  }
  $context['results'][$module][$number] = array_merge($context['results'][$module][$number], $ret);
  if (!empty($ret['#abort'])) {
    $context['results'][$module]['#abort'] = TRUE;
  }

  // Record the schema update if it was completed successfully.
  if ($context['finished'] == 1 && empty($context['results'][$module]['#abort'])) {
    drupal_set_installed_schema_version($module, $number);
  }
  $context['message'] = 'Updating ' . check_plain($module) . ' module';
}