update.php

  1. 7.x drupal-7.x/update.php
  2. 6.x drupal-6.x/update.php

Administrative page for handling updates from one Drupal version to another.

Point your browser to "http://www.example.com/update.php" and follow the instructions.

If you are not logged in as administrator, you will need to modify the access check statement inside your settings.php file. After finishing the upgrade, be sure to open settings.php again, and change it back to its original state!

File

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