webmaster@1: "''"
webmaster@1: * in the $attributes array. If NOT NULL and DEFAULT are set the PostgreSQL
webmaster@1: * version will set values of the added column in old rows to the
webmaster@1: * DEFAULT value.
webmaster@1: *
webmaster@1: * @param $ret
webmaster@1: * Array to which results will be added.
webmaster@1: * @param $table
webmaster@1: * Name of the table, without {}
webmaster@1: * @param $column
webmaster@1: * Name of the column
webmaster@1: * @param $type
webmaster@1: * Type of column
webmaster@1: * @param $attributes
webmaster@1: * Additional optional attributes. Recognized attributes:
webmaster@1: * not null => TRUE|FALSE
webmaster@1: * default => NULL|FALSE|value (the value must be enclosed in '' marks)
webmaster@1: * @return
webmaster@1: * nothing, but modifies $ret parameter.
webmaster@1: */
webmaster@1: function db_add_column(&$ret, $table, $column, $type, $attributes = array()) {
webmaster@1: if (array_key_exists('not null', $attributes) and $attributes['not null']) {
webmaster@1: $not_null = 'NOT NULL';
webmaster@1: }
webmaster@1: if (array_key_exists('default', $attributes)) {
webmaster@1: if (is_null($attributes['default'])) {
webmaster@1: $default_val = 'NULL';
webmaster@1: $default = 'default NULL';
webmaster@1: }
webmaster@1: elseif ($attributes['default'] === FALSE) {
webmaster@1: $default = '';
webmaster@1: }
webmaster@1: else {
webmaster@1: $default_val = "$attributes[default]";
webmaster@1: $default = "default $attributes[default]";
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column $type");
webmaster@1: if (!empty($default)) {
webmaster@1: $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET $default");
webmaster@1: }
webmaster@1: if (!empty($not_null)) {
webmaster@1: if (!empty($default)) {
webmaster@1: $ret[] = update_sql("UPDATE {". $table ."} SET $column = $default_val");
webmaster@1: }
webmaster@1: $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET NOT NULL");
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Change a column definition using syntax appropriate for PostgreSQL.
webmaster@1: * Save result of SQL commands in $ret array.
webmaster@1: *
webmaster@1: * Remember that changing a column definition involves adding a new column
webmaster@1: * and dropping an old one. This means that any indices, primary keys and
webmaster@1: * sequences from serial-type columns are dropped and might need to be
webmaster@1: * recreated.
webmaster@1: *
webmaster@1: * @param $ret
webmaster@1: * Array to which results will be added.
webmaster@1: * @param $table
webmaster@1: * Name of the table, without {}
webmaster@1: * @param $column
webmaster@1: * Name of the column to change
webmaster@1: * @param $column_new
webmaster@1: * New name for the column (set to the same as $column if you don't want to change the name)
webmaster@1: * @param $type
webmaster@1: * Type of column
webmaster@1: * @param $attributes
webmaster@1: * Additional optional attributes. Recognized attributes:
webmaster@1: * not null => TRUE|FALSE
webmaster@1: * default => NULL|FALSE|value (with or without '', it won't be added)
webmaster@1: * @return
webmaster@1: * nothing, but modifies $ret parameter.
webmaster@1: */
webmaster@1: function db_change_column(&$ret, $table, $column, $column_new, $type, $attributes = array()) {
webmaster@1: if (array_key_exists('not null', $attributes) and $attributes['not null']) {
webmaster@1: $not_null = 'NOT NULL';
webmaster@1: }
webmaster@1: if (array_key_exists('default', $attributes)) {
webmaster@1: if (is_null($attributes['default'])) {
webmaster@1: $default_val = 'NULL';
webmaster@1: $default = 'default NULL';
webmaster@1: }
webmaster@1: elseif ($attributes['default'] === FALSE) {
webmaster@1: $default = '';
webmaster@1: }
webmaster@1: else {
webmaster@1: $default_val = "$attributes[default]";
webmaster@1: $default = "default $attributes[default]";
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: $ret[] = update_sql("ALTER TABLE {". $table ."} RENAME $column TO ". $column ."_old");
webmaster@1: $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column_new $type");
webmaster@1: $ret[] = update_sql("UPDATE {". $table ."} SET $column_new = ". $column ."_old");
webmaster@1: if ($default) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET $default"); }
webmaster@1: if ($not_null) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET NOT NULL"); }
webmaster@1: $ret[] = update_sql("ALTER TABLE {". $table ."} DROP ". $column ."_old");
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Perform one update and store the results which will later be displayed on
webmaster@1: * the finished page.
webmaster@1: *
webmaster@1: * An update function can force the current and all later updates for this
webmaster@1: * module to abort by returning a $ret array with an element like:
webmaster@1: * $ret['#abort'] = array('success' => FALSE, 'query' => 'What went wrong');
webmaster@1: * The schema version will not be updated in this case, and all the
webmaster@1: * aborted updates will continue to appear on update.php as updates that
webmaster@1: * have not yet been run.
webmaster@1: *
webmaster@1: * @param $module
webmaster@1: * The module whose update will be run.
webmaster@1: * @param $number
webmaster@1: * The update number to run.
webmaster@1: * @param $context
webmaster@1: * The batch context array
webmaster@1: */
webmaster@1: function update_do_one($module, $number, &$context) {
webmaster@1: // If updates for this module have been aborted
webmaster@1: // in a previous step, go no further.
webmaster@1: if (!empty($context['results'][$module]['#abort'])) {
webmaster@1: return;
webmaster@1: }
webmaster@1:
webmaster@1: $function = $module .'_update_'. $number;
webmaster@1: if (function_exists($function)) {
webmaster@1: $ret = $function($context['sandbox']);
webmaster@1: }
webmaster@1:
webmaster@1: if (isset($ret['#finished'])) {
webmaster@1: $context['finished'] = $ret['#finished'];
webmaster@1: unset($ret['#finished']);
webmaster@1: }
webmaster@1:
webmaster@1: if (!isset($context['results'][$module])) {
webmaster@1: $context['results'][$module] = array();
webmaster@1: }
webmaster@1: if (!isset($context['results'][$module][$number])) {
webmaster@1: $context['results'][$module][$number] = array();
webmaster@1: }
webmaster@1: $context['results'][$module][$number] = array_merge($context['results'][$module][$number], $ret);
webmaster@1:
webmaster@1: if (!empty($ret['#abort'])) {
webmaster@1: $context['results'][$module]['#abort'] = TRUE;
webmaster@1: }
webmaster@1: // Record the schema update if it was completed successfully.
webmaster@1: if ($context['finished'] == 1 && empty($context['results'][$module]['#abort'])) {
webmaster@1: drupal_set_installed_schema_version($module, $number);
webmaster@1: }
webmaster@1:
webmaster@1: $context['message'] = 'Updating '. check_plain($module) .' module';
webmaster@1: }
webmaster@1:
webmaster@1: function update_selection_page() {
webmaster@1: $output = '
The version of Drupal you are updating from has been automatically detected. You can select a different version, but you should not need to.
';
webmaster@1: $output .= 'Click Update to start the update process.
';
webmaster@1:
webmaster@1: drupal_set_title('Drupal database update');
webmaster@1: $output .= drupal_get_form('update_script_selection_form');
webmaster@1:
webmaster@1: update_task_list('select');
webmaster@1:
webmaster@1: return $output;
webmaster@1: }
webmaster@1:
webmaster@1: function update_script_selection_form() {
webmaster@1: $form = array();
webmaster@1: $form['start'] = array(
webmaster@1: '#tree' => TRUE,
webmaster@1: '#type' => 'fieldset',
webmaster@1: '#title' => 'Select versions',
webmaster@1: '#collapsible' => TRUE,
webmaster@1: '#collapsed' => TRUE,
webmaster@1: );
webmaster@1:
webmaster@1: // Ensure system.module's updates appear first
webmaster@1: $form['start']['system'] = array();
webmaster@1:
webmaster@1: $modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
webmaster@1: foreach ($modules as $module => $schema_version) {
webmaster@1: $updates = drupal_get_schema_versions($module);
webmaster@1: // Skip incompatible module updates completely, otherwise test schema versions.
webmaster@1: if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) {
webmaster@1: // module_invoke returns NULL for nonexisting hooks, so if no updates
webmaster@1: // are removed, it will == 0.
webmaster@1: $last_removed = module_invoke($module, 'update_last_removed');
webmaster@1: if ($schema_version < $last_removed) {
webmaster@1: $form['start'][$module] = array(
webmaster@1: '#value' => ''. $module .' 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 '. $module .' module, you will first need to upgrade to the last version in which these updates were available.',
webmaster@1: '#prefix' => '',
webmaster@1: '#suffix' => '
',
webmaster@1: );
webmaster@1: $form['start']['#collapsed'] = FALSE;
webmaster@1: continue;
webmaster@1: }
webmaster@1: $updates = drupal_map_assoc($updates);
webmaster@1: $updates[] = 'No updates available';
webmaster@1: $default = $schema_version;
webmaster@1: foreach (array_keys($updates) as $update) {
webmaster@1: if ($update > $schema_version) {
webmaster@1: $default = $update;
webmaster@1: break;
webmaster@1: }
webmaster@1: }
webmaster@1: $form['start'][$module] = array(
webmaster@1: '#type' => 'select',
webmaster@1: '#title' => $module .' module',
webmaster@1: '#default_value' => $default,
webmaster@1: '#options' => $updates,
webmaster@1: );
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: $form['has_js'] = array(
webmaster@1: '#type' => 'hidden',
webmaster@1: '#default_value' => FALSE,
webmaster@1: '#attributes' => array('id' => 'edit-has_js'),
webmaster@1: );
webmaster@1: $form['submit'] = array(
webmaster@1: '#type' => 'submit',
webmaster@1: '#value' => 'Update',
webmaster@1: );
webmaster@1: return $form;
webmaster@1: }
webmaster@1:
webmaster@1: function update_batch() {
webmaster@1: global $base_url;
webmaster@1:
webmaster@1: $operations = array();
webmaster@1: // Set the installed version so updates start at the correct place.
webmaster@1: foreach ($_POST['start'] as $module => $version) {
webmaster@1: drupal_set_installed_schema_version($module, $version - 1);
webmaster@1: $updates = drupal_get_schema_versions($module);
webmaster@1: $max_version = max($updates);
webmaster@1: if ($version <= $max_version) {
webmaster@1: foreach ($updates as $update) {
webmaster@1: if ($update >= $version) {
webmaster@1: $operations[] = array('update_do_one', array($module, $update));
webmaster@1: }
webmaster@1: }
webmaster@1: }
webmaster@1: }
webmaster@1: $batch = array(
webmaster@1: 'operations' => $operations,
webmaster@1: 'title' => 'Updating',
webmaster@1: 'init_message' => 'Starting updates',
webmaster@1: '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.',
webmaster@1: 'finished' => 'update_finished',
webmaster@1: );
webmaster@1: batch_set($batch);
webmaster@1: batch_process($base_url .'/update.php?op=results', $base_url .'/update.php');
webmaster@1: }
webmaster@1:
webmaster@1: function update_finished($success, $results, $operations) {
webmaster@1: // clear the caches in case the data has been updated.
webmaster@1: drupal_flush_all_caches();
webmaster@1:
webmaster@1: $_SESSION['update_results'] = $results;
webmaster@1: $_SESSION['update_success'] = $success;
webmaster@1: $_SESSION['updates_remaining'] = $operations;
webmaster@1: }
webmaster@1:
webmaster@1: function update_results_page() {
webmaster@1: drupal_set_title('Drupal database update');
webmaster@1: // NOTE: we can't use l() here because the URL would point to 'update.php?q=admin'.
webmaster@1: $links[] = 'Main page';
webmaster@1: $links[] = 'Administration pages';
webmaster@1:
webmaster@1: update_task_list();
webmaster@1: // Report end result
webmaster@1: if (module_exists('dblog')) {
webmaster@1: $log_message = ' All errors have been logged.';
webmaster@1: }
webmaster@1: else {
webmaster@1: $log_message = ' All errors have been logged.';
webmaster@1: }
webmaster@1:
webmaster@1: if ($_SESSION['update_success']) {
webmaster@1: $output = 'Updates were attempted. If you see no failures below, you may proceed happily to the administration pages. Otherwise, you may need to update your database manually.'. $log_message .'
';
webmaster@1: }
webmaster@1: else {
webmaster@1: list($module, $version) = array_pop(reset($_SESSION['updates_remaining']));
webmaster@1: $output = 'The update process was aborted prematurely while running update #'. $version .' in '. $module .'.module.'. $log_message;
webmaster@1: if (module_exists('dblog')) {
webmaster@1: $output .= ' You may need to check the watchdog
database table manually.';
webmaster@1: }
webmaster@1: $output .= '
';
webmaster@1: }
webmaster@1:
webmaster@1: if (!empty($GLOBALS['update_free_access'])) {
webmaster@1: $output .= "Reminder: don't forget to set the \$update_free_access
value in your settings.php
file back to FALSE
.
";
webmaster@1: }
webmaster@1:
webmaster@1: $output .= theme('item_list', $links);
webmaster@1:
webmaster@1: // Output a list of queries executed
webmaster@1: if (!empty($_SESSION['update_results'])) {
webmaster@1: $output .= '';
webmaster@1: $output .= '
The following queries were executed
';
webmaster@1: foreach ($_SESSION['update_results'] as $module => $updates) {
webmaster@1: $output .= '
'. $module .' module
';
webmaster@1: foreach ($updates as $number => $queries) {
webmaster@1: if ($number != '#abort') {
webmaster@1: $output .= '
Update #'. $number .'
';
webmaster@1: $output .= '
';
webmaster@1: foreach ($queries as $query) {
webmaster@1: if ($query['success']) {
webmaster@1: $output .= '- '. $query['query'] .'
';
webmaster@1: }
webmaster@1: else {
webmaster@1: $output .= '- Failed: '. $query['query'] .'
';
webmaster@1: }
webmaster@1: }
webmaster@1: if (!count($queries)) {
webmaster@1: $output .= '- No queries
';
webmaster@1: }
webmaster@1: }
webmaster@1: $output .= '
';
webmaster@1: }
webmaster@1: }
webmaster@1: $output .= '
';
webmaster@1: }
webmaster@1: unset($_SESSION['update_results']);
webmaster@1: unset($_SESSION['update_success']);
webmaster@1:
webmaster@1: return $output;
webmaster@1: }
webmaster@1:
webmaster@1: function update_info_page() {
webmaster@1: // Change query-strings on css/js files to enforce reload for all users.
webmaster@1: _drupal_flush_css_js();
webmaster@1: // Flush the cache of all data for the update status module.
webmaster@1: if (db_table_exists('cache_update')) {
webmaster@1: cache_clear_all('*', 'cache_update', TRUE);
webmaster@1: }
webmaster@1:
webmaster@1: update_task_list('info');
webmaster@1: drupal_set_title('Drupal database update');
webmaster@15: $token = drupal_get_token('update');
webmaster@1: $output = 'Use this utility to update your database whenever a new release of Drupal or a module is installed.
For more detailed information, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.
';
webmaster@1: $output .= "\n";
webmaster@1: $output .= "- Back up your database. This process will change your database values and in case of emergency you may need to revert to a backup.
\n";
webmaster@1: $output .= "- Back up your code. 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.
\n";
webmaster@1: $output .= '- Put your site into maintenance mode.
'."\n";
webmaster@1: $output .= "- Install your new files in the appropriate location, as described in the handbook.
\n";
webmaster@1: $output .= "
\n";
webmaster@1: $output .= "When you have performed the steps above, you may proceed.
\n";
webmaster@15: $output .= '';
webmaster@1: $output .= "\n";
webmaster@1: return $output;
webmaster@1: }
webmaster@1:
webmaster@1: function update_access_denied_page() {
webmaster@1: drupal_set_title('Access denied');
webmaster@1: return '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 settings.php
to bypass this access check. To do this:
webmaster@1:
webmaster@1: - 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
sites/your_site_name
if such directory exists, or else to sites/default
which applies otherwise.
webmaster@1: - There is a line inside your settings.php file that says
$update_free_access = FALSE;
. Change it to $update_free_access = TRUE;
.
webmaster@1: - As soon as the update.php script is done, you must change the settings.php file back to its original form with
$update_free_access = FALSE;
.
webmaster@1: - 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.
webmaster@1:
';
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Create the batch table.
webmaster@1: *
webmaster@1: * This is part of the Drupal 5.x to 6.x migration.
webmaster@1: */
webmaster@1: function update_create_batch_table() {
webmaster@1:
webmaster@1: // If batch table exists, update is not necessary
webmaster@1: if (db_table_exists('batch')) {
webmaster@1: return;
webmaster@1: }
webmaster@1:
webmaster@1: $schema['batch'] = array(
webmaster@1: 'fields' => array(
webmaster@1: 'bid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
webmaster@1: 'token' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE),
webmaster@1: 'timestamp' => array('type' => 'int', 'not null' => TRUE),
webmaster@1: 'batch' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big')
webmaster@1: ),
webmaster@1: 'primary key' => array('bid'),
webmaster@1: 'indexes' => array('token' => array('token')),
webmaster@1: );
webmaster@1:
webmaster@1: $ret = array();
webmaster@1: db_create_table($ret, 'batch', $schema['batch']);
webmaster@1: return $ret;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Disable anything in the {system} table that is not compatible with the
webmaster@1: * current version of Drupal core.
webmaster@1: */
webmaster@1: function update_fix_compatibility() {
webmaster@1: $ret = array();
webmaster@1: $incompatible = array();
webmaster@1: $query = db_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')");
webmaster@1: while ($result = db_fetch_object($query)) {
webmaster@1: if (update_check_incompatibility($result->name, $result->type)) {
webmaster@1: $incompatible[] = $result->name;
webmaster@1: }
webmaster@1: }
webmaster@1: if (!empty($incompatible)) {
webmaster@1: $ret[] = update_sql("UPDATE {system} SET status = 0 WHERE name IN ('". implode("','", $incompatible) ."')");
webmaster@1: }
webmaster@1: return $ret;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Helper function to test compatibility of a module or theme.
webmaster@1: */
webmaster@1: function update_check_incompatibility($name, $type = 'module') {
webmaster@1: static $themes, $modules;
webmaster@1:
webmaster@1: // Store values of expensive functions for future use.
webmaster@1: if (empty($themes) || empty($modules)) {
webmaster@15: $themes = _system_theme_data();
webmaster@1: $modules = module_rebuild_cache();
webmaster@1: }
webmaster@1:
webmaster@1: if ($type == 'module' && isset($modules[$name])) {
webmaster@1: $file = $modules[$name];
webmaster@1: }
webmaster@1: else if ($type == 'theme' && isset($themes[$name])) {
webmaster@1: $file = $themes[$name];
webmaster@1: }
webmaster@1: if (!isset($file)
webmaster@1: || !isset($file->info['core'])
webmaster@1: || $file->info['core'] != DRUPAL_CORE_COMPATIBILITY
webmaster@1: || version_compare(phpversion(), $file->info['php']) < 0) {
webmaster@1: return TRUE;
webmaster@1: }
webmaster@1: return FALSE;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Perform Drupal 5.x to 6.x updates that are required for update.php
webmaster@1: * to function properly.
webmaster@1: *
webmaster@1: * This function runs when update.php is run the first time for 6.x,
webmaster@1: * even before updates are selected or performed. It is important
webmaster@1: * that if updates are not ultimately performed that no changes are
webmaster@1: * made which make it impossible to continue using the prior version.
webmaster@1: * Just adding columns is safe. However, renaming the
webmaster@1: * system.description column to owner is not. Therefore, we add the
webmaster@1: * system.owner column and leave it to system_update_6008() to copy
webmaster@1: * the data from description and remove description. The same for
webmaster@1: * renaming locales_target.locale to locales_target.language, which
webmaster@1: * will be finished by locale_update_6002().
webmaster@1: */
webmaster@1: function update_fix_d6_requirements() {
webmaster@1: $ret = array();
webmaster@1:
webmaster@1: if (drupal_get_installed_schema_version('system') < 6000 && !variable_get('update_d6_requirements', FALSE)) {
webmaster@1: $spec = array('type' => 'int', 'size' => 'small', 'default' => 0, 'not null' => TRUE);
webmaster@1: db_add_field($ret, 'cache', 'serialized', $spec);
webmaster@1: db_add_field($ret, 'cache_filter', 'serialized', $spec);
webmaster@1: db_add_field($ret, 'cache_page', 'serialized', $spec);
webmaster@1: db_add_field($ret, 'cache_menu', 'serialized', $spec);
webmaster@1:
webmaster@1: db_add_field($ret, 'system', 'info', array('type' => 'text'));
webmaster@1: db_add_field($ret, 'system', 'owner', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
webmaster@1: if (db_table_exists('locales_target')) {
webmaster@1: db_add_field($ret, 'locales_target', 'language', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
webmaster@1: }
webmaster@1: if (db_table_exists('locales_source')) {
webmaster@1: db_add_field($ret, 'locales_source', 'textgroup', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'default'));
webmaster@1: db_add_field($ret, 'locales_source', 'version', array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'none'));
webmaster@1: }
webmaster@1: variable_set('update_d6_requirements', TRUE);
webmaster@1:
webmaster@1: // Create the cache_block table. See system_update_6027() for more details.
webmaster@1: $schema['cache_block'] = array(
webmaster@1: 'fields' => array(
webmaster@1: 'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
webmaster@1: 'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
webmaster@1: 'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
webmaster@1: 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
webmaster@1: 'headers' => array('type' => 'text', 'not null' => FALSE),
webmaster@1: 'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
webmaster@1: ),
webmaster@1: 'indexes' => array('expire' => array('expire')),
webmaster@1: 'primary key' => array('cid'),
webmaster@1: );
webmaster@1: db_create_table($ret, 'cache_block', $schema['cache_block']);
webmaster@1: }
webmaster@1:
webmaster@1: return $ret;
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Add the update task list to the current page.
webmaster@1: */
webmaster@1: function update_task_list($active = NULL) {
webmaster@1: // Default list of tasks.
webmaster@1: $tasks = array(
webmaster@1: 'info' => 'Overview',
webmaster@1: 'select' => 'Select updates',
webmaster@1: 'run' => 'Run updates',
webmaster@1: 'finished' => 'Review log',
webmaster@1: );
webmaster@1:
webmaster@1: drupal_set_content('left', theme('task_list', $tasks, $active));
webmaster@1: }
webmaster@1:
webmaster@1: /**
webmaster@1: * Check update requirements and report any errors.
webmaster@1: */
webmaster@1: function update_check_requirements() {
webmaster@1: // Check the system module requirements only.
webmaster@1: $requirements = module_invoke('system', 'requirements', 'update');
webmaster@1: $severity = drupal_requirements_severity($requirements);
webmaster@1:
webmaster@1: // If there are issues, report them.
webmaster@1: if ($severity != REQUIREMENT_OK) {
webmaster@1: foreach ($requirements as $requirement) {
webmaster@1: if (isset($requirement['severity']) && $requirement['severity'] != REQUIREMENT_OK) {
webmaster@1: $message = isset($requirement['description']) ? $requirement['description'] : '';
webmaster@1: if (isset($requirement['value']) && $requirement['value']) {
webmaster@1: $message .= ' (Currently using '. $requirement['title'] .' '. $requirement['value'] .')';
webmaster@1: }
webmaster@1: drupal_set_message($message, 'warning');
webmaster@1: }
webmaster@1: }
webmaster@1: }
webmaster@1: }
webmaster@1:
webmaster@1: // Some unavoidable errors happen because the database is not yet up-to-date.
webmaster@1: // Our custom error handler is not yet installed, so we just suppress them.
webmaster@1: ini_set('display_errors', FALSE);
webmaster@1:
webmaster@1: require_once './includes/bootstrap.inc';
webmaster@1:
webmaster@1: // We only load DRUPAL_BOOTSTRAP_CONFIGURATION for the update requirements
webmaster@1: // check to avoid reaching the PHP memory limit.
webmaster@1: $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
webmaster@1: if (empty($op)) {
webmaster@1: // Minimum load of components.
webmaster@1: drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
webmaster@1:
webmaster@1: require_once './includes/install.inc';
webmaster@1: require_once './includes/file.inc';
webmaster@1: require_once './modules/system/system.install';
webmaster@1:
webmaster@1: // Load module basics.
webmaster@1: include_once './includes/module.inc';
webmaster@1: $module_list['system']['filename'] = 'modules/system/system.module';
webmaster@1: $module_list['filter']['filename'] = 'modules/filter/filter.module';
webmaster@1: module_list(TRUE, FALSE, FALSE, $module_list);
webmaster@1: drupal_load('module', 'system');
webmaster@1: drupal_load('module', 'filter');
webmaster@1:
webmaster@1: // Set up $language, since the installer components require it.
webmaster@1: drupal_init_language();
webmaster@1:
webmaster@1: // Set up theme system for the maintenance page.
webmaster@1: drupal_maintenance_theme();
webmaster@1:
webmaster@1: // Check the update requirements for Drupal.
webmaster@1: update_check_requirements();
webmaster@1:
webmaster@1: // Display the warning messages (if any) in a dedicated maintenance page,
webmaster@1: // or redirect to the update information page if no message.
webmaster@1: $messages = drupal_set_message();
webmaster@1: if (!empty($messages['warning'])) {
webmaster@1: drupal_maintenance_theme();
webmaster@1: print theme('update_page', '', FALSE);
webmaster@1: exit;
webmaster@1: }
webmaster@1: install_goto('update.php?op=info');
webmaster@1: }
webmaster@1:
webmaster@1: drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
webmaster@1: drupal_maintenance_theme();
webmaster@1:
webmaster@1: // This must happen *after* drupal_bootstrap(), since it calls
webmaster@1: // variable_(get|set), which only works after a full bootstrap.
webmaster@1: update_create_batch_table();
webmaster@1:
webmaster@1: // Turn error reporting back on. From now on, only fatal errors (which are
webmaster@1: // not passed through the error handler) will cause a message to be printed.
webmaster@1: ini_set('display_errors', TRUE);
webmaster@1:
webmaster@1: // Access check:
webmaster@1: if (!empty($update_free_access) || $user->uid == 1) {
webmaster@1:
webmaster@1: include_once './includes/install.inc';
webmaster@1: include_once './includes/batch.inc';
webmaster@1: drupal_load_updates();
webmaster@1:
webmaster@1: update_fix_d6_requirements();
webmaster@1: update_fix_compatibility();
webmaster@1:
webmaster@1: $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
webmaster@1: switch ($op) {
webmaster@15: case 'selection':
webmaster@15: if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) {
webmaster@15: $output = update_selection_page();
webmaster@15: break;
webmaster@15: }
webmaster@15:
webmaster@15: case 'Update':
webmaster@15: if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) {
webmaster@15: update_batch();
webmaster@15: break;
webmaster@15: }
webmaster@15:
webmaster@1: // update.php ops
webmaster@1: case 'info':
webmaster@1: $output = update_info_page();
webmaster@1: break;
webmaster@1:
webmaster@1: case 'results':
webmaster@1: $output = update_results_page();
webmaster@1: break;
webmaster@1:
webmaster@1: // Regular batch ops : defer to batch processing API
webmaster@1: default:
webmaster@1: update_task_list('run');
webmaster@1: $output = _batch_page();
webmaster@1: break;
webmaster@1: }
webmaster@1: }
webmaster@1: else {
webmaster@1: $output = update_access_denied_page();
webmaster@1: }
webmaster@1: if (isset($output) && $output) {
webmaster@1: // We defer the display of messages until all updates are done.
webmaster@1: $progress_page = ($batch = batch_get()) && isset($batch['running']);
webmaster@1: print theme('update_page', $output, !$progress_page);
webmaster@1: }