1 update.inc | update_prepare_bootstrap() |
Performs extra steps required to bootstrap when using a Drupal 7 database.
Users who still have a Drupal 7 database (and are in the process of updating to Backdrop) need extra help before a full bootstrap can be achieved. This function does the necessary preliminary work that allows the bootstrap to be successful.
No access check has been performed when this function is called, so no irreversible changes to the database are made here.
File
- core/
includes/ update.inc, line 80 - Backdrop site update API.
Code
function update_prepare_bootstrap() {
// Allow the database system to work even if the registry has not been
// created yet.
include_once BACKDROP_ROOT . '/core/includes/install.inc';
include_once BACKDROP_ROOT . '/core/modules/entity/entity.controller.inc';
backdrop_bootstrap(BACKDROP_BOOTSTRAP_CONFIGURATION);
// Check whether settings.php needs to be rewritten.
$settings_exist = !empty($GLOBALS['config_directories']);
$active_config = config_get_config_storage('active');
$staging_config = config_get_config_storage('staging');
if (!is_a($active_config, 'ConfigDatabaseStorage')) {
if (!$settings_exist || !$active_config->isInitialized()) {
backdrop_install_config_location();
}
// Check for a staging directory.
if (!$staging_config->isInitialized()) {
$t = get_t();
backdrop_set_message($t('The staging configuration directory (%directory) could not be found. Please make sure it exists and is properly referenced in settings.php.',
array('%directory' => config_get_config_directory('staging'))), 'warning', FALSE);
}
}
// If any of the required settings needs to be written, then settings.php
// needs to be writable.
if (!$settings_exist) {
$settings_file = conf_path() . '/settings.php';
$writable = backdrop_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_WRITABLE);
$requirements['settings file']['title'] = 'Settings file';
if ($writable) {
$requirements['settings file'] += array(
'value' => 'settings.php is writable.',
);
}
else {
$requirements['settings file'] += array(
'value' => 'settings.php is not writable.',
'severity' => REQUIREMENT_ERROR,
'description' => 'Backdrop CMS requires write permissions to <em>' . $settings_file . '</em> during the update process. If you are unsure how to grant file permissions, consult the <a href="https://backdropcms.org/installation">Installation Instructions</a> page.',
);
}
update_extra_requirements($requirements);
}
// Bootstrap the database.
backdrop_bootstrap(BACKDROP_BOOTSTRAP_DATABASE);
// If the site has not updated to Backdrop yet, check to make sure that it is
// running an up-to-date version of Drupal 7 before proceeding. Note this has
// to happen AFTER the database bootstraps because of
// backdrop_get_installed_schema_version().
$system_schema = backdrop_get_installed_schema_version('system');
if ($system_schema > 7000 || $system_schema < 6000) {
$has_required_schema = $system_schema >= REQUIRED_D7_SCHEMA_VERSION || $system_schema < 6000;
$requirements = array(
'drupal 7 version' => array(
'title' => 'Drupal 7 version',
'value' => $has_required_schema ? 'You are running a current version of Drupal 7.' : 'You are not running a current version of Drupal 7',
'severity' => $has_required_schema ? REQUIREMENT_OK : REQUIREMENT_ERROR,
'description' => $has_required_schema ? '' : 'Please update your Drupal 7 installation to the most recent version before attempting to upgrade to Backdrop',
),
);
update_extra_requirements($requirements);
if ($has_required_schema) {
// Bootstrap variables so we can update theme while preparing the update
// process.
backdrop_bootstrap(BACKDROP_BOOTSTRAP_VARIABLES);
// Change language column to langcode in url_alias.
if (db_table_exists('url_alias') && db_field_exists('url_alias', 'language')) {
db_drop_index('url_alias', 'alias_language_pid');
db_drop_index('url_alias', 'source_language_pid');
$langcode_spec = array(
'description' => "The language code this alias is for; if 'und', the alias will be used for unknown languages. Each Backdrop path can have an alias for each supported language.",
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
);
$langcode_indexes = array(
'indexes' => array(
'alias_langcode_pid' => array('alias', 'langcode', 'pid'),
'source_langcode_pid' => array('source', 'langcode', 'pid'),
),
);
db_change_field('url_alias', 'language', 'langcode', $langcode_spec, $langcode_indexes);
}
// Create the state table.
if (!db_table_exists('state')) {
$schema = array(
'description' => 'Stores environment-specific state values.',
'fields' => array(
'name' => array(
'description' => 'The name of the state.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'value' => array(
'description' => 'The value of the state.',
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
),
),
'primary key' => array('name'),
);
db_create_table('state', $schema);
}
// Update role ID to be a varchar instead of an integer.
$role_column = array(
'type' => 'varchar',
'length' => 64,
'description' => 'Primary Key: The name of the role.',
'not null' => TRUE,
'default' => '',
);
if (!db_field_exists('users_roles', 'role')) {
db_add_field('users_roles', 'role', $role_column);
}
// Update the environment for the language bootstrap if needed. Language
// depends on the state table, so this runs after its creation.
update_prepare_language();
}
}
}