Created
January 15, 2012 13:00
-
-
Save lstrojny/1615794 to your computer and use it in GitHub Desktop.
Execute Drupal Updates without User Interaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Content-Type: text/plain"); | |
define('DRUPAL_ROOT', getcwd()); | |
define('MAINTENANCE_MODE', 'update'); | |
ini_set('display_errors', TRUE); | |
require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; | |
require_once DRUPAL_ROOT . '/includes/update.inc'; | |
require_once DRUPAL_ROOT . '/includes/common.inc'; | |
require_once DRUPAL_ROOT . '/includes/file.inc'; | |
require_once DRUPAL_ROOT . '/includes/entity.inc'; | |
require_once DRUPAL_ROOT . '/includes/unicode.inc'; | |
update_prepare_d7_bootstrap(); | |
// Temporarily disable configurable timezones so the upgrade process uses the | |
// site-wide timezone. This prevents a PHP notice during session initlization | |
// and before offsets have been converted in user_update_7002(). | |
$configurable_timezones = variable_get('configurable_timezones', 1); | |
$conf['configurable_timezones'] = 0; | |
// Determine if the current user has access to run update.php. | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); | |
// Reset configurable timezones. | |
$conf['configurable_timezones'] = $configurable_timezones; | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE); | |
include_once DRUPAL_ROOT . '/includes/unicode.inc'; | |
update_fix_d7_requirements(); | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | |
drupal_maintenance_theme(); | |
include_once DRUPAL_ROOT . '/includes/install.inc'; | |
include_once DRUPAL_ROOT . '/includes/batch.inc'; | |
drupal_load_updates(); | |
update_fix_compatibility(); | |
$updates['system'] = array(); | |
foreach (update_get_update_list() as $module => $update) { | |
foreach ($update['pending'] as $version => $description) { | |
$updates[$module] = $version; | |
} | |
} | |
$updates = update_resolve_dependencies($updates); | |
$dependency_map = array(); | |
foreach ($updates as $function => $update) { | |
$dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array(); | |
} | |
$operations = array(); | |
foreach ($updates as $update) { | |
if ($update['allowed']) { | |
drupal_set_installed_schema_version($update['module'], $update['number'] - 1); | |
} | |
$function = $update['module'] . '_update_' . $update['number']; | |
$context = array('results' => array(), 'sandbox' => array(), 'sandbox' => array('#finished' => true)); | |
update_do_one($update['module'], $update['number'], $dependency_map[$function], $context); | |
printf("%s: %s\n", $function, $context['message']); | |
if (!empty($context['results'][$update['module']][$update['number']]['#abort'])) { | |
printf( | |
" - %s\n", | |
strip_tags( | |
html_entity_decode($context['results'][$update['module']][$update['number']]['#abort']['query']) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment