annotate update.php @ 0:ff03f76ab3fe

initial version
author danieleb <danielebarchiesi@me.com>
date Wed, 21 Aug 2013 18:51:11 +0100
parents
children
rev   line source
danielebarchiesi@0 1 <?php
danielebarchiesi@0 2
danielebarchiesi@0 3 /**
danielebarchiesi@0 4 * Defines the root directory of the Drupal installation.
danielebarchiesi@0 5 */
danielebarchiesi@0 6 define('DRUPAL_ROOT', getcwd());
danielebarchiesi@0 7
danielebarchiesi@0 8 /**
danielebarchiesi@0 9 * @file
danielebarchiesi@0 10 * Administrative page for handling updates from one Drupal version to another.
danielebarchiesi@0 11 *
danielebarchiesi@0 12 * Point your browser to "http://www.example.com/update.php" and follow the
danielebarchiesi@0 13 * instructions.
danielebarchiesi@0 14 *
danielebarchiesi@0 15 * If you are not logged in using either the site maintenance account or an
danielebarchiesi@0 16 * account with the "Administer software updates" permission, you will need to
danielebarchiesi@0 17 * modify the access check statement inside your settings.php file. After
danielebarchiesi@0 18 * finishing the upgrade, be sure to open settings.php again, and change it
danielebarchiesi@0 19 * back to its original state!
danielebarchiesi@0 20 */
danielebarchiesi@0 21
danielebarchiesi@0 22 /**
danielebarchiesi@0 23 * Global flag indicating that update.php is being run.
danielebarchiesi@0 24 *
danielebarchiesi@0 25 * When this flag is set, various operations do not take place, such as invoking
danielebarchiesi@0 26 * hook_init() and hook_exit(), css/js preprocessing, and translation.
danielebarchiesi@0 27 */
danielebarchiesi@0 28 define('MAINTENANCE_MODE', 'update');
danielebarchiesi@0 29
danielebarchiesi@0 30 /**
danielebarchiesi@0 31 * Renders a form with a list of available database updates.
danielebarchiesi@0 32 */
danielebarchiesi@0 33 function update_selection_page() {
danielebarchiesi@0 34 drupal_set_title('Drupal database update');
danielebarchiesi@0 35 $elements = drupal_get_form('update_script_selection_form');
danielebarchiesi@0 36 $output = drupal_render($elements);
danielebarchiesi@0 37
danielebarchiesi@0 38 update_task_list('select');
danielebarchiesi@0 39
danielebarchiesi@0 40 return $output;
danielebarchiesi@0 41 }
danielebarchiesi@0 42
danielebarchiesi@0 43 /**
danielebarchiesi@0 44 * Form constructor for the list of available database module updates.
danielebarchiesi@0 45 */
danielebarchiesi@0 46 function update_script_selection_form($form, &$form_state) {
danielebarchiesi@0 47 $count = 0;
danielebarchiesi@0 48 $incompatible_count = 0;
danielebarchiesi@0 49 $form['start'] = array(
danielebarchiesi@0 50 '#tree' => TRUE,
danielebarchiesi@0 51 '#type' => 'fieldset',
danielebarchiesi@0 52 '#collapsed' => TRUE,
danielebarchiesi@0 53 '#collapsible' => TRUE,
danielebarchiesi@0 54 );
danielebarchiesi@0 55
danielebarchiesi@0 56 // Ensure system.module's updates appear first.
danielebarchiesi@0 57 $form['start']['system'] = array();
danielebarchiesi@0 58
danielebarchiesi@0 59 $updates = update_get_update_list();
danielebarchiesi@0 60 $starting_updates = array();
danielebarchiesi@0 61 $incompatible_updates_exist = FALSE;
danielebarchiesi@0 62 foreach ($updates as $module => $update) {
danielebarchiesi@0 63 if (!isset($update['start'])) {
danielebarchiesi@0 64 $form['start'][$module] = array(
danielebarchiesi@0 65 '#type' => 'item',
danielebarchiesi@0 66 '#title' => $module . ' module',
danielebarchiesi@0 67 '#markup' => $update['warning'],
danielebarchiesi@0 68 '#prefix' => '<div class="messages warning">',
danielebarchiesi@0 69 '#suffix' => '</div>',
danielebarchiesi@0 70 );
danielebarchiesi@0 71 $incompatible_updates_exist = TRUE;
danielebarchiesi@0 72 continue;
danielebarchiesi@0 73 }
danielebarchiesi@0 74 if (!empty($update['pending'])) {
danielebarchiesi@0 75 $starting_updates[$module] = $update['start'];
danielebarchiesi@0 76 $form['start'][$module] = array(
danielebarchiesi@0 77 '#type' => 'hidden',
danielebarchiesi@0 78 '#value' => $update['start'],
danielebarchiesi@0 79 );
danielebarchiesi@0 80 $form['start'][$module . '_updates'] = array(
danielebarchiesi@0 81 '#theme' => 'item_list',
danielebarchiesi@0 82 '#items' => $update['pending'],
danielebarchiesi@0 83 '#title' => $module . ' module',
danielebarchiesi@0 84 );
danielebarchiesi@0 85 }
danielebarchiesi@0 86 if (isset($update['pending'])) {
danielebarchiesi@0 87 $count = $count + count($update['pending']);
danielebarchiesi@0 88 }
danielebarchiesi@0 89 }
danielebarchiesi@0 90
danielebarchiesi@0 91 // Find and label any incompatible updates.
danielebarchiesi@0 92 foreach (update_resolve_dependencies($starting_updates) as $function => $data) {
danielebarchiesi@0 93 if (!$data['allowed']) {
danielebarchiesi@0 94 $incompatible_updates_exist = TRUE;
danielebarchiesi@0 95 $incompatible_count++;
danielebarchiesi@0 96 $module_update_key = $data['module'] . '_updates';
danielebarchiesi@0 97 if (isset($form['start'][$module_update_key]['#items'][$data['number']])) {
danielebarchiesi@0 98 $text = $data['missing_dependencies'] ? 'This update will been skipped due to the following missing dependencies: <em>' . implode(', ', $data['missing_dependencies']) . '</em>' : "This update will be skipped due to an error in the module's code.";
danielebarchiesi@0 99 $form['start'][$module_update_key]['#items'][$data['number']] .= '<div class="warning">' . $text . '</div>';
danielebarchiesi@0 100 }
danielebarchiesi@0 101 // Move the module containing this update to the top of the list.
danielebarchiesi@0 102 $form['start'] = array($module_update_key => $form['start'][$module_update_key]) + $form['start'];
danielebarchiesi@0 103 }
danielebarchiesi@0 104 }
danielebarchiesi@0 105
danielebarchiesi@0 106 // Warn the user if any updates were incompatible.
danielebarchiesi@0 107 if ($incompatible_updates_exist) {
danielebarchiesi@0 108 drupal_set_message('Some of the pending updates cannot be applied because their dependencies were not met.', 'warning');
danielebarchiesi@0 109 }
danielebarchiesi@0 110
danielebarchiesi@0 111 if (empty($count)) {
danielebarchiesi@0 112 drupal_set_message(t('No pending updates.'));
danielebarchiesi@0 113 unset($form);
danielebarchiesi@0 114 $form['links'] = array(
danielebarchiesi@0 115 '#markup' => theme('item_list', array('items' => update_helpful_links())),
danielebarchiesi@0 116 );
danielebarchiesi@0 117
danielebarchiesi@0 118 // No updates to run, so caches won't get flushed later. Clear them now.
danielebarchiesi@0 119 drupal_flush_all_caches();
danielebarchiesi@0 120 }
danielebarchiesi@0 121 else {
danielebarchiesi@0 122 $form['help'] = array(
danielebarchiesi@0 123 '#markup' => '<p>The version of Drupal you are updating from has been automatically detected.</p>',
danielebarchiesi@0 124 '#weight' => -5,
danielebarchiesi@0 125 );
danielebarchiesi@0 126 if ($incompatible_count) {
danielebarchiesi@0 127 $form['start']['#title'] = format_plural(
danielebarchiesi@0 128 $count,
danielebarchiesi@0 129 '1 pending update (@number_applied to be applied, @number_incompatible skipped)',
danielebarchiesi@0 130 '@count pending updates (@number_applied to be applied, @number_incompatible skipped)',
danielebarchiesi@0 131 array('@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count)
danielebarchiesi@0 132 );
danielebarchiesi@0 133 }
danielebarchiesi@0 134 else {
danielebarchiesi@0 135 $form['start']['#title'] = format_plural($count, '1 pending update', '@count pending updates');
danielebarchiesi@0 136 }
danielebarchiesi@0 137 $form['has_js'] = array(
danielebarchiesi@0 138 '#type' => 'hidden',
danielebarchiesi@0 139 '#default_value' => FALSE,
danielebarchiesi@0 140 );
danielebarchiesi@0 141 $form['actions'] = array('#type' => 'actions');
danielebarchiesi@0 142 $form['actions']['submit'] = array(
danielebarchiesi@0 143 '#type' => 'submit',
danielebarchiesi@0 144 '#value' => 'Apply pending updates',
danielebarchiesi@0 145 );
danielebarchiesi@0 146 }
danielebarchiesi@0 147 return $form;
danielebarchiesi@0 148 }
danielebarchiesi@0 149
danielebarchiesi@0 150 /**
danielebarchiesi@0 151 * Provides links to the homepage and administration pages.
danielebarchiesi@0 152 */
danielebarchiesi@0 153 function update_helpful_links() {
danielebarchiesi@0 154 $links[] = '<a href="' . base_path() . '">Front page</a>';
danielebarchiesi@0 155 if (user_access('access administration pages')) {
danielebarchiesi@0 156 $links[] = '<a href="' . base_path() . '?q=admin">Administration pages</a>';
danielebarchiesi@0 157 }
danielebarchiesi@0 158 return $links;
danielebarchiesi@0 159 }
danielebarchiesi@0 160
danielebarchiesi@0 161 /**
danielebarchiesi@0 162 * Displays results of the update script with any accompanying errors.
danielebarchiesi@0 163 */
danielebarchiesi@0 164 function update_results_page() {
danielebarchiesi@0 165 drupal_set_title('Drupal database update');
danielebarchiesi@0 166 $links = update_helpful_links();
danielebarchiesi@0 167
danielebarchiesi@0 168 update_task_list();
danielebarchiesi@0 169 // Report end result.
danielebarchiesi@0 170 if (module_exists('dblog') && user_access('access site reports')) {
danielebarchiesi@0 171 $log_message = ' All errors have been <a href="' . base_path() . '?q=admin/reports/dblog">logged</a>.';
danielebarchiesi@0 172 }
danielebarchiesi@0 173 else {
danielebarchiesi@0 174 $log_message = ' All errors have been logged.';
danielebarchiesi@0 175 }
danielebarchiesi@0 176
danielebarchiesi@0 177 if ($_SESSION['update_success']) {
danielebarchiesi@0 178 $output = '<p>Updates were attempted. If you see no failures below, you may proceed happily back to your <a href="' . base_path() . '">site</a>. Otherwise, you may need to update your database manually.' . $log_message . '</p>';
danielebarchiesi@0 179 }
danielebarchiesi@0 180 else {
danielebarchiesi@0 181 list($module, $version) = array_pop(reset($_SESSION['updates_remaining']));
danielebarchiesi@0 182 $output = '<p class="error">The update process was aborted prematurely while running <strong>update #' . $version . ' in ' . $module . '.module</strong>.' . $log_message;
danielebarchiesi@0 183 if (module_exists('dblog')) {
danielebarchiesi@0 184 $output .= ' You may need to check the <code>watchdog</code> database table manually.';
danielebarchiesi@0 185 }
danielebarchiesi@0 186 $output .= '</p>';
danielebarchiesi@0 187 }
danielebarchiesi@0 188
danielebarchiesi@0 189 if (!empty($GLOBALS['update_free_access'])) {
danielebarchiesi@0 190 $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>";
danielebarchiesi@0 191 }
danielebarchiesi@0 192
danielebarchiesi@0 193 $output .= theme('item_list', array('items' => $links));
danielebarchiesi@0 194
danielebarchiesi@0 195 // Output a list of queries executed.
danielebarchiesi@0 196 if (!empty($_SESSION['update_results'])) {
danielebarchiesi@0 197 $all_messages = '';
danielebarchiesi@0 198 foreach ($_SESSION['update_results'] as $module => $updates) {
danielebarchiesi@0 199 if ($module != '#abort') {
danielebarchiesi@0 200 $module_has_message = FALSE;
danielebarchiesi@0 201 $query_messages = '';
danielebarchiesi@0 202 foreach ($updates as $number => $queries) {
danielebarchiesi@0 203 $messages = array();
danielebarchiesi@0 204 foreach ($queries as $query) {
danielebarchiesi@0 205 // If there is no message for this update, don't show anything.
danielebarchiesi@0 206 if (empty($query['query'])) {
danielebarchiesi@0 207 continue;
danielebarchiesi@0 208 }
danielebarchiesi@0 209
danielebarchiesi@0 210 if ($query['success']) {
danielebarchiesi@0 211 $messages[] = '<li class="success">' . $query['query'] . '</li>';
danielebarchiesi@0 212 }
danielebarchiesi@0 213 else {
danielebarchiesi@0 214 $messages[] = '<li class="failure"><strong>Failed:</strong> ' . $query['query'] . '</li>';
danielebarchiesi@0 215 }
danielebarchiesi@0 216 }
danielebarchiesi@0 217
danielebarchiesi@0 218 if ($messages) {
danielebarchiesi@0 219 $module_has_message = TRUE;
danielebarchiesi@0 220 $query_messages .= '<h4>Update #' . $number . "</h4>\n";
danielebarchiesi@0 221 $query_messages .= '<ul>' . implode("\n", $messages) . "</ul>\n";
danielebarchiesi@0 222 }
danielebarchiesi@0 223 }
danielebarchiesi@0 224
danielebarchiesi@0 225 // If there were any messages in the queries then prefix them with the
danielebarchiesi@0 226 // module name and add it to the global message list.
danielebarchiesi@0 227 if ($module_has_message) {
danielebarchiesi@0 228 $all_messages .= '<h3>' . $module . " module</h3>\n" . $query_messages;
danielebarchiesi@0 229 }
danielebarchiesi@0 230 }
danielebarchiesi@0 231 }
danielebarchiesi@0 232 if ($all_messages) {
danielebarchiesi@0 233 $output .= '<div id="update-results"><h2>The following updates returned messages</h2>';
danielebarchiesi@0 234 $output .= $all_messages;
danielebarchiesi@0 235 $output .= '</div>';
danielebarchiesi@0 236 }
danielebarchiesi@0 237 }
danielebarchiesi@0 238 unset($_SESSION['update_results']);
danielebarchiesi@0 239 unset($_SESSION['update_success']);
danielebarchiesi@0 240
danielebarchiesi@0 241 return $output;
danielebarchiesi@0 242 }
danielebarchiesi@0 243
danielebarchiesi@0 244 /**
danielebarchiesi@0 245 * Provides an overview of the Drupal database update.
danielebarchiesi@0 246 *
danielebarchiesi@0 247 * This page provides cautionary suggestions that should happen before
danielebarchiesi@0 248 * proceeding with the update to ensure data integrity.
danielebarchiesi@0 249 *
danielebarchiesi@0 250 * @return
danielebarchiesi@0 251 * Rendered HTML form.
danielebarchiesi@0 252 */
danielebarchiesi@0 253 function update_info_page() {
danielebarchiesi@0 254 // Change query-strings on css/js files to enforce reload for all users.
danielebarchiesi@0 255 _drupal_flush_css_js();
danielebarchiesi@0 256 // Flush the cache of all data for the update status module.
danielebarchiesi@0 257 if (db_table_exists('cache_update')) {
danielebarchiesi@0 258 cache_clear_all('*', 'cache_update', TRUE);
danielebarchiesi@0 259 }
danielebarchiesi@0 260
danielebarchiesi@0 261 update_task_list('info');
danielebarchiesi@0 262 drupal_set_title('Drupal database update');
danielebarchiesi@0 263 $token = drupal_get_token('update');
danielebarchiesi@0 264 $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/upgrade">upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>';
danielebarchiesi@0 265 $output .= "<ol>\n";
danielebarchiesi@0 266 $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";
danielebarchiesi@0 267 $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";
danielebarchiesi@0 268 $output .= '<li>Put your site into <a href="' . base_path() . '?q=admin/config/development/maintenance">maintenance mode</a>.</li>' . "\n";
danielebarchiesi@0 269 $output .= "<li>Install your new files in the appropriate location, as described in the handbook.</li>\n";
danielebarchiesi@0 270 $output .= "</ol>\n";
danielebarchiesi@0 271 $output .= "<p>When you have performed the steps above, you may proceed.</p>\n";
danielebarchiesi@0 272 $form_action = check_url(drupal_current_script_url(array('op' => 'selection', 'token' => $token)));
danielebarchiesi@0 273 $output .= '<form method="post" action="' . $form_action . '"><p><input type="submit" value="Continue" class="form-submit" /></p></form>';
danielebarchiesi@0 274 $output .= "\n";
danielebarchiesi@0 275 return $output;
danielebarchiesi@0 276 }
danielebarchiesi@0 277
danielebarchiesi@0 278 /**
danielebarchiesi@0 279 * Renders a 403 access denied page for update.php.
danielebarchiesi@0 280 *
danielebarchiesi@0 281 * @return
danielebarchiesi@0 282 * Rendered HTML warning with 403 status.
danielebarchiesi@0 283 */
danielebarchiesi@0 284 function update_access_denied_page() {
danielebarchiesi@0 285 drupal_add_http_header('Status', '403 Forbidden');
danielebarchiesi@0 286 watchdog('access denied', 'update.php', NULL, WATCHDOG_WARNING);
danielebarchiesi@0 287 drupal_set_title('Access denied');
danielebarchiesi@0 288 return '<p>Access denied. You are not authorized to access this page. Log in using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to edit <code>settings.php</code> to bypass this access check. To do this:</p>
danielebarchiesi@0 289 <ol>
danielebarchiesi@0 290 <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>
danielebarchiesi@0 291 <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>
danielebarchiesi@0 292 <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>
danielebarchiesi@0 293 <li>To avoid having this problem in the future, remember to log in to your website using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation) before you backup your database at the beginning of the update process.</li>
danielebarchiesi@0 294 </ol>';
danielebarchiesi@0 295 }
danielebarchiesi@0 296
danielebarchiesi@0 297 /**
danielebarchiesi@0 298 * Determines if the current user is allowed to run update.php.
danielebarchiesi@0 299 *
danielebarchiesi@0 300 * @return
danielebarchiesi@0 301 * TRUE if the current user should be granted access, or FALSE otherwise.
danielebarchiesi@0 302 */
danielebarchiesi@0 303 function update_access_allowed() {
danielebarchiesi@0 304 global $update_free_access, $user;
danielebarchiesi@0 305
danielebarchiesi@0 306 // Allow the global variable in settings.php to override the access check.
danielebarchiesi@0 307 if (!empty($update_free_access)) {
danielebarchiesi@0 308 return TRUE;
danielebarchiesi@0 309 }
danielebarchiesi@0 310 // Calls to user_access() might fail during the Drupal 6 to 7 update process,
danielebarchiesi@0 311 // so we fall back on requiring that the user be logged in as user #1.
danielebarchiesi@0 312 try {
danielebarchiesi@0 313 require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'user') . '/user.module';
danielebarchiesi@0 314 return user_access('administer software updates');
danielebarchiesi@0 315 }
danielebarchiesi@0 316 catch (Exception $e) {
danielebarchiesi@0 317 return ($user->uid == 1);
danielebarchiesi@0 318 }
danielebarchiesi@0 319 }
danielebarchiesi@0 320
danielebarchiesi@0 321 /**
danielebarchiesi@0 322 * Adds the update task list to the current page.
danielebarchiesi@0 323 */
danielebarchiesi@0 324 function update_task_list($active = NULL) {
danielebarchiesi@0 325 // Default list of tasks.
danielebarchiesi@0 326 $tasks = array(
danielebarchiesi@0 327 'requirements' => 'Verify requirements',
danielebarchiesi@0 328 'info' => 'Overview',
danielebarchiesi@0 329 'select' => 'Review updates',
danielebarchiesi@0 330 'run' => 'Run updates',
danielebarchiesi@0 331 'finished' => 'Review log',
danielebarchiesi@0 332 );
danielebarchiesi@0 333
danielebarchiesi@0 334 drupal_add_region_content('sidebar_first', theme('task_list', array('items' => $tasks, 'active' => $active)));
danielebarchiesi@0 335 }
danielebarchiesi@0 336
danielebarchiesi@0 337 /**
danielebarchiesi@0 338 * Returns and stores extra requirements that apply during the update process.
danielebarchiesi@0 339 */
danielebarchiesi@0 340 function update_extra_requirements($requirements = NULL) {
danielebarchiesi@0 341 static $extra_requirements = array();
danielebarchiesi@0 342 if (isset($requirements)) {
danielebarchiesi@0 343 $extra_requirements += $requirements;
danielebarchiesi@0 344 }
danielebarchiesi@0 345 return $extra_requirements;
danielebarchiesi@0 346 }
danielebarchiesi@0 347
danielebarchiesi@0 348 /**
danielebarchiesi@0 349 * Checks update requirements and reports errors and (optionally) warnings.
danielebarchiesi@0 350 *
danielebarchiesi@0 351 * @param $skip_warnings
danielebarchiesi@0 352 * (optional) If set to TRUE, requirement warnings will be ignored, and a
danielebarchiesi@0 353 * report will only be issued if there are requirement errors. Defaults to
danielebarchiesi@0 354 * FALSE.
danielebarchiesi@0 355 */
danielebarchiesi@0 356 function update_check_requirements($skip_warnings = FALSE) {
danielebarchiesi@0 357 // Check requirements of all loaded modules.
danielebarchiesi@0 358 $requirements = module_invoke_all('requirements', 'update');
danielebarchiesi@0 359 $requirements += update_extra_requirements();
danielebarchiesi@0 360 $severity = drupal_requirements_severity($requirements);
danielebarchiesi@0 361
danielebarchiesi@0 362 // If there are errors, always display them. If there are only warnings, skip
danielebarchiesi@0 363 // them if the caller has indicated they should be skipped.
danielebarchiesi@0 364 if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && !$skip_warnings)) {
danielebarchiesi@0 365 update_task_list('requirements');
danielebarchiesi@0 366 drupal_set_title('Requirements problem');
danielebarchiesi@0 367 $status_report = theme('status_report', array('requirements' => $requirements));
danielebarchiesi@0 368 $status_report .= 'Check the error messages and <a href="' . check_url(drupal_requirements_url($severity)) . '">try again</a>.';
danielebarchiesi@0 369 print theme('update_page', array('content' => $status_report));
danielebarchiesi@0 370 exit();
danielebarchiesi@0 371 }
danielebarchiesi@0 372 }
danielebarchiesi@0 373
danielebarchiesi@0 374 // Some unavoidable errors happen because the database is not yet up-to-date.
danielebarchiesi@0 375 // Our custom error handler is not yet installed, so we just suppress them.
danielebarchiesi@0 376 ini_set('display_errors', FALSE);
danielebarchiesi@0 377
danielebarchiesi@0 378 // We prepare a minimal bootstrap for the update requirements check to avoid
danielebarchiesi@0 379 // reaching the PHP memory limit.
danielebarchiesi@0 380 require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
danielebarchiesi@0 381 require_once DRUPAL_ROOT . '/includes/update.inc';
danielebarchiesi@0 382 require_once DRUPAL_ROOT . '/includes/common.inc';
danielebarchiesi@0 383 require_once DRUPAL_ROOT . '/includes/file.inc';
danielebarchiesi@0 384 require_once DRUPAL_ROOT . '/includes/entity.inc';
danielebarchiesi@0 385 require_once DRUPAL_ROOT . '/includes/unicode.inc';
danielebarchiesi@0 386 update_prepare_d7_bootstrap();
danielebarchiesi@0 387
danielebarchiesi@0 388 // Temporarily disable configurable timezones so the upgrade process uses the
danielebarchiesi@0 389 // site-wide timezone. This prevents a PHP notice during session initlization
danielebarchiesi@0 390 // and before offsets have been converted in user_update_7002().
danielebarchiesi@0 391 $configurable_timezones = variable_get('configurable_timezones', 1);
danielebarchiesi@0 392 $conf['configurable_timezones'] = 0;
danielebarchiesi@0 393
danielebarchiesi@0 394 // Determine if the current user has access to run update.php.
danielebarchiesi@0 395 drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
danielebarchiesi@0 396
danielebarchiesi@0 397 // Reset configurable timezones.
danielebarchiesi@0 398 $conf['configurable_timezones'] = $configurable_timezones;
danielebarchiesi@0 399
danielebarchiesi@0 400 // Only allow the requirements check to proceed if the current user has access
danielebarchiesi@0 401 // to run updates (since it may expose sensitive information about the site's
danielebarchiesi@0 402 // configuration).
danielebarchiesi@0 403 $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
danielebarchiesi@0 404 if (empty($op) && update_access_allowed()) {
danielebarchiesi@0 405 require_once DRUPAL_ROOT . '/includes/install.inc';
danielebarchiesi@0 406 require_once DRUPAL_ROOT . '/modules/system/system.install';
danielebarchiesi@0 407
danielebarchiesi@0 408 // Load module basics.
danielebarchiesi@0 409 include_once DRUPAL_ROOT . '/includes/module.inc';
danielebarchiesi@0 410 $module_list['system']['filename'] = 'modules/system/system.module';
danielebarchiesi@0 411 module_list(TRUE, FALSE, FALSE, $module_list);
danielebarchiesi@0 412 drupal_load('module', 'system');
danielebarchiesi@0 413
danielebarchiesi@0 414 // Reset the module_implements() cache so that any new hook implementations
danielebarchiesi@0 415 // in updated code are picked up.
danielebarchiesi@0 416 module_implements('', FALSE, TRUE);
danielebarchiesi@0 417
danielebarchiesi@0 418 // Set up $language, since the installer components require it.
danielebarchiesi@0 419 drupal_language_initialize();
danielebarchiesi@0 420
danielebarchiesi@0 421 // Set up theme system for the maintenance page.
danielebarchiesi@0 422 drupal_maintenance_theme();
danielebarchiesi@0 423
danielebarchiesi@0 424 // Check the update requirements for Drupal. Only report on errors at this
danielebarchiesi@0 425 // stage, since the real requirements check happens further down.
danielebarchiesi@0 426 update_check_requirements(TRUE);
danielebarchiesi@0 427
danielebarchiesi@0 428 // Redirect to the update information page if all requirements were met.
danielebarchiesi@0 429 install_goto('update.php?op=info');
danielebarchiesi@0 430 }
danielebarchiesi@0 431
danielebarchiesi@0 432 // update_fix_d7_requirements() needs to run before bootstrapping beyond path.
danielebarchiesi@0 433 // So bootstrap to DRUPAL_BOOTSTRAP_LANGUAGE then include unicode.inc.
danielebarchiesi@0 434
danielebarchiesi@0 435 drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);
danielebarchiesi@0 436 include_once DRUPAL_ROOT . '/includes/unicode.inc';
danielebarchiesi@0 437
danielebarchiesi@0 438 update_fix_d7_requirements();
danielebarchiesi@0 439
danielebarchiesi@0 440 // Now proceed with a full bootstrap.
danielebarchiesi@0 441
danielebarchiesi@0 442 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
danielebarchiesi@0 443 drupal_maintenance_theme();
danielebarchiesi@0 444
danielebarchiesi@0 445 // Turn error reporting back on. From now on, only fatal errors (which are
danielebarchiesi@0 446 // not passed through the error handler) will cause a message to be printed.
danielebarchiesi@0 447 ini_set('display_errors', TRUE);
danielebarchiesi@0 448
danielebarchiesi@0 449 // Only proceed with updates if the user is allowed to run them.
danielebarchiesi@0 450 if (update_access_allowed()) {
danielebarchiesi@0 451
danielebarchiesi@0 452 include_once DRUPAL_ROOT . '/includes/install.inc';
danielebarchiesi@0 453 include_once DRUPAL_ROOT . '/includes/batch.inc';
danielebarchiesi@0 454 drupal_load_updates();
danielebarchiesi@0 455
danielebarchiesi@0 456 update_fix_compatibility();
danielebarchiesi@0 457
danielebarchiesi@0 458 // Check the update requirements for all modules. If there are warnings, but
danielebarchiesi@0 459 // no errors, skip reporting them if the user has provided a URL parameter
danielebarchiesi@0 460 // acknowledging the warnings and indicating a desire to continue anyway. See
danielebarchiesi@0 461 // drupal_requirements_url().
danielebarchiesi@0 462 $skip_warnings = !empty($_GET['continue']);
danielebarchiesi@0 463 update_check_requirements($skip_warnings);
danielebarchiesi@0 464
danielebarchiesi@0 465 $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
danielebarchiesi@0 466 switch ($op) {
danielebarchiesi@0 467 // update.php ops.
danielebarchiesi@0 468
danielebarchiesi@0 469 case 'selection':
danielebarchiesi@0 470 if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) {
danielebarchiesi@0 471 $output = update_selection_page();
danielebarchiesi@0 472 break;
danielebarchiesi@0 473 }
danielebarchiesi@0 474
danielebarchiesi@0 475 case 'Apply pending updates':
danielebarchiesi@0 476 if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) {
danielebarchiesi@0 477 // Generate absolute URLs for the batch processing (using $base_root),
danielebarchiesi@0 478 // since the batch API will pass them to url() which does not handle
danielebarchiesi@0 479 // update.php correctly by default.
danielebarchiesi@0 480 $batch_url = $base_root . drupal_current_script_url();
danielebarchiesi@0 481 $redirect_url = $base_root . drupal_current_script_url(array('op' => 'results'));
danielebarchiesi@0 482 update_batch($_POST['start'], $redirect_url, $batch_url);
danielebarchiesi@0 483 break;
danielebarchiesi@0 484 }
danielebarchiesi@0 485
danielebarchiesi@0 486 case 'info':
danielebarchiesi@0 487 $output = update_info_page();
danielebarchiesi@0 488 break;
danielebarchiesi@0 489
danielebarchiesi@0 490 case 'results':
danielebarchiesi@0 491 $output = update_results_page();
danielebarchiesi@0 492 break;
danielebarchiesi@0 493
danielebarchiesi@0 494 // Regular batch ops : defer to batch processing API.
danielebarchiesi@0 495 default:
danielebarchiesi@0 496 update_task_list('run');
danielebarchiesi@0 497 $output = _batch_page();
danielebarchiesi@0 498 break;
danielebarchiesi@0 499 }
danielebarchiesi@0 500 }
danielebarchiesi@0 501 else {
danielebarchiesi@0 502 $output = update_access_denied_page();
danielebarchiesi@0 503 }
danielebarchiesi@0 504 if (isset($output) && $output) {
danielebarchiesi@0 505 // Explicitly start a session so that the update.php token will be accepted.
danielebarchiesi@0 506 drupal_session_start();
danielebarchiesi@0 507 // We defer the display of messages until all updates are done.
danielebarchiesi@0 508 $progress_page = ($batch = batch_get()) && isset($batch['running']);
danielebarchiesi@0 509 print theme('update_page', array('content' => $output, 'show_messages' => !$progress_page));
danielebarchiesi@0 510 }