[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/ -> update.php (source)

   1  <?php
   2  
   3  /**
   4   * @file
   5   * Administrative page for handling updates from one Drupal version to another.
   6   *
   7   * Point your browser to "http://www.example.com/update.php" and follow the
   8   * instructions.
   9   *
  10   * If you are not logged in as administrator, you will need to modify the access
  11   * check statement inside your settings.php file. After finishing the upgrade,
  12   * be sure to open settings.php again, and change it back to its original state!
  13   */
  14  
  15  /**
  16   * Global flag to identify update.php run, and so avoid various unwanted
  17   * operations, such as hook_init() and hook_exit() invokes, css/js preprocessing
  18   * and translation, and solve some theming issues. This flag is checked on several
  19   * places in Drupal code (not just update.php).
  20   */
  21  define('MAINTENANCE_MODE', 'update');
  22  
  23  /**
  24   * Add a column to a database using syntax appropriate for PostgreSQL.
  25   * Save result of SQL commands in $ret array.
  26   *
  27   * Note: when you add a column with NOT NULL and you are not sure if there are
  28   * already rows in the table, you MUST also add DEFAULT. Otherwise PostgreSQL
  29   * won't work when the table is not empty, and db_add_column() will fail.
  30   * To have an empty string as the default, you must use: 'default' => "''"
  31   * in the $attributes array. If NOT NULL and DEFAULT are set the PostgreSQL
  32   * version will set values of the added column in old rows to the
  33   * DEFAULT value.
  34   *
  35   * @param $ret
  36   *   Array to which results will be added.
  37   * @param $table
  38   *   Name of the table, without {}
  39   * @param $column
  40   *   Name of the column
  41   * @param $type
  42   *   Type of column
  43   * @param $attributes
  44   *   Additional optional attributes. Recognized attributes:
  45   *     not null => TRUE|FALSE
  46   *     default  => NULL|FALSE|value (the value must be enclosed in '' marks)
  47   * @return
  48   *   nothing, but modifies $ret parameter.
  49   */
  50  function db_add_column(&$ret, $table, $column, $type, $attributes = array()) {
  51    if (array_key_exists('not null', $attributes) and $attributes['not null']) {
  52      $not_null = 'NOT NULL';
  53    }
  54    if (array_key_exists('default', $attributes)) {
  55      if (is_null($attributes['default'])) {
  56        $default_val = 'NULL';
  57        $default = 'default NULL';
  58      }
  59      elseif ($attributes['default'] === FALSE) {
  60        $default = '';
  61      }
  62      else {
  63        $default_val = "$attributes[default]";
  64        $default = "default $attributes[default]";
  65      }
  66    }
  67  
  68    $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column $type");
  69    if (!empty($default)) {
  70      $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET $default");
  71    }
  72    if (!empty($not_null)) {
  73      if (!empty($default)) {
  74        $ret[] = update_sql("UPDATE {". $table ."} SET $column = $default_val");
  75      }
  76      $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET NOT NULL");
  77    }
  78  }
  79  
  80  /**
  81   * Change a column definition using syntax appropriate for PostgreSQL.
  82   * Save result of SQL commands in $ret array.
  83   *
  84   * Remember that changing a column definition involves adding a new column
  85   * and dropping an old one. This means that any indices, primary keys and
  86   * sequences from serial-type columns are dropped and might need to be
  87   * recreated.
  88   *
  89   * @param $ret
  90   *   Array to which results will be added.
  91   * @param $table
  92   *   Name of the table, without {}
  93   * @param $column
  94   *   Name of the column to change
  95   * @param $column_new
  96   *   New name for the column (set to the same as $column if you don't want to change the name)
  97   * @param $type
  98   *   Type of column
  99   * @param $attributes
 100   *   Additional optional attributes. Recognized attributes:
 101   *     not null => TRUE|FALSE
 102   *     default  => NULL|FALSE|value (with or without '', it won't be added)
 103   * @return
 104   *   nothing, but modifies $ret parameter.
 105   */
 106  function db_change_column(&$ret, $table, $column, $column_new, $type, $attributes = array()) {
 107    if (array_key_exists('not null', $attributes) and $attributes['not null']) {
 108      $not_null = 'NOT NULL';
 109    }
 110    if (array_key_exists('default', $attributes)) {
 111      if (is_null($attributes['default'])) {
 112        $default_val = 'NULL';
 113        $default = 'default NULL';
 114      }
 115      elseif ($attributes['default'] === FALSE) {
 116        $default = '';
 117      }
 118      else {
 119        $default_val = "$attributes[default]";
 120        $default = "default $attributes[default]";
 121      }
 122    }
 123  
 124    $ret[] = update_sql("ALTER TABLE {". $table ."} RENAME $column TO ". $column ."_old");
 125    $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column_new $type");
 126    $ret[] = update_sql("UPDATE {". $table ."} SET $column_new = ". $column ."_old");
 127    if ($default) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET $default"); }
 128    if ($not_null) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET NOT NULL"); }
 129    $ret[] = update_sql("ALTER TABLE {". $table ."} DROP ". $column ."_old");
 130  }
 131  
 132  /**
 133   * Perform one update and store the results which will later be displayed on
 134   * the finished page.
 135   *
 136   * An update function can force the current and all later updates for this
 137   * module to abort by returning a $ret array with an element like:
 138   * $ret['#abort'] = array('success' => FALSE, 'query' => 'What went wrong');
 139   * The schema version will not be updated in this case, and all the
 140   * aborted updates will continue to appear on update.php as updates that
 141   * have not yet been run.
 142   *
 143   * @param $module
 144   *   The module whose update will be run.
 145   * @param $number
 146   *   The update number to run.
 147   * @param $context
 148   *   The batch context array
 149   */
 150  function update_do_one($module, $number, &$context) {
 151    // If updates for this module have been aborted
 152    // in a previous step, go no further.
 153    if (!empty($context['results'][$module]['#abort'])) {
 154      return;
 155    }
 156  
 157    $function = $module .'_update_'. $number;
 158    if (function_exists($function)) {
 159      $ret = $function($context['sandbox']);
 160    }
 161  
 162    if (isset($ret['#finished'])) {
 163      $context['finished'] = $ret['#finished'];
 164      unset($ret['#finished']);
 165    }
 166  
 167    if (!isset($context['results'][$module])) {
 168      $context['results'][$module] = array();
 169    }
 170    if (!isset($context['results'][$module][$number])) {
 171      $context['results'][$module][$number] = array();
 172    }
 173    $context['results'][$module][$number] = array_merge($context['results'][$module][$number], $ret);
 174  
 175    if (!empty($ret['#abort'])) {
 176      $context['results'][$module]['#abort'] = TRUE;
 177    }
 178    // Record the schema update if it was completed successfully.
 179    if ($context['finished'] == 1 && empty($context['results'][$module]['#abort'])) {
 180      drupal_set_installed_schema_version($module, $number);
 181    }
 182  
 183    $context['message'] = 'Updating '. check_plain($module) .' module';
 184  }
 185  
 186  function update_selection_page() {
 187    $output = '<p>The version of Drupal you are updating from has been automatically detected. You can select a different version, but you should not need to.</p>';
 188    $output .= '<p>Click Update to start the update process.</p>';
 189  
 190    drupal_set_title('Drupal database update');
 191    $output .= drupal_get_form('update_script_selection_form');
 192  
 193    update_task_list('select');
 194  
 195    return $output;
 196  }
 197  
 198  function update_script_selection_form() {
 199    $form = array();
 200    $form['start'] = array(
 201      '#tree' => TRUE,
 202      '#type' => 'fieldset',
 203      '#title' => 'Select versions',
 204      '#collapsible' => TRUE,
 205      '#collapsed' => TRUE,
 206    );
 207  
 208    // Ensure system.module's updates appear first
 209    $form['start']['system'] = array();
 210  
 211    $modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
 212    foreach ($modules as $module => $schema_version) {
 213      $updates = drupal_get_schema_versions($module);
 214      // Skip incompatible module updates completely, otherwise test schema versions.
 215      if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) {
 216        // module_invoke returns NULL for nonexisting hooks, so if no updates
 217        // are removed, it will == 0.
 218        $last_removed = module_invoke($module, 'update_last_removed');
 219        if ($schema_version < $last_removed) {
 220          $form['start'][$module] = array(
 221            '#value'  => '<em>'. $module .'</em> module can not be updated. Its schema version is '. $schema_version .'. Updates up to and including '. $last_removed .' have been removed in this release. In order to update <em>'. $module .'</em> module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.',
 222            '#prefix' => '<div class="warning">',
 223            '#suffix' => '</div>',
 224          );
 225          $form['start']['#collapsed'] = FALSE;
 226          continue;
 227        }
 228        $updates = drupal_map_assoc($updates);
 229        $updates[] = 'No updates available';
 230        $default = $schema_version;
 231        foreach (array_keys($updates) as $update) {
 232          if ($update > $schema_version) {
 233            $default = $update;
 234            break;
 235          }
 236        }
 237        $form['start'][$module] = array(
 238          '#type' => 'select',
 239          '#title' => $module .' module',
 240          '#default_value' => $default,
 241          '#options' => $updates,
 242        );
 243      }
 244    }
 245  
 246    $form['has_js'] = array(
 247      '#type' => 'hidden',
 248      '#default_value' => FALSE,
 249    );
 250    $form['submit'] = array(
 251      '#type' => 'submit',
 252      '#value' => 'Update',
 253    );
 254    return $form;
 255  }
 256  
 257  function update_batch() {
 258    global $base_url;
 259  
 260    $operations = array();
 261    // Set the installed version so updates start at the correct place.
 262    foreach ($_POST['start'] as $module => $version) {
 263      drupal_set_installed_schema_version($module, $version - 1);
 264      $updates = drupal_get_schema_versions($module);
 265      $max_version = max($updates);
 266      if ($version <= $max_version) {
 267        foreach ($updates as $update) {
 268          if ($update >= $version) {
 269            $operations[] = array('update_do_one', array($module, $update));
 270          }
 271        }
 272      }
 273    }
 274    $batch = array(
 275      'operations' => $operations,
 276      'title' => 'Updating',
 277      'init_message' => 'Starting updates',
 278      'error_message' => 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.',
 279      'finished' => 'update_finished',
 280    );
 281    batch_set($batch);
 282    batch_process($base_url .'/update.php?op=results', $base_url .'/update.php');
 283  }
 284  
 285  function update_finished($success, $results, $operations) {
 286    // clear the caches in case the data has been updated.
 287    drupal_flush_all_caches();
 288  
 289    $_SESSION['update_results'] = $results;
 290    $_SESSION['update_success'] = $success;
 291    $_SESSION['updates_remaining'] = $operations;
 292  }
 293  
 294  function update_results_page() {
 295    drupal_set_title('Drupal database update');
 296    // NOTE: we can't use l() here because the URL would point to 'update.php?q=admin'.
 297    $links[] = '<a href="'. base_path() .'">Main page</a>';
 298    $links[] = '<a href="'. base_path() .'?q=admin">Administration pages</a>';
 299  
 300    update_task_list();
 301    // Report end result
 302    if (module_exists('dblog')) {
 303      $log_message = ' All errors have been <a href="'. base_path() .'?q=admin/reports/dblog">logged</a>.';
 304    }
 305    else {
 306      $log_message = ' All errors have been logged.';
 307    }
 308  
 309    if ($_SESSION['update_success']) {
 310      $output = '<p>Updates were attempted. If you see no failures below, you may proceed happily to the <a href="'. base_path() .'?q=admin">administration pages</a>. Otherwise, you may need to update your database manually.'. $log_message .'</p>';
 311    }
 312    else {
 313      list($module, $version) = array_pop(reset($_SESSION['updates_remaining']));
 314      $output = '<p class="error">The update process was aborted prematurely while running <strong>update #'. $version .' in '. $module .'.module</strong>.'. $log_message;
 315      if (module_exists('dblog')) {
 316        $output .= ' You may need to check the <code>watchdog</code> database table manually.';
 317      }
 318      $output .= '</p>';
 319    }
 320  
 321    if (!empty($GLOBALS['update_free_access'])) {
 322      $output .= "<p><strong>Reminder: don't forget to set the <code>\$update_free_access</code> value in your <code>settings.php</code> file back to <code>FALSE</code>.</strong></p>";
 323    }
 324  
 325    $output .= theme('item_list', $links);
 326  
 327    // Output a list of queries executed
 328    if (!empty($_SESSION['update_results'])) {
 329      $output .= '<div id="update-results">';
 330      $output .= '<h2>The following queries were executed</h2>';
 331      foreach ($_SESSION['update_results'] as $module => $updates) {
 332        $output .= '<h3>'. $module .' module</h3>';
 333        foreach ($updates as $number => $queries) {
 334          if ($number != '#abort') {
 335            $output .= '<h4>Update #'. $number .'</h4>';
 336            $output .= '<ul>';
 337            foreach ($queries as $query) {
 338              if ($query['success']) {
 339                $output .= '<li class="success">'. $query['query'] .'</li>';
 340              }
 341              else {
 342                $output .= '<li class="failure"><strong>Failed:</strong> '. $query['query'] .'</li>';
 343              }
 344            }
 345            if (!count($queries)) {
 346              $output .= '<li class="none">No queries</li>';
 347            }
 348            $output .= '</ul>';
 349          }
 350        }
 351      }
 352      $output .= '</div>';
 353    }
 354    unset($_SESSION['update_results']);
 355    unset($_SESSION['update_success']);
 356  
 357    return $output;
 358  }
 359  
 360  function update_info_page() {
 361    // Change query-strings on css/js files to enforce reload for all users.
 362    _drupal_flush_css_js();
 363    // Flush the cache of all data for the update status module.
 364    if (db_table_exists('cache_update')) {
 365      cache_clear_all('*', 'cache_update', TRUE);
 366    }
 367  
 368    update_task_list('info');
 369    drupal_set_title('Drupal database update');
 370    $token = drupal_get_token('update');
 371    $output = '<p>Use this utility to update your database whenever a new release of Drupal or a module is installed.</p><p>For more detailed information, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>';
 372    $output .= "<ol>\n";
 373    $output .= "<li><strong>Back up your database</strong>. This process will change your database values and in case of emergency you may need to revert to a backup.</li>\n";
 374    $output .= "<li><strong>Back up your code</strong>. Hint: when backing up module code, do not leave that backup in the 'modules' or 'sites/*/modules' directories as this may confuse Drupal's auto-discovery mechanism.</li>\n";
 375    $output .= '<li>Put your site into <a href="'. base_path() .'?q=admin/settings/site-maintenance">maintenance mode</a>.</li>'."\n";
 376    $output .= "<li>Install your new files in the appropriate location, as described in the handbook.</li>\n";
 377    $output .= "</ol>\n";
 378    $output .= "<p>When you have performed the steps above, you may proceed.</p>\n";
 379    $output .= '<form method="post" action="update.php?op=selection&amp;token='. $token .'"><p><input type="submit" value="Continue" /></p></form>';
 380    $output .= "\n";
 381    return $output;
 382  }
 383  
 384  function update_access_denied_page() {
 385    drupal_set_title('Access denied');
 386    return '<p>Access denied. You are not authorized to access this page. Please log in as the admin user (the first user you created). If you cannot log in, you will have to edit <code>settings.php</code> to bypass this access check. To do this:</p>
 387  <ol>
 388   <li>With a text editor find the settings.php file on your system. From the main Drupal directory that you installed all the files into, go to <code>sites/your_site_name</code> if such directory exists, or else to <code>sites/default</code> which applies otherwise.</li>
 389   <li>There is a line inside your settings.php file that says <code>$update_free_access = FALSE;</code>. Change it to <code>$update_free_access = TRUE;</code>.</li>
 390   <li>As soon as the update.php script is done, you must change the settings.php file back to its original form with <code>$update_free_access = FALSE;</code>.</li>
 391   <li>To avoid having this problem in future, remember to log in to your website as the admin user (the user you first created) before you backup your database at the beginning of the update process.</li>
 392  </ol>';
 393  }
 394  
 395  /**
 396   * Create the batch table.
 397   *
 398   * This is part of the Drupal 5.x to 6.x migration.
 399   */
 400  function update_create_batch_table() {
 401  
 402    // If batch table exists, update is not necessary
 403    if (db_table_exists('batch')) {
 404      return;
 405    }
 406  
 407    $schema['batch'] = array(
 408      'fields' => array(
 409        'bid'       => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
 410        'token'     => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE),
 411        'timestamp' => array('type' => 'int', 'not null' => TRUE),
 412        'batch'     => array('type' => 'text', 'not null' => FALSE, 'size' => 'big')
 413      ),
 414      'primary key' => array('bid'),
 415      'indexes' => array('token' => array('token')),
 416    );
 417  
 418    $ret = array();
 419    db_create_table($ret, 'batch', $schema['batch']);
 420    return $ret;
 421  }
 422  
 423  /**
 424   * Disable anything in the {system} table that is not compatible with the
 425   * current version of Drupal core.
 426   */
 427  function update_fix_compatibility() {
 428    $ret = array();
 429    $incompatible = array();
 430    $query = db_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')");
 431    while ($result = db_fetch_object($query)) {
 432      if (update_check_incompatibility($result->name, $result->type)) {
 433        $incompatible[] = $result->name;
 434      }
 435    }
 436    if (!empty($incompatible)) {
 437      $ret[] = update_sql("UPDATE {system} SET status = 0 WHERE name IN ('". implode("','", $incompatible) ."')");
 438    }
 439    return $ret;
 440  }
 441  
 442  /**
 443   * Helper function to test compatibility of a module or theme.
 444   */
 445  function update_check_incompatibility($name, $type = 'module') {
 446    static $themes, $modules;
 447  
 448    // Store values of expensive functions for future use.
 449    if (empty($themes) || empty($modules)) {
 450      $themes = _system_theme_data();
 451      $modules = module_rebuild_cache();
 452    }
 453  
 454    if ($type == 'module' && isset($modules[$name])) {
 455      $file = $modules[$name];
 456    }
 457    else if ($type == 'theme' && isset($themes[$name])) {
 458      $file = $themes[$name];
 459    }
 460    if (!isset($file)
 461        || !isset($file->info['core'])
 462        || $file->info['core'] != DRUPAL_CORE_COMPATIBILITY
 463        || version_compare(phpversion(), $file->info['php']) < 0) {
 464      return TRUE;
 465    }
 466    return FALSE;
 467  }
 468  
 469  /**
 470   * Perform Drupal 5.x to 6.x updates that are required for update.php
 471   * to function properly.
 472   *
 473   * This function runs when update.php is run the first time for 6.x,
 474   * even before updates are selected or performed.  It is important
 475   * that if updates are not ultimately performed that no changes are
 476   * made which make it impossible to continue using the prior version.
 477   * Just adding columns is safe.  However, renaming the
 478   * system.description column to owner is not.  Therefore, we add the
 479   * system.owner column and leave it to system_update_6008() to copy
 480   * the data from description and remove description. The same for
 481   * renaming locales_target.locale to locales_target.language, which
 482   * will be finished by locale_update_6002().
 483   */
 484  function update_fix_d6_requirements() {
 485    $ret = array();
 486  
 487    if (drupal_get_installed_schema_version('system') < 6000 && !variable_get('update_d6_requirements', FALSE)) {
 488      $spec = array('type' => 'int', 'size' => 'small', 'default' => 0, 'not null' => TRUE);
 489      db_add_field($ret, 'cache', 'serialized', $spec);
 490      db_add_field($ret, 'cache_filter', 'serialized', $spec);
 491      db_add_field($ret, 'cache_page', 'serialized', $spec);
 492      db_add_field($ret, 'cache_menu', 'serialized', $spec);
 493  
 494      db_add_field($ret, 'system', 'info', array('type' => 'text'));
 495      db_add_field($ret, 'system', 'owner', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
 496      if (db_table_exists('locales_target')) {
 497        db_add_field($ret, 'locales_target', 'language', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
 498      }
 499      if (db_table_exists('locales_source')) {
 500        db_add_field($ret, 'locales_source', 'textgroup', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'default'));
 501        db_add_field($ret, 'locales_source', 'version', array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'none'));
 502      }
 503      variable_set('update_d6_requirements', TRUE);
 504  
 505      // Create the cache_block table. See system_update_6027() for more details.
 506      $schema['cache_block'] = array(
 507        'fields' => array(
 508          'cid'        => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
 509          'data'       => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
 510          'expire'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
 511          'created'    => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
 512          'headers'    => array('type' => 'text', 'not null' => FALSE),
 513          'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
 514        ),
 515        'indexes' => array('expire' => array('expire')),
 516        'primary key' => array('cid'),
 517      );
 518      db_create_table($ret, 'cache_block', $schema['cache_block']);
 519  
 520      // Create the semaphore table now -- the menu system after 6.15 depends on
 521      // this table, and menu code runs in updates prior to the table being
 522      // created in its original update function, system_update_6054().
 523      $schema['semaphore'] = array(
 524        'fields' => array(
 525          'name' => array(
 526            'type' => 'varchar',
 527            'length' => 255,
 528            'not null' => TRUE,
 529            'default' => ''),
 530          'value' => array(
 531            'type' => 'varchar',
 532            'length' => 255,
 533            'not null' => TRUE,
 534            'default' => ''),
 535          'expire' => array(
 536            'type' => 'float',
 537            'size' => 'big',
 538            'not null' => TRUE),
 539          ),
 540        'indexes' => array('expire' => array('expire')),
 541        'primary key' => array('name'),
 542      );
 543      db_create_table($ret, 'semaphore', $schema['semaphore']);
 544    }
 545  
 546    return $ret;
 547  }
 548  
 549  /**
 550   * Add the update task list to the current page.
 551   */
 552  function update_task_list($active = NULL) {
 553    // Default list of tasks.
 554    $tasks = array(
 555      'info' => 'Overview',
 556      'select' => 'Select updates',
 557      'run' => 'Run updates',
 558      'finished' => 'Review log',
 559    );
 560  
 561    drupal_set_content('left', theme('task_list', $tasks, $active));
 562  }
 563  
 564  /**
 565   * Check update requirements and report any errors.
 566   */
 567  function update_check_requirements() {
 568    // Check the system module requirements only.
 569    $requirements = module_invoke('system', 'requirements', 'update');
 570    $severity = drupal_requirements_severity($requirements);
 571  
 572    // If there are issues, report them.
 573    if ($severity != REQUIREMENT_OK) {
 574      foreach ($requirements as $requirement) {
 575        if (isset($requirement['severity']) && $requirement['severity'] != REQUIREMENT_OK) {
 576          $message = isset($requirement['description']) ? $requirement['description'] : '';
 577          if (isset($requirement['value']) && $requirement['value']) {
 578            $message .= ' (Currently using '. $requirement['title'] .' '. $requirement['value'] .')';
 579          }
 580          drupal_set_message($message, 'warning');
 581        }
 582      }
 583    }
 584  }
 585  
 586  // Some unavoidable errors happen because the database is not yet up-to-date.
 587  // Our custom error handler is not yet installed, so we just suppress them.
 588  ini_set('display_errors', FALSE);
 589  
 590  require_once  './includes/bootstrap.inc';
 591  
 592  // We only load DRUPAL_BOOTSTRAP_CONFIGURATION for the update requirements
 593  // check to avoid reaching the PHP memory limit.
 594  $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
 595  if (empty($op)) {
 596    // Minimum load of components.
 597    drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
 598  
 599    require_once  './includes/install.inc';
 600    require_once  './includes/file.inc';
 601    require_once  './modules/system/system.install';
 602  
 603    // Load module basics.
 604    include_once  './includes/module.inc';
 605    $module_list['system']['filename'] = 'modules/system/system.module';
 606    $module_list['filter']['filename'] = 'modules/filter/filter.module';
 607    module_list(TRUE, FALSE, FALSE, $module_list);
 608    drupal_load('module', 'system');
 609    drupal_load('module', 'filter');
 610  
 611    // Set up $language, since the installer components require it.
 612    drupal_init_language();
 613  
 614    // Set up theme system for the maintenance page.
 615    drupal_maintenance_theme();
 616  
 617    // Check the update requirements for Drupal.
 618    update_check_requirements();
 619  
 620    // Display the warning messages (if any) in a dedicated maintenance page,
 621    // or redirect to the update information page if no message.
 622    $messages = drupal_set_message();
 623    if (!empty($messages['warning'])) {
 624      drupal_maintenance_theme();
 625      print theme('update_page', '<form method="post" action="update.php?op=info"><input type="submit" value="Continue" /></form>', FALSE);
 626      exit;
 627    }
 628    install_goto('update.php?op=info');
 629  }
 630  
 631  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 632  drupal_maintenance_theme();
 633  
 634  // This must happen *after* drupal_bootstrap(), since it calls
 635  // variable_(get|set), which only works after a full bootstrap.
 636  update_create_batch_table();
 637  
 638  // Turn error reporting back on. From now on, only fatal errors (which are
 639  // not passed through the error handler) will cause a message to be printed.
 640  ini_set('display_errors', TRUE);
 641  
 642  // Access check:
 643  if (!empty($update_free_access) || $user->uid == 1) {
 644  
 645    include_once  './includes/install.inc';
 646    include_once  './includes/batch.inc';
 647    drupal_load_updates();
 648  
 649    update_fix_d6_requirements();
 650    update_fix_compatibility();
 651  
 652    $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
 653    switch ($op) {
 654      case 'selection':
 655        if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) {
 656          $output = update_selection_page();
 657          break;
 658        }
 659  
 660      case 'Update':
 661        if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) {
 662          update_batch();
 663          break;
 664        }
 665  
 666      // update.php ops
 667      case 'info':
 668        $output = update_info_page();
 669        break;
 670  
 671      case 'results':
 672        $output = update_results_page();
 673        break;
 674  
 675      // Regular batch ops : defer to batch processing API
 676      default:
 677        update_task_list('run');
 678        $output = _batch_page();
 679        break;
 680    }
 681  }
 682  else {
 683    $output = update_access_denied_page();
 684  }
 685  if (isset($output) && $output) {
 686    // We defer the display of messages until all updates are done.
 687    $progress_page = ($batch = batch_get()) && isset($batch['running']);
 688    print theme('update_page', $output, !$progress_page);
 689  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7