From bc058bada9f5deda6301e4bf85d21236ed267ad9 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Fri, 31 Jan 2014 09:26:04 -0800 Subject: [PATCH] Issue #2168011 by xjm, jessebeach, Damien Tournoud, znerol, Xano: Remove all 7.x to 8.x update hooks and disallow updates from the previous major version. --- core/includes/install.inc | 8 +- core/includes/schema.inc | 5 - core/includes/theme.inc | 1 - core/includes/update.inc | 931 ++------------ core/lib/Drupal.php | 5 + .../Drupal/Core/Extension/ModuleHandler.php | 9 +- .../Core/Extension/UpdateModuleHandler.php | 7 +- core/modules/aggregator/aggregator.install | 49 - core/modules/block/block.install | 349 ----- core/modules/book/book.install | 23 - core/modules/color/color.install | 28 - core/modules/comment/comment.install | 454 ------- core/modules/contact/contact.install | 91 -- core/modules/dblog/dblog.install | 38 - core/modules/entity/entity.install | 86 -- core/modules/field/field.install | 585 --------- core/modules/field_ui/field_ui.install | 44 - core/modules/file/file.install | 121 -- core/modules/filter/filter.install | 60 - core/modules/forum/forum.install | 135 -- core/modules/image/image.install | 230 ---- core/modules/locale/locale.install | 584 --------- core/modules/menu/menu.install | 96 -- core/modules/node/node.install | 704 ---------- core/modules/rdf/rdf.install | 60 - core/modules/search/search.install | 92 -- core/modules/shortcut/shortcut.install | 183 --- core/modules/simpletest/simpletest.install | 13 - core/modules/statistics/statistics.install | 41 - core/modules/syslog/syslog.install | 21 - .../Update/DependencyHookInvocationTest.php | 8 +- .../Tests/Update/DependencyMissingTest.php | 10 +- .../Tests/Update/DependencyOrderingTest.php | 14 +- .../system/Tests/Update/InvalidUpdateHook.php | 63 + .../system/Tests/Update/UpdateScriptTest.php | 128 +- .../system/Tests/Update/UpdatesWith7x.php | 63 + core/modules/system/system.api.php | 86 +- core/modules/system/system.install | 1131 ----------------- .../update_script_test.install | 25 +- .../update_test_0/update_test_0.info.yml | 7 + .../update_test_0/update_test_0.install | 24 + .../update_test_0/update_test_0.module | 1 + .../update_test_1/update_test_1.install | 43 +- .../update_test_2/update_test_2.install | 32 +- .../update_test_3/update_test_3.install | 8 +- .../update_test_invalid_hook.info.yml | 7 + .../update_test_invalid_hook.install | 12 + .../update_test_invalid_hook.module | 1 + .../update_test_with_7x.info.yml | 7 + .../update_test_with_7x.install | 25 + .../update_test_with_7x.module | 1 + core/modules/taxonomy/taxonomy.install | 262 ---- core/modules/text/text.install | 17 - core/modules/toolbar/toolbar.install | 27 - core/modules/tracker/tracker.install | 48 - core/modules/update/update.install | 35 - core/modules/user/user.install | 806 ------------ core/update.php | 89 +- 58 files changed, 603 insertions(+), 7430 deletions(-) delete mode 100644 core/modules/entity/entity.install delete mode 100644 core/modules/field/field.install delete mode 100644 core/modules/field_ui/field_ui.install delete mode 100644 core/modules/filter/filter.install delete mode 100644 core/modules/rdf/rdf.install create mode 100644 core/modules/system/lib/Drupal/system/Tests/Update/InvalidUpdateHook.php create mode 100644 core/modules/system/lib/Drupal/system/Tests/Update/UpdatesWith7x.php create mode 100644 core/modules/system/tests/modules/update_test_0/update_test_0.info.yml create mode 100644 core/modules/system/tests/modules/update_test_0/update_test_0.install create mode 100644 core/modules/system/tests/modules/update_test_0/update_test_0.module create mode 100644 core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.info.yml create mode 100644 core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.install create mode 100644 core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.module create mode 100644 core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.info.yml create mode 100644 core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.install create mode 100644 core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.module delete mode 100644 core/modules/text/text.install delete mode 100644 core/modules/toolbar/toolbar.install diff --git a/core/includes/install.inc b/core/includes/install.inc index 8c91dc86dadf..f3fbdf0bf8f2 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -630,8 +630,14 @@ function drupal_install_system($install_state) { $system_path = drupal_get_path('module', 'system'); require_once DRUPAL_ROOT . '/' . $system_path . '/system.install'; + + // Set the schema version to the number of the last update provided by the + // module, or the minimum core schema version. + $system_version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION; $system_versions = drupal_get_schema_versions('system'); - $system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED; + if ($system_versions) { + $system_version = max(max($system_versions), $system_version); + } \Drupal::keyValue('system.schema')->set('system', $system_version); // System module needs to be enabled and the system/module lists need to be diff --git a/core/includes/schema.inc b/core/includes/schema.inc index e086da7c7e39..bb1c6e6641c8 100644 --- a/core/includes/schema.inc +++ b/core/includes/schema.inc @@ -19,11 +19,6 @@ */ const SCHEMA_UNINSTALLED = -1; -/** - * Indicates that a module has been installed. - */ -const SCHEMA_INSTALLED = 0; - /** * Gets the schema definition of a table, or the whole database schema. * diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 96a04666eada..144882b9b62b 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1046,7 +1046,6 @@ function theme_get_setting($setting_name, $theme = NULL) { * Converts theme settings to configuration. * * @see system_theme_settings_submit() - * @see system_update_8054() * * @param array $theme_settings * An array of theme settings from system setting form or a Drupal 7 variable. diff --git a/core/includes/update.inc b/core/includes/update.inc index 9383a0727321..f1850362e9c8 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -19,16 +19,6 @@ use Drupal\Component\Utility\NestedArray; use Symfony\Component\HttpFoundation\Request; -/** - * Minimum schema version of Drupal 7 required for upgrade to Drupal 8. - * - * Upgrades from Drupal 7 to Drupal 8 require that Drupal 7 be running - * the most recent version, or the upgrade could fail. We can't easily - * check the Drupal 7 version once the update process has begun, so instead - * we check the schema version of system.module. - */ -const REQUIRED_D7_SCHEMA_VERSION = '7069'; - /** * Disables any extensions that are incompatible with the current core version. */ @@ -82,653 +72,95 @@ function update_check_incompatibility($name, $type = 'module') { } /** - * 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 Drupal 8) need extra help before a full bootstrap can be - * achieved. This function does the necessary preliminary work that allows - * the bootstrap to be successful. + * Returns whether the settings file requirement has been satisfied. * - * No access check has been performed when this function is called, so no - * irreversible changes to the database are made here. + * @return array + * A requirements info array. */ -function update_prepare_d8_bootstrap() { - include_once __DIR__ . '/install.inc'; - include_once __DIR__ . '/schema.inc'; - // Bootstrap to configuration. - drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); - - // During the bootstrap to DRUPAL_BOOTSTRAP_PAGE_CACHE, code will try to read - // the cache but the cache tables are not compatible yet. Use the Null backend - // by default to avoid exceptions. - $settings = settings()->getAll(); - $settings['cache']['default'] = 'cache.backend.memory'; - new Settings($settings); - - // Enable UpdateServiceProvider service overrides. - // @see update_flush_all_caches() - $GLOBALS['conf']['container_service_providers']['UpdateServiceProvider'] = 'Drupal\Core\DependencyInjection\UpdateServiceProvider'; - $GLOBALS['conf']['update_service_provider_overrides'] = TRUE; +function update_settings_file_requirements() { + $requirements = array(); // Check whether settings.php needs to be rewritten. - $settings_exist = !empty($GLOBALS['config_directories']); - - if (!$settings_exist || !is_dir(config_get_config_directory('active')) || !is_dir(config_get_config_directory('staging'))) { - drupal_install_config_directories(); - } - - // Bootstrap the kernel. - // Do not attempt to dump and write it. - $kernel = new DrupalKernel('update', drupal_classloader(), FALSE); - $kernel->boot(); - $request = Request::createFromGlobals(); - \Drupal::getContainer()->set('request', $request); - - // 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 = drupal_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' => 'Drupal 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="http://drupal.org/server-permissions">online handbook</a>.', - ); - } - update_extra_requirements($requirements); - } - - // Bootstrap the database. - require_once __DIR__ . '/database.inc'; - - // module.inc is not yet loaded but there are calls to module_config_sort() - // below. - require_once __DIR__ . '/module.inc'; - - // If the site has not updated to Drupal 8 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 - // drupal_get_installed_schema_version(). - try { - $system_schema = drupal_get_installed_schema_version('system'); - } - catch (\Exception $e) { - $system_schema = db_query('SELECT schema_version FROM {system} WHERE name = :system', array(':system' => 'system'))->fetchField(); - } - if ($system_schema < 8000) { - $has_required_schema = $system_schema >= REQUIRED_D7_SCHEMA_VERSION; - $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 ? NULL : REQUIREMENT_ERROR, - 'description' => $has_required_schema ? '' : 'Please update your Drupal 7 installation to the most recent version before attempting to upgrade to Drupal 8', - ), + $settings_file = conf_path() . '/settings.php'; + $writable = drupal_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.', ); - update_extra_requirements($requirements); - - // @todo update.php stages seem to be completely screwed up; the initial - // requirements check is not supposed to change the system. All of the - // following code seems to have been mistakenly/unknowingly added here and - // does not belong into update_prepare_d8_bootstrap(). - if ($has_required_schema) { - if (!db_table_exists('key_value')) { - $specs = array( - 'description' => 'Generic key-value storage table. See the state system for an example.', - 'fields' => array( - 'collection' => array( - 'description' => 'A named collection of key and value pairs.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - ), - 'name' => array( - 'description' => 'The key of the key-value pair. As KEY is a SQL reserved keyword, name was chosen instead.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - ), - 'value' => array( - 'description' => 'The value.', - 'type' => 'blob', - 'not null' => TRUE, - 'size' => 'big', - 'translatable' => TRUE, - ), - ), - 'primary key' => array('collection', 'name'), - ); - db_create_table('key_value', $specs); - } - if (!db_table_exists('cache_tags')) { - $table = array( - 'description' => 'Cache table for tracking cache tags related to the cache bin.', - 'fields' => array( - 'tag' => array( - 'description' => 'Namespace-prefixed tag string.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'invalidations' => array( - 'description' => 'Number incremented when the tag is invalidated.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'deletions' => array( - 'description' => 'Number incremented when the tag is deleted.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'primary key' => array('tag'), - ); - db_create_table('cache_tags', $table); - } - if (!db_table_exists('cache_config')) { - $spec = array( - 'description' => 'Cache table for configuration data.', - 'fields' => array( - 'cid' => array( - 'description' => 'Primary Key: Unique cache ID.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'data' => array( - 'description' => 'A collection of data to cache.', - 'type' => 'blob', - 'not null' => FALSE, - 'size' => 'big', - ), - 'expire' => array( - 'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'created' => array( - 'description' => 'A Unix timestamp indicating when the cache entry was created.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'serialized' => array( - 'description' => 'A flag to indicate whether content is serialized (1) or not (0).', - 'type' => 'int', - 'size' => 'small', - 'not null' => TRUE, - 'default' => 0, - ), - 'tags' => array( - 'description' => 'Space-separated list of cache tags for this entry.', - 'type' => 'text', - 'size' => 'big', - 'not null' => FALSE, - ), - 'checksum_invalidations' => array( - 'description' => 'The tag invalidation sum when this entry was saved.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'checksum_deletions' => array( - 'description' => 'The tag deletion sum when this entry was saved.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'indexes' => array( - 'expire' => array('expire'), - ), - 'primary key' => array('cid'), - ); - db_create_table('cache_config', $spec); - } - - require_once DRUPAL_ROOT . '/core/modules/system/system.install'; - $tables = array( - 'cache', - 'cache_bootstrap', - 'cache_block', - 'cache_field', - 'cache_filter', - 'cache_form', - 'cache_image', - 'cache_menu', - 'cache_page', - 'cache_path', - 'cache_update', - ); - - foreach ($tables as $table) { - update_add_cache_columns($table); - } - - // Bootstrap to cache system. - drupal_bootstrap(DRUPAL_BOOTSTRAP_PAGE_CACHE); - - // Update the 'language_default' system variable, if configured. - // Required to run before drupal_install_config_directories(), since that - // triggers a call into system_stream_wrappers(), which calls t(), which - // calls into language_default(). - $language_default = update_variable_get('language_default'); - if (!empty($language_default) && (isset($language_default->id) || isset($language_default->language))) { - if (!isset($language_default->id)) { - $language_default->id = $language_default->language; - } - unset($language_default->language); - // In D8, the 'language_default' is not anymore an object, but an array, - // so make sure that the new value that is saved into this variable is an - // array. - update_variable_set('language_default', (array) $language_default); - } - - $module_config = \Drupal::config('system.module'); - $theme_config = \Drupal::config('system.theme'); - $disabled_themes = \Drupal::config('system.theme.disabled'); - $schema_store = \Drupal::keyValue('system.schema'); - - // Load system.module, because update_prepare_d8_bootstrap() is called in - // the initial minimal update.php bootstrap that performs the core - // requirements check. - require_once DRUPAL_ROOT . '/core/modules/system/system.module'; - - // Make sure that the bootstrap cache is cleared as that might contain - // incompatible data structures. - cache('bootstrap')->deleteAll(); - - // Retrieve all installed extensions from the {system} table. - // Uninstalled extensions are ignored and not converted. - $result = db_query('SELECT name, status, weight, schema_version, type FROM {system} WHERE type = :theme OR (type = :module AND schema_version <> :schema_uninstalled)', array( - ':theme' => 'theme', - ':module' => 'module', - ':schema_uninstalled' => SCHEMA_UNINSTALLED, - )); - - $module_data = _system_rebuild_module_data(); - - // Migrate each extension into configuration, varying by the extension's - // status, and record its schema version. - foreach ($result as $record) { - // Before migrating any extension into configuration, make sure the - // extensions name length is not higher than the limit. - if (drupal_strlen($record->name) > 50) { - $requirements['module name too long ' . $record->name] = array( - 'title' => 'Module name too long', - 'value' => format_string('@name is @count characters long.', array('@name' => $record->name, '@count' => drupal_strlen($record->name))), - 'description' => 'Module names longer than 50 characters are <a href="https://drupal.org/node/2014073">no longer supported</a>.', - 'severity' => REQUIREMENT_ERROR, - ); - update_extra_requirements($requirements); - } - - if ($record->type == 'module') { - if ($record->status && isset($module_data[$record->name])) { - $module_config->set('enabled.' . $record->name, $record->weight); - } - } - elseif ($record->type == 'theme') { - if ($record->status) { - $theme_config->set('enabled.' . $record->name, 0); - } - else { - $disabled_themes->set($record->name, 0); - } - } - $schema_store->set($record->name, $record->schema_version); - } - $sorted_modules = module_config_sort($module_config->get('enabled')); - $module_config->set('enabled', $sorted_modules)->save(); - $sorted_with_filenames = array(); - foreach (array_keys($sorted_modules) as $m) { - $sorted_with_filenames[$m] = drupal_get_filename('module', $m); - } - \Drupal::moduleHandler()->setModuleList($sorted_with_filenames); - $theme_config->save(); - $disabled_themes->save(); - - // Migrate the private key to state. This is used to create the token for - // the upgrade batch so needs to be be done before the upgrade has begun. - update_variables_to_state(array( - 'drupal_private_key' => 'system.private_key', - )); - - // Update the dynamic include paths that might be used before running the - // proper update functions. - update_prepare_stored_includes(); - // Update the environment for the language bootstrap if needed. - update_prepare_d8_language(); - // Rebuild kernel after new language fields are added in the database - // because the translation service depends on them being there. - \Drupal::service('kernel')->updateModules($sorted_with_filenames, $sorted_with_filenames); - - // 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 Drupal 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); - } - } } - // Moves install_profile from variable to settings. You can't do that in - // system.install because _system_rebuild_module_data() needs the profile - // directly. Check that it has not been set already. This is the case for - // Simpletest upgrade path tests. - if (!settings()->get('install_profile')) { - $old_variable = unserialize(\Drupal::database()->query('SELECT value FROM {variable} WHERE name = :name', array(':name' => 'install_profile'))->fetchField()); - $settings = array( - 'settings' => array( - 'install_profile' => (object) array( - 'value' => $old_variable, - 'required' => TRUE, - ), - ) + else { + $requirements['settings file'] += array( + 'value' => 'settings.php is not writable.', + 'severity' => REQUIREMENT_ERROR, + 'description' => 'Drupal 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="http://drupal.org/server-permissions">online handbook</a>.', ); - drupal_rewrite_settings($settings); } - - // Now remove the cache override. - $settings = settings()->getAll(); - unset($settings['cache']['default']); - new Settings($settings); - $kernel = new DrupalKernel('update', drupal_classloader(), FALSE); - $kernel->boot(); - \Drupal::getContainer()->set('request', $request); - - // Clear the D7 caches, to ensure that for example the theme_registry does not - // take part in the upgrade process. - Drupal::cache('cache')->deleteAll(); + return $requirements; } /** - * Fixes stored include paths to match the "/core" migration. - */ -function update_prepare_stored_includes() { - // Retrieve the currently stored language types. Default to the hardcoded D7 - // values. - $default_language_types = array('language' => TRUE, 'language_content' => FALSE, 'language_url' => FALSE); - $language_types = array_keys(update_variable_get('language_types', $default_language_types)); - - // Update language negotiation settings. - foreach ($language_types as $language_type) { - $negotiation = update_variable_get("language_negotiation_$language_type", array()); - foreach ($negotiation as &$method) { - unset($method['file']); - } - update_variable_set("language_negotiation_$language_type", $negotiation); - } -} - -/** - * Prepares Drupal 8 language changes for the bootstrap if needed. + * Returns whether the minimum schema requirement has been satisfied. + * + * @return array + * A requirements info array. */ -function update_prepare_d8_language() { - if (db_table_exists('languages')) { - \Drupal::moduleHandler()->install(array('language')); - - $languages = db_select('languages', 'l') - ->fields('l') - ->execute(); - $plurals = array(); - $javascript = array(); - $prefixes = array(); - $domains = array(); - foreach ($languages as $language) { - $plurals[$language->language] = array( - 'plurals' => $language->plurals, - 'formula' => $language->formula, - ); - $javascript[$language->language] = $language->javascript; - $prefixes[$language->language] = $language->prefix; - $domains[$language->language] = $language->domain; - } - \Drupal::state()->set('locale.translation.plurals', $plurals); - \Drupal::state()->set('locale.translation.javascript', $javascript); - \Drupal::config('language.negotiation') - ->set('url.prefixes', $prefixes) - ->set('url.domains', $domains) - ->save(); +function update_system_schema_requirements() { + $requirements = array(); - // Drop now unneeded columns. - db_drop_field('languages', 'plurals'); - db_drop_field('languages', 'formula'); - db_drop_field('languages', 'javascript'); - db_drop_field('languages', 'prefix'); - db_drop_field('languages', 'domain'); - db_drop_field('languages', 'native'); - db_drop_field('languages', 'enabled'); + $system_schema = drupal_get_installed_schema_version('system'); - // Rename the languages table to language. - db_rename_table('languages', 'language'); - - // Rename language column to langcode and set it again as the primary key. - if (db_field_exists('language', 'language')) { - db_drop_primary_key('language'); - $langcode_spec = array( - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'description' => "Language code, e.g. 'de' or 'en-US'.", - ); - db_change_field('language', 'language', 'langcode', $langcode_spec, array('primary key' => array('langcode'))); - } - - // Adds the locked column and saves the special languages. - if (!db_field_exists('language', 'locked')) { - $locked_spec = array( - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 0, - 'description' => 'A boolean indicating whether the administrator can edit or delete the language.', - ); - db_add_field('language', 'locked', $locked_spec); - - $max_language_weight = db_query('SELECT MAX(weight) FROM {language}')->fetchField(); - $languages = \Drupal::languageManager()->getDefaultLockedLanguages($max_language_weight); - foreach ($languages as $language) { - db_insert('language') - ->fields(array( - 'langcode' => $language->id, - 'name' => $language->name, - 'weight' => $language->weight, - // These languages are locked, default to enabled. - 'locked' => 1, - )) - ->execute(); - } - } - - // Update the 'language_default' system variable with the langcode change. - $language_default = update_variable_get('language_default'); - if (!empty($language_default)) { - if (isset($language_default->language)) { - $language_default->id = $language_default->language; - unset($language_default->language); - } - unset($language_default->enabled); - // In D8, the 'language_default' is not anymore an object, but an array, - // so make sure that the new value that is saved into this variable is an - // array. - $language_default = (array) $language_default; - $language_default['langcode'] = 'en'; - update_variable_set('language_default', $language_default); - } - - // Convert languages to config entities. - $result = db_query('SELECT * FROM {language}'); - $uuid = \Drupal::service('uuid'); - foreach ($result as $language) { - \Drupal::config('language.entity.' . $language->langcode) - ->set('id', $language->langcode) - ->set('uuid', $uuid->generate()) - ->set('label', $language->name) - ->set('direction', $language->direction) - ->set('weight', $language->weight) - ->set('locked', $language->locked) - ->set('langcode', 'en') - ->save(); - } - - // Add column to track customized string status to locales_target. - // When updating in a non-English language, the locale translation system is - // triggered, which attempts to query string translations already. - if (db_table_exists('locales_target') && !db_field_exists('locales_target', 'customized')) { - $spec = array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, // LOCALE_NOT_CUSTOMIZED - 'description' => 'Boolean indicating whether the translation is custom to this site.', - ); - db_add_field('locales_target', 'customized', $spec); - } - // Add locales_location table to track string locations. - // When updating in a non-English language, this table is used for - // refreshing JavaScript translations. - if (db_table_exists('locales_source') && !db_table_exists('locales_location')) { - $table = array( - 'description' => 'Location information for source strings.', - 'fields' => array( - 'lid' => array( - 'type' => 'serial', - 'not null' => TRUE, - 'description' => 'Unique identifier of this location.', - ), - 'sid' => array( - 'type' => 'int', - 'not null' => TRUE, - 'description' => 'Unique identifier of this string.', - ), - 'type' => array( - 'type' => 'varchar', - 'length' => 50, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The location type (file, config, path, etc).', - ), - 'name' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Type dependent location information (file name, path, etc).', - ), - 'version' => array( - 'type' => 'varchar', - 'length' => 20, - 'not null' => TRUE, - 'default' => 'none', - 'description' => 'Version of Drupal where the location was found.', - ), - ), - 'primary key' => array('lid'), - 'foreign keys' => array( - 'locales_source' => array( - 'table' => 'locales_source', - 'columns' => array('sid' => 'lid'), - ), - ), - 'indexes' => array( - 'string_id' => array('sid'), - 'string_type' => array('sid', 'type'), - ), - ); - - db_create_table('locales_location', $table); - } + $requirements['minimum schema']['title'] = 'Minimum schema version'; + if ($system_schema >= \Drupal::CORE_MINIMUM_SCHEMA_VERSION) { + $requirements['minimum schema'] += array( + 'value' => 'The installed schema version meets the minimum.', + 'description' => 'Schema version: ' . $system_schema, + ); } + else { + $requirements['minimum schema'] += array( + 'value' => 'The installed schema version does not meet the minimum.', + 'severity' => REQUIREMENT_ERROR, + 'description' => 'Your system schema version is ' . $system_schema . '. Updating directly from a schema version prior to 8000 is not supported. You must <a href="https://drupal.org/node/2179269">migrate your site to Drupal 8</a> first.', + ); + } + + return $requirements; } /** - * Performs Drupal 7.x to 8.x required update.php updates. + * Checks update requirements and reports errors and (optionally) warnings. * - * This function runs when update.php is run the first time for 8.x, - * even before updates are selected or performed. It is important - * that if updates are not ultimately performed that no changes are - * made which make it impossible to continue using the prior version. + * @param $skip_warnings + * (optional) If set to TRUE, requirement warnings will be ignored, and a + * report will only be issued if there are requirement errors. Defaults to + * FALSE. */ -function update_fix_d8_requirements() { - if (drupal_get_installed_schema_version('system') < 8000 && !update_variable_get('update_d8_requirements', FALSE)) { - - // Make sure that file.module is enabled as it is required for the user - // picture upgrade path. - \Drupal::moduleHandler()->install(array('file')); - - $schema = array( - 'description' => 'Generic key/value storage table with an expiration.', - 'fields' => array( - 'collection' => array( - 'description' => 'A named collection of key and value pairs.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - ), - 'name' => array( - // KEY is an SQL reserved word, so use 'name' as the key's field name. - 'description' => 'The key of the key/value pair.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - ), - 'value' => array( - 'description' => 'The value of the key/value pair.', - 'type' => 'blob', - 'not null' => TRUE, - 'size' => 'big', - ), - 'expire' => array( - 'description' => 'The time since Unix epoch in seconds when this item expires. Defaults to the maximum possible time.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 2147483647, - ), - ), - 'primary key' => array('collection', 'name'), - 'indexes' => array( - 'all' => array('name', 'collection', 'expire'), - ), +function update_check_requirements($skip_warnings = FALSE) { + // Check requirements of all loaded modules. + $requirements = \Drupal::moduleHandler()->invokeAll('requirements', array('update')); + $requirements += update_system_schema_requirements(); + $requirements += update_settings_file_requirements(); + $severity = drupal_requirements_severity($requirements); + + // If there are errors, always display them. If there are only warnings, skip + // them if the caller has indicated they should be skipped. + if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && !$skip_warnings)) { + update_task_list('requirements'); + drupal_set_title('Requirements problem'); + $status = array( + '#theme' => 'status_report', + '#requirements' => $requirements, ); - db_create_table('key_value_expire', $schema); - - // Views module is required to convert all previously existing listings into - // views configurations. - // Like any other module APIs and services, Views' services are not available - // in update.php. Existing listings are migrated into configuration, using - // the limited standard tools of raw database queries and \Drupal::config(). - \Drupal::moduleHandler()->install(array('views')); - - update_variable_set('update_d8_requirements', TRUE); + $status_report = drupal_render($status); + $status_report .= 'Check the messages and <a href="' . check_url(drupal_requirements_url($severity)) . '">try again</a>.'; + drupal_add_http_header('Content-Type', 'text/html; charset=utf-8'); + $maintenance_page = array( + '#theme' => 'maintenance_page', + '#content' => $status_report, + ); + print drupal_render($maintenance_page); + exit(); } } @@ -985,6 +417,12 @@ function update_get_update_list() { if ($schema_version == SCHEMA_UNINSTALLED || update_check_incompatibility($module)) { continue; } + // Display a requirements error if the user somehow has a schema version + // from the previous Drupal major version. + if ($schema_version < \Drupal::CORE_MINIMUM_SCHEMA_VERSION) { + $ret[$module]['warning'] = '<em>' . $module . '</em> module cannot be updated. Its schema version is ' . $schema_version . ', which is from an earlier major release of Drupal. You will need to <a href="https://drupal.org/node/2127611">migrate the data for this module</a> instead.'; + continue; + } // Otherwise, get the list of updates defined by this module. $updates = drupal_get_schema_versions($module); if ($updates !== FALSE) { @@ -992,12 +430,16 @@ function update_get_update_list() { // are removed, it will == 0. $last_removed = module_invoke($module, 'update_last_removed'); if ($schema_version < $last_removed) { - $ret[$module]['warning'] = '<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.'; + $ret[$module]['warning'] = '<em>' . $module . '</em> module cannot 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.'; continue; } $updates = drupal_map_assoc($updates); foreach (array_keys($updates) as $update) { + if ($update == \Drupal::CORE_MINIMUM_SCHEMA_VERSION) { + $ret[$module]['warning'] = '<em>' . $module . '</em> module cannot be updated. It contains an update numbered as ' . \Drupal::CORE_MINIMUM_SCHEMA_VERSION . ' which is reserved for the earliest installation of a module in Drupal ' . \Drupal::CORE_COMPATIBILITY . ', before any updates. In order to update <em>' . $module . '</em> module, you will need to install a version of the module with valid updates.'; + continue 2; + } if ($update > $schema_version) { // The description for an update comes from its Doxygen. $func = new ReflectionFunction($module . '_update_' . $update); @@ -1146,10 +588,10 @@ function update_get_update_function_list($starting_updates) { * requirement that the first update function needs to run before the second. * For example, consider this graph: * - * system_update_8000 ---> system_update_8001 ---> system_update_8002 + * system_update_8001 ---> system_update_8002 ---> system_update_8003 * - * Visually, this indicates that system_update_8000() must run before - * system_update_8001(), which in turn must run before system_update_8002(). + * Visually, this indicates that system_update_8001() must run before + * system_update_8002(), which in turn must run before system_update_8003(). * * The function takes into account standard dependencies within each module, as * shown above (i.e., the fact that each module's updates must run in numerical @@ -1302,15 +744,15 @@ function update_retrieve_dependencies() { // implementation of hook_update_dependencies() required this // ordering: // - // system_update_8001 ---> user_update_8000 + // system_update_8002 ---> user_update_8001 // // but another module's implementation of the hook required this // one: // - // system_update_8002 ---> user_update_8000 + // system_update_8003 ---> user_update_8001 // - // we record the second one, since system_update_8001() is always - // guaranteed to run before system_update_8002() anyway (within + // we record the second one, since system_update_8002() is always + // guaranteed to run before system_update_8003() anyway (within // an individual module, updates are always run in numerical // order). if (!isset($return[$module][$update][$module_dependency]) || $update_dependency > $return[$module][$update][$module_dependency]) { @@ -1326,207 +768,6 @@ function update_retrieve_dependencies() { return $return; } -/** - * Gets the value of a variable from the database during 7.x-8.x upgrades. - * - * Use this during the 7.x-8.x upgrade path instead of variable_get(). - * - * @param string $name - * The name of the variable. - * @param mixed $default - * The default value of the variable. - * - * @return mixed - * The value of the variable in the database unserialized, or NULL if not set. - * - * @see update_variable_set() - * @see update_variable_del() - * @ingroup config_upgrade - */ -function update_variable_get($name, $default = NULL) { - $result = db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => $name))->fetchField(); - if ($result !== FALSE) { - return unserialize($result); - } - return $default; -} - -/** - * Sets a persistent variable during the 7.x-8.x upgrade path. - * - * Use this during the 7.x-8.x upgrade path instead of variable_set(). - * - * @param string $name - * The name of the variable to set. - * @param mixed $value - * The value to set. This can be any PHP data type; these functions take care - * of serialization as necessary. - * - * @see update_variable_get() - * @see update_variable_del() - * @ingroup config_upgrade - */ -function update_variable_set($name, $value) { - db_merge('variable') - ->key(array( - 'name' => $name, - )) - ->fields(array( - 'value' => serialize($value), - )) - ->execute(); -} - -/** - * Delete a variable from the database during the 7.x-8.x upgrade path. - * - * Use this during the 7.x-8.x upgrade path instead of variable_del(). - * - * @param string $name - * The name of the variable to delete. - * - * @see update_variable_get() - * @see update_variable_set() - * @ingroup config_upgrade - */ -function update_variable_del($name) { - db_delete('variable') - ->condition('name', $name) - ->execute(); -} - -/** - * Updates config with values set on Drupal 7.x. - * - * Provides a generalised method to migrate variables from Drupal 7 to - * Drupal 8's configuration management system. - * - * @param string $config_name - * The configuration object name to retrieve. - * @param array $variable_map - * An associative array that maps old variables names to new configuration - * object keys; e.g.: - * @code - * array('old_variable' => 'new_config.sub_key') - * @endcode - * This would migrate the value contained in variable name 'old_variable' into - * the data key 'new_config.sub_key' of the configuration object $config_name. - */ -function update_variables_to_config($config_name, array $variable_map) { - // Build the new configuration object. - // This potentially loads an existing configuration object, in case another - // update function migrated configuration values into $config_name already. - $config = \Drupal::config($config_name); - $original_data = $config->get(); - - // Extract the module namespace/owner from the configuration object name. - $module = strtok($config_name, '.'); - - // Load and set default configuration values. - $file = new FileStorage(drupal_get_path('module', $module) . '/config'); - if (!$file->exists($config_name)) { - throw new ConfigException("Default configuration file $config_name for $module extension not found but is required to exist."); - } - $default_data = $file->read($config_name); - - // Apply the default values. - $config->setData($default_data); - - // Merge any possibly existing original data into default values. - // Only relevant when being called repetitively on the same config object. - if (!empty($original_data)) { - $config->merge($original_data); - } - - // Fetch existing variables. - $variables = db_query('SELECT name, value FROM {variable} WHERE name IN (:variables)', array(':variables' => array_keys($variable_map)))->fetchAllKeyed(); - - // Set configuration values according to the provided variable mapping. - foreach ($variable_map as $variable_name => $config_key) { - // This function migrates variables regardless of their value, including - // NULL values. Any possibly required customizations need to be performed - // manually, either via variable_set() before calling this function or via - // \Drupal::config() after calling this function. - if (isset($variables[$variable_name])) { - $value = unserialize($variables[$variable_name]); - $config->set($config_key, $value); - } - } - - // Save the configuration object. - $config->save(); - - // Delete the migrated variables. - db_delete('variable')->condition('name', array_keys($variable_map), 'IN')->execute(); -} - -/** - * Installs a default configuration file into the active store. - * - * Provide a generalised method to save a default configuration object for an - * already enabled module or theme as part of an update from Drupal 7 to Drupal - * 8's configuration management system. - * - * @param string $type - * The extension type; e.g., 'module' or 'theme'. - * @param string $config_name - * The configuration object name to retrieve. - * @param string $name - * (optional) The owner of the config. Defaults to NULL, in which case the - * name will be derived from the $config_name. - * - * @return boolean - * True on success, false if config file does not exist. - */ -function update_install_default_config($type, $config_name, $name = NULL) { - // Build the new configuration object. - $config = \Drupal::config($config_name); - - // Extract the extension namespace/owner from the configuration object name. - if (!$name) { - $name = strtok($config_name, '.'); - } - - // Load and set default configuration values. - $file = new FileStorage(drupal_get_path($type, $name) . '/config'); - if (!$file->exists($config_name)) { - return FALSE; - } - - // Apply and save the default values. - $config->setData($file->read($config_name))->save(); - return TRUE; -} - -/** - * Updates 7.x variables to state records. - * - * Provides a generalized method to migrate variables from 7.x to 8.x's - * \Drupal::state() system. - * - * @param array $variable_map - * An associative array that maps old variables names to new state record - * names; e.g.: - * @code - * array('old_variable' => 'extension.new_name') - * @endcode - * This would migrate the value contained in variable name 'old_variable' into - * the state item 'extension.new_name'. - * Non-existing variables and variables with NULL values are omitted. - */ -function update_variables_to_state(array $variable_map) { - foreach ($variable_map as $variable_name => $state_name) { - if (NULL !== $value = update_variable_get($variable_name)) { - \Drupal::state()->set($state_name, $value); - } - } - - // Delete the migrated variables. - db_delete('variable') - ->condition('name', array_keys($variable_map)) - ->execute(); -} - /** * Helper function to update entities with uuid. * diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 0ec88d7dac57..cc689374b433 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -86,6 +86,11 @@ class Drupal { */ const CORE_COMPATIBILITY = '8.x'; + /** + * Core minimum schema version. + */ + const CORE_MINIMUM_SCHEMA_VERSION = 8000; + /** * The currently active container object. * diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index d48697327722..ef7b5e74fce5 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -627,10 +627,13 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // Now install the module's schema if necessary. drupal_install_schema($module); - // Set the schema version to the number of the last update provided - // by the module. + // Set the schema version to the number of the last update provided by + // the module, or the minimum core schema version. + $version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION; $versions = drupal_get_schema_versions($module); - $version = $versions ? max($versions) : SCHEMA_INSTALLED; + if ($versions) { + $version = max(max($versions), $version); + } // Install default configuration of the module. \Drupal::service('config.installer')->installDefaultConfig('module', $module); diff --git a/core/lib/Drupal/Core/Extension/UpdateModuleHandler.php b/core/lib/Drupal/Core/Extension/UpdateModuleHandler.php index 65f26a0bd60d..a8334b84c9f2 100644 --- a/core/lib/Drupal/Core/Extension/UpdateModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/UpdateModuleHandler.php @@ -42,7 +42,7 @@ public function getImplementations($hook) { // Forms do not render without the basic elements in // drupal_common_theme() called from system_theme(). case 'theme': - // user_update_8011() uses public:// to create the image style directory. + // Allow access to stream wrappers. case 'stream_wrappers': return array('system'); @@ -71,10 +71,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { $schema_store = \Drupal::keyValue('system.schema'); $old_schema = array(); foreach ($module_list as $module) { - // Check for initial schema and install it. The schema version of a newly - // installed module is always 0. Using 8000 here would be inconsistent - // since $module_update_8000() may involve a schema change, and we want - // to install the schema as it was before any updates were added. + // Check for initial schema and install it. module_load_install($module); $function = $module . '_schema_0'; if (function_exists($function)) { diff --git a/core/modules/aggregator/aggregator.install b/core/modules/aggregator/aggregator.install index 23e26c07a3ea..e4bef0ebdb19 100644 --- a/core/modules/aggregator/aggregator.install +++ b/core/modules/aggregator/aggregator.install @@ -198,52 +198,3 @@ function aggregator_schema() { return $schema; } - -/** - * Moves aggregator settings from variables to config. - * - * @ingroup config_upgrade - */ -function aggregator_update_8000() { - update_variables_to_config('aggregator.settings', array( - 'aggregator_fetcher' => 'fetcher', - 'aggregator_parser' => 'parser', - 'aggregator_processors' => 'processors', - 'aggregator_allowed_html_tags' => 'items.allowed_html', - 'aggregator_teaser_length' => 'items.teaser_length', - 'aggregator_clear' => 'items.expire', - 'aggregator_summary_items' => 'source.list_max', - )); -} - -/** - * Adds the langcode field to {aggregator_item} and {aggregator_feed}. - */ -function aggregator_update_8001() { - // Add the field. - db_add_field('aggregator_feed', 'langcode', array( - 'description' => 'The {language}.langcode of this feed.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'initial' => Language::LANGCODE_NOT_SPECIFIED, - )); - db_add_field('aggregator_item', 'langcode', array( - 'description' => 'The {language}.langcode of this feed item.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'initial' => Language::LANGCODE_NOT_SPECIFIED, - )); -} - -/** - * Add index on timestamp. - */ -function aggregator_update_8002() { - if (!db_index_exists('aggregator_item', 'timestamp')) { - db_add_index('aggregator_item', 'timestamp', array('timestamp')); - } -} diff --git a/core/modules/block/block.install b/core/modules/block/block.install index e29af112de8c..a53a12005c0c 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -17,352 +17,3 @@ function block_install() { // so before block module runs, there will not be much to alter. module_set_weight('block', -5); } - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Implements hook_update_dependencies(). - */ -function block_update_dependencies() { - // Convert role IDs after User module converted {role}. - $dependencies['block'][8002] = array( - 'user' => 8002, - ); - // Migrate users.data after User module prepared the tables. - $dependencies['block'][8005] = array( - 'user' => 8016, - ); - // Migrate custom blocks after field storage has been reorganized. - $dependencies['block'][8008] = array( - 'field' => 8006, - ); - return $dependencies; -} - -/** - * Block cache is always enabled in 8.x. - * - * @ingroup config_upgrade - */ -function block_update_8000() { - update_variable_del('block_cache'); -} - -/** - * Creates table {block_language} for language visibility settings per block. - */ -function block_update_8001() { - $schema = array( - 'description' => 'Sets up display criteria for blocks based on langcode.', - 'fields' => array( - 'module' => array( - 'type' => 'varchar', - 'length' => 64, - 'not null' => TRUE, - 'description' => "The block's origin module, from {block}.module.", - ), - 'delta' => array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'description' => "The block's unique delta within module, from {block}.delta.", - ), - 'type' => array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'description' => "Language type name. Applied to filter the block by that type.", - ), - 'langcode' => array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'description' => "The machine-readable name of this language from {language}.langcode.", - ), - ), - 'primary key' => array('module', 'delta', 'type', 'langcode'), - ); - db_create_table('block_language', $schema); -} - -/** - * Replace serial role IDs with machine name strings. - * - * @see user_update_8002() - */ -function block_update_8002() { - // Change serial rid column into string. - $column = array( - 'type' => 'varchar', - 'length' => 64, - 'not null' => TRUE, - 'description' => "The user's role ID from {users_roles}.rid.", - ); - db_change_field('block_role', 'rid', 'rid', $column); - - // Rename the built-in serial role IDs into the hardcoded machine names. - db_update('block_role') - ->fields(array('rid' => DRUPAL_ANONYMOUS_RID)) - ->condition('rid', 1) - ->execute(); - db_update('block_role') - ->fields(array('rid' => DRUPAL_AUTHENTICATED_RID)) - ->condition('rid', 2) - ->execute(); -} - -/** - * Increase {block}.title length to 255 characters. - */ -function block_update_8003() { - db_change_field('block', 'title', 'title', array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Custom title for the block. (Empty string will use block default title, - None - will remove the title, text will cause block to use specified title.)', - ) - ); -} - -/** - * Rename default menu names. - */ -function block_update_8004() { - // System menu's new block deltas are prefixed with 'menu-'. - $map = array( - 'navigation' => 'menu-tools', - 'management' => 'menu-admin', - 'user-menu' => 'menu-account', - 'main-menu' => 'menu-main', - ); - foreach ($map as $old => $new) { - db_update('block') - ->condition('module', 'system') - ->condition('delta', $old) - ->fields(array('delta' => $new)) - ->execute(); - db_update('block_language') - ->condition('module', 'system') - ->condition('delta', $old) - ->fields(array('delta' => $new)) - ->execute(); - db_update('block_role') - ->condition('module', 'system') - ->condition('delta', $old) - ->fields(array('delta' => $new)) - ->execute(); - } -} - -/** - * Migrate {users}.data into {users_data}. - */ -function block_update_8005() { - $query = db_select('_d7_users_data', 'ud'); - $query->addField('ud', 'uid'); - $query->addExpression("'block'", 'module'); - $query->addExpression("'block'", 'name'); - // Take over the extracted and serialized value in {_d7_users_data} as-is. - $query->addField('ud', 'value'); - $query->addExpression('1', 'serialized'); - $query->condition('name', 'block'); - - db_insert('users_data') - ->from($query) - ->execute(); - - db_delete('_d7_users_data') - ->condition('name', 'block') - ->execute(); -} - -/** - * Enable the Custom Block module. - */ -function block_update_8006() { - \Drupal::moduleHandler()->install(array('custom_block')); -} - -/** - * Migrate {block_custom} to {custom_block}. - * - * Note this table now resides in custom_block_schema() but for 7.x to 8.x - * upgrades, changes must be made from block module as custom_block module is - * only enabled during upgrade process. - */ -function block_update_8007() { - // Populate the {custom_block} and {custom_block_revision} table. - $results = db_select('block_custom', 'bc')->fields('bc')->execute(); - - $uuid = \Drupal::service('uuid'); - $execute = FALSE; - $block_insert = db_insert('custom_block')->fields(array( - 'id', - 'uuid', - 'info', - 'revision_id', - 'langcode', - 'type', - 'changed', - )); - $revision_insert = db_insert('custom_block_revision')->fields(array( - 'id', - 'revision_id', - 'log', - 'info', - 'changed', - )); - foreach ($results as $block) { - $custom_block = array( - 'id' => $block->bid, - 'uuid' => $uuid->generate(), - 'info' => $block->info, - 'revision_id' => $block->bid, - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'type' => 'basic', - 'changed' => REQUEST_TIME, - ); - $revision = array( - 'id' => $block->bid, - 'revision_id' => $block->bid, - 'info' => $block->info, - 'log' => 'Initial value from 7.x to 8.x upgrade', - 'changed' => REQUEST_TIME, - ); - $block_insert->values($custom_block); - $revision_insert->values($revision); - // We have something to execute. - $execute = TRUE; - } - if ($execute) { - $block_insert->execute(); - $revision_insert->execute(); - } -} - -/** - * Migrate {block_custom}.body and {block_custom}.format to body field. - */ -function block_update_8008() { - $sandbox['#finished'] = 0; - - if (!isset($sandbox['total'])) { - // Initial invocation. - - // First, create the body field. - $body_field = array( - 'name' => 'body', - 'entity_type' => 'custom_block', - 'type' => 'text_with_summary', - 'module' => 'text', - 'cardinality' => 1, - 'schema' => array( - 'columns' => array( - 'value' => array( - 'type' => 'text', - 'size' => 'big', - 'not null' => FALSE, - ), - 'summary' => array( - 'type' => 'text', - 'size' => 'big', - 'not null' => FALSE, - ), - 'format' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - ), - ), - 'indexes' => array( - 'format' => array('format'), - ), - ), - ); - _update_8003_field_create_field($body_field); - - - $instance = array( - 'entity_type' => 'custom_block', - 'bundle' => 'basic', - 'label' => 'Block body', - 'settings' => array('display_summary' => FALSE), - ); - _update_8003_field_create_instance($body_field, $instance); - - module_load_install('entity'); - // Assign form settings for the 'default' form mode. - $form_display = _update_8000_entity_get_form_display('custom_block', 'basic', 'default'); - $form_display->set('content.user_picture', array( - 'type' => 'text_textarea_with_summary', - )) - ->save(); - - // Initialize state for future calls. - $sandbox['last'] = 0; - $sandbox['count'] = 0; - - $query = db_select('block_custom', 'bc'); - $sandbox['total'] = $query->countQuery()->execute()->fetchField(); - - $sandbox['body_field_id'] = $body_field['id']; - } - else { - // Subsequent invocations. - - $found = FALSE; - if ($sandbox['total']) { - // Operate on each block in turn. - $batch_size = 200; - $query = db_select('block_custom', 'bc'); - $query - ->fields('bc', array('bid', 'body', 'format')) - ->condition('bc.bid', $sandbox['last'], '>') - ->orderBy('bc.bid', 'ASC') - ->range(0, $batch_size); - $blocks = $query->execute(); - - // Load the block, set up 'body' and save the field data. - foreach ($blocks as $block) { - $found = TRUE; - - $data = array( - Language::LANGCODE_NOT_SPECIFIED => array( - array( - 'format' => $block->format, - 'value' => $block->body - ) - ) - ); - // This is a core update and no contrib modules are enabled yet, so - // we can assume default field storage for a faster update. - _update_8006_field_write_data_sql('custom_block', 'basic', $block->bid, $block->bid, 'body', $data); - - $sandbox['last'] = $block->bid; - $sandbox['count'] += 1; - } - - $sandbox['#finished'] = min(0.99, $sandbox['count'] / $sandbox['total']); - } - - if (!$found) { - // All blocks are processed. - - // Remove the now-obsolete body info from block_custom. - db_drop_field('block_custom', 'body'); - db_drop_field('block_custom', 'format'); - - // We're done. - $sandbox['#finished'] = 1; - } - } -} - -/** - * @} End of "addtogroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/book/book.install b/core/modules/book/book.install index fb8c225815f9..0b540bd9e453 100644 --- a/core/modules/book/book.install +++ b/core/modules/book/book.install @@ -56,26 +56,3 @@ function book_schema() { return $schema; } - -/** - * Move the Book module settings from variables to config. - * - * @ingroup config_upgrade - */ -function book_update_8000() { - update_variables_to_config('book.settings', array( - 'book_child_type' => 'child_type', - 'book_block_mode' => 'block.navigation.mode', - )); - $allowed_types = update_variable_get('book_allowed_types', FALSE); - if ($allowed_types) { - // Ensure consistent ordering of allowed_types. - // @see book_admin_settings_submit() - sort($allowed_types); - - \Drupal::config('book.settings') - ->set('allowed_types', $allowed_types) - ->save(); - } - -} diff --git a/core/modules/color/color.install b/core/modules/color/color.install index 923f38f0c918..c3f9a74ea9a1 100644 --- a/core/modules/color/color.install +++ b/core/modules/color/color.install @@ -37,31 +37,3 @@ function color_requirements($phase) { return $requirements; } - -/** - * Converts variables to config. - */ -function color_update_8001() { - $themes = db_select('variable', 'v') - ->fields('v', array('name')) - ->condition('v.name', db_like('color_') . '%' . db_like('_palette'), 'LIKE') - ->execute() - ->fetchAllAssoc('name'); - - foreach ($themes as $theme_palette => $theme) { - // Get theme name from color palette variable. - preg_match('/color_(.*)_palette/', $theme_palette, $matches); - $theme_key = $matches[1]; - $config = \Drupal::config('color.' . $theme_key); - $config->set('palette', update_variable_get('color_' . $theme_key . '_palette')); - $config->set('logo', update_variable_get('color_' . $theme_key . '_logo')); - $config->set('stylesheets', update_variable_get('color_' . $theme_key . '_stylesheets')); - $config->set('files', update_variable_get('color_' . $theme_key . '_files')); - // Screenshot is optional. - if (update_variable_get('color_' . $theme_key . '_screenshot')) { - $config->set('screenshot', update_variable_get('color_' . $theme_key . '_screenshot')); - } - $config->save(); - } -} - diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 3d093fb53059..356065fe8091 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -258,457 +258,3 @@ function comment_schema() { return $schema; } - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Implements hook_update_dependencies(). - */ -function comment_update_dependencies() { - // Node comment status cannot be turned into fields until after the fields and - // instances are converted to ConfigEntities. - $dependencies['comment'][8006]['field'] = 8003; - return $dependencies; -} - -/** - * Renames {comment}.language to {comment}.langcode. - */ -function comment_update_8000() { - db_drop_index('comment', 'comment_nid_language'); - $langcode_spec = array( - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'description' => "Language code, e.g. 'de' or 'en-US'.", - ); - db_change_field('comment', 'language', 'langcode', $langcode_spec); - db_add_index('comment', 'comment_nid_langcode', array('nid', 'langcode')); -} - -/** - * Create a UUID column for comments. - */ -function comment_update_8001() { - $spec = array( - 'description' => 'Unique Key: Universally unique identifier for this entity.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - ); - $keys = array( - 'unique keys' => array( - 'uuid' => array('uuid'), - ), - ); - // Account for sites having the contributed UUID module installed. - if (db_field_exists('comment', 'uuid')) { - db_change_field('comment', 'uuid', 'uuid', $spec, $keys); - } - else { - db_add_field('comment', 'uuid', $spec, $keys); - } -} - -/** - * Make *id fields unsigned. - */ -function comment_update_8002() { - db_drop_index('comment', 'comment_num_new'); - db_drop_index('comment', 'comment_nid_langcode'); - db_change_field('comment', 'nid', 'nid', - array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The {node}.nid to which this comment is a reply.', - ), - array('indexes' => array( - 'comment_num_new' => array('nid', 'status', 'created', 'cid', 'thread'), - 'comment_nid_langcode' => array('nid', 'langcode'), - )) - ); - db_drop_index('comment', 'comment_uid'); - db_change_field('comment', 'uid', 'uid', - array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.', - ), - array('indexes' => array( - 'comment_uid' => array('uid'), - )) - ); - - db_drop_index('node_comment_statistics', 'last_comment_uid'); - db_change_field('node_comment_statistics', 'last_comment_uid', 'last_comment_uid', - array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.', - ), - array('indexes' => array( - 'last_comment_uid' => array('last_comment_uid'), - )) - ); -} - -/** - * Generate a UUID for all comments. - */ -function comment_update_8003(&$sandbox) { - if (!isset($sandbox['progress'])) { - $sandbox['progress'] = 0; - $sandbox['last'] = 0; - $sandbox['max'] = db_query('SELECT COUNT(cid) FROM {comment} WHERE uuid IS NULL')->fetchField(); - } - - $cids = db_query_range('SELECT cid FROM {comment} WHERE cid > :cid AND uuid IS NULL ORDER BY cid ASC', 0, 10, array(':cid' => $sandbox['last']))->fetchCol(); - update_add_uuids($sandbox, 'comment', 'cid', $cids); - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); -} - -/** - * Convert variables to state. - */ -function comment_update_8004() { - update_variables_to_state(array( - 'node_cron_comments_scale' => 'comment.node_comment_statistics_scale', - 'comment_maintain_node_statistics' => 'comment.maintain_entity_statistics', - )); -} - -/** - * Update the {comment_node_statistics} and {comment} tables to new structure. - */ -function comment_update_8005(&$sandbox) { - // Drop old indexes. - if (db_index_exists('comment', 'comment_node')) { - // Drop the comment_node foreign key. - db_drop_index('comment', 'comment_node'); - } - db_drop_index('comment', 'comment_num_new'); - db_drop_index('comment', 'comment_nid_langcode'); - - // Add the entity_type and field id columns to comment. - db_add_field('comment', 'entity_type', array( - 'type' => 'varchar', - 'not null' => TRUE, - 'default' => 'node', - 'length' => 255, - 'description' => 'The entity_type of the entity to which this comment is a reply.', - )); - db_add_field('comment', 'field_id', array( - 'type' => 'varchar', - 'not null' => TRUE, - 'default' => 'node__comment', - 'length' => 255, - 'description' => 'The field_id of the field that was used to add this comment.', - )); - // Rename the nid column to entity_id. - db_change_field('comment', 'nid', 'entity_id', array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The entity_id of the entity to which this comment is a reply.', - )); - db_add_index('comment', 'comment_num_new', array( - 'entity_id', - array('entity_type', 32), - array('field_id', 32), - 'status', - 'created', - 'cid', - 'thread' - )); - // Add the comment_entity_langcode index. - db_add_index('comment', 'comment_entity_langcode', array( - 'entity_id', - array('entity_type', 32), - array('field_id', 32), - 'langcode', - )); - - // We need to drop all indexes to make sure their constrains named properly. - db_drop_primary_key('node_comment_statistics'); - if (db_index_exists('node_comment_statistics', 'statistics_node')) { - // Drop the statistics_node foreign key. - db_drop_index('node_comment_statistics', 'statistics_node'); - } - db_drop_index('node_comment_statistics', 'node_comment_timestamp'); - db_drop_index('node_comment_statistics', 'comment_count'); - db_drop_index('node_comment_statistics', 'last_comment_uid'); - - // Rename {node_comment_statistics} to {comment_entity_statistics}. - db_rename_table('node_comment_statistics', 'comment_entity_statistics'); - - // Add the entity_type and field id columns to comment_entity_statistics. - db_add_field('comment_entity_statistics', 'entity_type', array( - 'type' => 'varchar', - 'not null' => TRUE, - 'default' => 'node', - 'length' => 255, - 'description' => 'The entity_type of the entity to which this comment is a reply.', - )); - db_add_field('comment_entity_statistics', 'field_id', array( - 'type' => 'varchar', - 'not null' => TRUE, - 'default' => 'node__comment', - 'length' => 255, - 'description' => 'The field_id of the field that was used to add this comment.', - )); - // Rename the nid column in entity_comment_statistics to entity_id. - db_change_field('comment_entity_statistics', 'nid', 'entity_id', array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The entity_id of the entity to which this comment is a reply.', - )); - - // Add indexes. - db_add_primary_key('comment_entity_statistics', array('entity_id', array('entity_type', 32), array('field_id',32))); - db_add_index('comment_entity_statistics', 'last_comment_timestamp', array('last_comment_timestamp')); - db_add_index('comment_entity_statistics', 'comment_count', array('comment_count')); - db_add_index('comment_entity_statistics', 'last_comment_uid', array('last_comment_uid')); -} - -/** - * Adds comment fields for all node types. - * - * Field instance settings "default_mode", "per_page" and "form_location" are - * preserved to allow migrate contrib modules. - */ -function comment_update_8006(&$sandbox) { - // Entity module update functions are needed to update components of node - // entity display and form display for new comment fields. - module_load_install('entity'); - // Loop over defined node_types. - $node_types = array_keys(_update_7000_node_get_types()); - foreach ($node_types as $node_type) { - // COMMENT_OPEN - $default_value = update_variable_get('comment_' . $node_type, 2); - // Add a default comment field for existing node comments. - $field_name = 'comment_' . $node_type; - $field = array( - // We need one per content type to match the existing comment bundles. - 'id' => 'node.' . $field_name, - 'type' => 'comment', - 'module' => 'comment', - 'name' => $field_name, - 'entity_type' => 'node', - ); - // Make sure field doesn't already exist. - $index = 0; - - // @todo Refactor once https://drupal.org/node/1856972 lands. - while (!\Drupal::config('field.field.node.' . $field['name'])->isNew()) { - // Append a numeric index. - $field['id'] = 'node.' . $field_name . '_' . $index; - $field['name'] = $field_name . '_' . $index; - // Increment index. - $index++; - } - $field_object = new Field($field); - $field['schema'] = CommentItem::schema($field_object); - _update_8003_field_create_field($field); - - // @todo Refactor once https://drupal.org/node/1856972 lands. - if (\Drupal::config("field.instance.node.$node_type." . $field['name'])->isNew()) { - // Add the comment field, setting the instance settings to match those for - // the given node_type. - $instance_settings = array( - // COMMENT_MODE_THREADED - 'default_mode' => update_variable_get('comment_default_mode_' . $node_type, 1), - 'per_page' => update_variable_get('comment_default_per_page_' . $node_type, 50), - // COMMENT_FORM_BELOW - 'form_location' => update_variable_get('comment_form_location_' . $node_type, 1), - // COMMENT_ANONYMOUS_MAYNOT_CONTACT - 'anonymous' => update_variable_get('comment_anonymous_' . $node_type, 0), - 'subject' => update_variable_get('comment_subject_field_' . $node_type, 1), - // DRUPAL_OPTIONAL - 'preview' => update_variable_get('comment_preview_' . $node_type, 1), - ); - $instance = array( - 'id' => "node.$node_type." . $field['name'], - 'entity_type' => 'node', - 'bundle' => $node_type, - 'default_value' => array(array('status' => $default_value)), - 'deleted' => '0', - 'description' => '', - 'label' => 'Comment settings', - 'required' => TRUE, - 'settings' => $instance_settings, - ); - _update_8003_field_create_instance($field, $instance); - } - - // Prepare defaults for the default and full view modes. - $display_options_default = array( - 'label' => 'hidden', - 'type' => 'comment_default', - 'settings' => array(), - 'weight' => 20, - ); - - // Assign display settings for the 'default' and 'full' view modes. - $display = _update_8000_entity_get_display('node', $node_type, 'default'); - $display->set('content.' . $field['name'], $display_options_default) - ->save(); - - $display = _update_8000_entity_get_display('node', $node_type, 'full'); - $display->set('content.' . $field['name'], $display_options_default) - ->save(); - - // Assign widget settings for the 'default' form mode. - $display_options_default = array( - 'type' => 'comment_default', - 'settings' => array(), - 'weight' => 20, - ); - $display = _update_8000_entity_get_form_display('node', $node_type, 'default'); - $display->set('content.' . $field['name'], $display_options_default) - ->save(); - - // Clean up old variables. - update_variable_del('comment_' . $node_type); - update_variable_del('comment_default_mode_' . $node_type); - update_variable_del('comment_default_per_page_' . $node_type); - update_variable_del('comment_anonymous_' . $node_type); - update_variable_del('comment_subject_field_' . $node_type); - update_variable_del('comment_form_location_' . $node_type); - update_variable_del('comment_preview_' . $node_type); - } -} - -/** - * Update existing comment values from node table to field data. - */ -function comment_update_8007(&$sandbox) { - - $types = array_keys(_update_7000_node_get_types()); - // Load each node type in batch and initialize field values for comment field. - if (!isset($sandbox['progress'])) { - $sandbox['progress'] = 0; - $sandbox['current_nid'] = 0; - // We track all node types here. - $sandbox['node_types'] = $types; - // We start with this node type. - $sandbox['node_type'] = array_shift($sandbox['node_types']); - $sandbox['#finished'] = 1; - $sandbox['max'] = db_query('SELECT COUNT(nid) FROM {node}')->fetchField(); - } - - // Set the initial values of comment fields for existing nodes. Note that - // contrib modules will need to handle the upgrade path on their own, as - // they are disabled during core upgrade. - - // Node table will always exist up until here because in 7.x comment - // depends on node. - $nodes = db_select('node', 'n') - ->fields('n', array('nid', 'comment', 'vid', 'langcode')) - ->condition('type', $sandbox['node_type']) - ->condition('nid', $sandbox['current_nid'], '>') - ->range(0, 50) - ->orderBy('nid', 'ASC') - ->execute() - ->fetchAllAssoc('nid'); - - if (count($nodes) > 0) { - $insert = db_insert('node__comment_' . $sandbox['node_type']) - ->fields(array( - 'bundle', - 'entity_id', - 'revision_id', - 'langcode', - 'delta', - 'comment_' . $sandbox['node_type'] . '_status', - )); - $revision = db_insert('node_revision__comment_' . $sandbox['node_type']) - ->fields(array( - 'bundle', - 'entity_id', - 'revision_id', - 'langcode', - 'delta', - 'comment_' . $sandbox['node_type'] . '_status', - )); - - // Update the field name to match the node type. - db_update('comment') - ->fields(array( - 'field_id' => 'node__comment_' . $sandbox['node_type'], - )) - ->condition('entity_id', array_keys($nodes)) - ->execute(); - foreach ($nodes as $nid => $node) { - $insert->values(array( - 'bundle' => $sandbox['node_type'], - 'entity_id' => $nid, - 'revision_id' => $node->vid, - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'delta' => 0, - 'comment_' . $sandbox['node_type'] . '_status' => $node->comment, - )); - $revision->values(array( - 'bundle' => $sandbox['node_type'], - 'entity_id' => $nid, - 'revision_id' => $node->vid, - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'delta' => 0, - 'comment_' . $sandbox['node_type'] . '_status' => $node->comment, - )); - $sandbox['progress']++; - $sandbox['current_nid'] = $nid; - } - $insert->execute(); - $revision->execute(); - // Populate the field name to match the node type. - db_update('comment_entity_statistics') - ->fields(array( - 'field_id' => 'node__comment_' . $sandbox['node_type'], - )) - ->condition('entity_id', array_keys($nodes)) - ->execute(); - } - else { - // Move to the next node type. - $sandbox['node_type'] = array_shift($sandbox['node_types']); - // Reset the current nid pointer. - $sandbox['current_nid'] = 0; - } - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); -} - -/** - * Removes the existing fields. - * - * Data was migrated in comment_update_8007(). - */ -function comment_update_8008(&$sandbox) { - // Remove the {node}.comment field. - db_drop_field('node', 'comment'); - // Remove the {node_revision}.comment field. - db_drop_field('node_revision', 'comment'); -} - -/** - * Remove the comment_block_count variable. - */ -function comment_update_8009() { - update_variable_del('comment_block_count'); -} - -/** - * @} End of "addtogroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/contact/contact.install b/core/modules/contact/contact.install index c3802e78f618..a67134ec6865 100644 --- a/core/modules/contact/contact.install +++ b/core/modules/contact/contact.install @@ -17,94 +17,3 @@ function contact_install() { } \Drupal::config('contact.category.feedback')->set('recipients', array($site_mail))->save(); } - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Implements hook_update_dependencies(). - */ -function contact_update_dependencies() { - // Migrate users.data after User module prepared the tables. - $dependencies['contact'][8003] = array( - 'user' => 8011, - ); - return $dependencies; -} - -/** - * Moves contact setting from variable to config. - * - * @ingroup config_upgrade - */ -function contact_update_8000() { - update_variables_to_config('contact.settings', array( - 'contact_default_status' => 'user_default_enabled', - 'contact_threshold_limit' => 'flood.limit', - 'contact_threshold_window' => 'flood.interval', - )); -} - -/** - * Migrate contact categories into configuration. - * - * @ingroup config_upgrade - */ -function contact_update_8001() { - $uuid = \Drupal::service('uuid'); - $result = db_query('SELECT * FROM {contact}'); - foreach ($result as $category) { - // Take over the category's serial ID as new machine name. - $category->id = $category->cid; - // Save default category setting. - if ($category->selected) { - \Drupal::config('contact.settings') - ->set('default_category', $category->id) - ->save(); - } - // Save the config object. - \Drupal::config('contact.category.' . $category->id) - ->set('id', $category->id) - ->set('uuid', $uuid->generate()) - ->set('label', $category->category) - ->set('recipients', explode(',', $category->recipients)) - ->set('reply', $category->reply) - ->set('weight', $category->weight) - ->set('langcode', Language::LANGCODE_NOT_SPECIFIED) - ->save(); - } -} - -/** - * Drop the {contact} table. - */ -function contact_update_8002() { - db_drop_table('contact'); -} - -/** - * Migrate {users}.data into {users_data}. - */ -function contact_update_8003() { - $query = db_select('_d7_users_data', 'ud'); - $query->condition('name', 'contact'); - $query->addField('ud', 'uid'); - $query->addExpression("'contact'", 'module'); - $query->addExpression("'enabled'", 'name'); - $query->addField('ud', 'value', 'value'); - $query->addExpression(1, 'serialized'); - - db_insert('users_data') - ->from($query) - ->execute(); - db_delete('_d7_users_data') - ->condition('name', 'contact') - ->execute(); -} - -/** - * @} End of "defgroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/dblog/dblog.install b/core/modules/dblog/dblog.install index a2e014402c96..b7454c133415 100644 --- a/core/modules/dblog/dblog.install +++ b/core/modules/dblog/dblog.install @@ -92,41 +92,3 @@ function dblog_schema() { return $schema; } - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Update settings to the new configuration system. - */ -function dblog_update_8000() { - update_variables_to_config('dblog.settings', array( - 'dblog_row_limit' => 'row_limit', - )); -} - -/** - * Make *id fields unsigned. - */ -function dblog_update_8001() { - db_drop_index('watchdog', 'uid'); - db_change_field('watchdog', 'uid', 'uid', - array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The {users}.uid of the user who triggered the event.', - ), - array('indexes' => array( - 'uid' => array('uid'), - )) - ); -} - -/** - * @} End of "addtogroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/entity/entity.install b/core/modules/entity/entity.install deleted file mode 100644 index 5ed9e6bc100b..000000000000 --- a/core/modules/entity/entity.install +++ /dev/null @@ -1,86 +0,0 @@ -<?php - -/** - * @file - * Install, update and uninstall functions for the entity module. - */ - -/** - * Returns the raw configuration object for an EntityDisplay entity. - * - * The function returns the existing configuration entry if it exists, or - * creates a fresh structure. - * - * @param string $entity_type - * The entity type. - * @param string $bundle - * The bundle name. - * @param string $view_mode - * The view mode. - * - * @return \Drupal\Core\Config\Config - * The configuration object. - */ -function _update_8000_entity_get_display($entity_type, $bundle, $view_mode) { - $id = $entity_type . '.' . $bundle . '.' . $view_mode; - $config = \Drupal::config("entity.display.$id"); - if ($config->get()) { - return $config; - } - - // Initialize a fresh structure. - $uuid = \Drupal::service('uuid'); - $properties = array( - 'id' => $id, - 'uuid' => $uuid->generate(), - 'targetEntityType' => $entity_type, - 'bundle' => $bundle, - 'mode' => $view_mode, - 'content' => array(), - 'status' => TRUE, - ); - foreach ($properties as $key => $value) { - $config->set($key, $value); - } - return $config; -} - -/** - * Returns the raw configuration object for an EntityFormDisplay entity. - * - * The function returns the existing configuration entry if it exists, or - * creates a fresh structure. - * - * @param string $entity_type - * The entity type. - * @param string $bundle - * The bundle name. - * @param string $form_mode - * The form mode. - * - * @return \Drupal\Core\Config\Config - * The configuration object. - */ -function _update_8000_entity_get_form_display($entity_type, $bundle, $form_mode) { - $id = $entity_type . '.' . $bundle . '.' . $form_mode; - $config = \Drupal::config("entity.form_display.$id"); - if ($config->get()) { - return $config; - } - - // Initialize a fresh structure. - $uuid = \Drupal::service('uuid'); - $properties = array( - 'id' => $id, - 'uuid' => $uuid->generate(), - 'targetEntityType' => $entity_type, - 'bundle' => $bundle, - 'mode' => $form_mode, - 'content' => array(), - 'status' => TRUE, - ); - foreach ($properties as $key => $value) { - $config->set($key, $value); - } - return $config; -} diff --git a/core/modules/field/field.install b/core/modules/field/field.install deleted file mode 100644 index 13aa45c4ed0e..000000000000 --- a/core/modules/field/field.install +++ /dev/null @@ -1,585 +0,0 @@ -<?php - -/** - * @file - * Install, update, and uninstall functions for the Field module. - */ - -use Drupal\Core\Entity\FieldableDatabaseStorageController; -use Drupal\field\Entity\Field; - -/** - * Creates a field by writing directly to configuration. - * - * Upgrades using this function need to use hook_update_dependencies() to ensure - * they get executed after field_update_8003(). - * - * @param array $field_config - * An array of field properties. Required properties are: - * - 'id': The field id (machine name). - * - 'type': The field type. - * - 'module': The name of the module providing the field type. - * - 'schema': The field schema, in the same format as - * \Drupal\Core\Field\ConfigFieldItemListInterface::schema(). - * - * @ingroup update_api - */ -function _update_8003_field_create_field(array &$field_config) { - $uuid = \Drupal::service('uuid'); - - // Merge in default values. - $field_config += array( - 'id' => $field_config['entity_type'] . '.' . $field_config['name'], - 'uuid' => $uuid->generate(), - 'cardinality' => 1, - 'translatable' => FALSE, - 'locked' => FALSE, - 'settings' => array(), - 'indexes' => array(), - 'status' => 1, - 'langcode' => 'und', - ); - - // Save in config. - \Drupal::config('field.field.' . $field_config['id']) - ->setData($field_config) - ->save(); - - // Create storage for the field. This requires a field entity, but cannot use - // the regular entity_create() function here. - $schema = FieldableDatabaseStorageController::_fieldSqlSchema(new Field($field_config), $field_config['schema']); - foreach ($schema as $name => $table) { - db_create_table($name, $table); - } -} - -/** - * Writes a field instance directly to configuration. - * - * Upgrades using this function need to use hook_update_dependencies() to ensure - * they get executed after field_update_8003(). - * - * @param array $field_config - * An array of field properties. - * @param array $instance_config - * An array of field instance properties. - * - * @ingroup update_api - */ -function _update_8003_field_create_instance(array $field_config, array &$instance_config) { - $uuid = \Drupal::service('uuid'); - - // Merge in defaults. - $instance_config += array( - 'id' => $instance_config['entity_type'] . '.' . $instance_config['bundle'] . '.' . $field_config['name'], - 'description' => '', - 'required' => FALSE, - 'uuid' => $uuid->generate(), - 'field_uuid' => $field_config['uuid'], - 'field_name' => $field_config['name'], - 'field_type' => $field_config['type'], - 'default_value' => array(), - 'default_value_function' => '', - 'settings' => array(), - 'widget' => array(), - 'status' => 1, - 'langcode' => 'und', - ); - - // Save in config. - \Drupal::config('field.instance.' . $instance_config['id']) - ->setData($instance_config) - ->save(); -} - -/** - * Writes field data directly to SQL storage. - * - * @param string $entity_type - * The entity type. - * @param string $bundle - * The bundle. - * @param int $entity_id - * The entity ID. - * @param int $revision_id - * The entity revision ID. - * @param string $field_name - * The field name. - * @param array $data - * The field values, as an array keyed by langcode, delta and property name. - * - * @ingroup update_api - */ -function _update_8006_field_write_data_sql($entity_type, $bundle, $entity_id, $revision_id, $field_name, array $data) { - if (!isset($revision_id)) { - $revision_id = $entity_id; - } - - $field_config = \Drupal::config("field.field.$entity_type.$field_name"); - $field = new Field($field_config); - - $table_name = FieldableDatabaseStorageController::_fieldTableName($field); - $revision_name = FieldableDatabaseStorageController::_fieldRevisionTableName($field); - - db_delete($table_name) - ->condition('entity_id', $entity_id) - ->execute(); - db_delete($revision_name) - ->condition('entity_id', $entity_id) - ->condition('revision_id', $revision_id) - ->execute(); - - $columns = array(); - foreach ($data as $langcode => $items) { - foreach ($items as $delta => $item) { - $record = array( - 'entity_id' => $entity_id, - 'revision_id' => $revision_id, - 'bundle' => $bundle, - 'delta' => $delta, - 'langcode' => $langcode, - ); - foreach ($item as $column => $value) { - $record[FieldableDatabaseStorageController::_fieldColumnName($field_name, $column)] = $value; - } - - $records[] = $record; - // Record the columns used. - $columns += $record; - } - } - - if ($columns) { - $query = db_insert($table_name)->fields(array_keys($columns)); - $revision_query = db_insert($revision_name)->fields(array_keys($columns)); - foreach ($records as $record) { - $query->values($record); - $revision_query->values($record); - } - $query->execute(); - $revision_query->execute(); - } -} - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Empty update - moved into field_update_8003(). - */ -function field_update_8001() { -} - -/** - * Migrate all instance widget and display settings to configuration. - * - * @ingroup config_upgrade - */ -function field_update_8002() { - $form_displays = $displays = array(); - module_load_install('entity'); - - $query = db_select('field_config_instance', 'fc')->fields('fc'); - foreach ($query->execute() as $record) { - // Unserialize the data array and start investigating the display key - // which holds the configuration of this instance for all view modes. - $data = unserialize($record->data); - - // Skip field instances that were created directly with the new API earlier - // in the upgrade path. - if (!isset($data['widget']) && !isset($data['display'])) { - continue; - } - - // Do not place deleted fields in entity displays. - if (empty($record->deleted)) { - // Migrate 'widget' settings. - if (isset($data['widget'])) { - $widget_options = $data['widget']; - // Determine name and create initial entry in the $form_displays array. - $form_display_id = $record->entity_type . '.' . $record->bundle . '.default'; - if (!isset($form_displays[$form_display_id])) { - $form_displays[$form_display_id] = _update_8000_entity_get_form_display($record->entity_type, $record->bundle, 'default'); - } - - // We do not need the 'module' key anymore. - unset($widget_options['module']); - $form_displays[$form_display_id]->set("content.$record->field_name", $widget_options); - } - - // Migrate 'display' settings. - if (isset($data['display'])) { - foreach ($data['display'] as $view_mode => $display_options) { - // Determine name and create initial entry in the $displays array if it - // does not exist yet. - $display_id = $record->entity_type . '.' . $record->bundle . '.' . $view_mode; - if (!isset($displays[$display_id])) { - $displays[$display_id] = _update_8000_entity_get_display($record->entity_type, $record->bundle, $view_mode); - } - - // The display object does not store hidden fields. - if ($display_options['type'] != 'hidden') { - // We do not need the 'module' key anymore. - unset($display_options['module']); - $displays[$display_id]->set("content.$record->field_name", $display_options); - } - } - } - } - - // Remove the 'widget' and 'display' keys and save the record back into the - // table. - unset($data['display'], $data['widget']); - db_update('field_config_instance') - ->condition('id', $record->id) - ->fields(array( - 'data' => serialize($data), - )) - ->execute(); - } - - // Migration of the content of the old 'bundle_settings_*'' variables. - // Avoid calling entity_get_info() by fetching the relevant variables - // directly in the variable table. - $variables = array_map('unserialize', db_query("SELECT name, value FROM {variable} WHERE name LIKE '%field_bundle_settings_%'")->fetchAllKeyed()); - foreach ($variables as $variable_name => $variable_value) { - if (preg_match('/field_bundle_settings_(.*)__(.*)/', $variable_name, $matches)) { - $entity_type = $matches[1]; - $bundle = $matches[2]; - - // Migrate form settings for extra fields. - if (isset($variable_value['extra_fields']['form'])) { - foreach ($variable_value['extra_fields']['form'] as $field_name => $field_settings) { - // Determine name and create initial entry in the $form_displays - // array if it does not exist yet. - $form_display_id = $entity_type . '.' . $bundle . '.default'; - if (!isset($form_displays[$form_display_id])) { - $form_displays[$form_display_id] = _update_8000_entity_get_form_display($entity_type, $bundle, 'default'); - } - $form_displays[$form_display_id]->set("content.$field_name", $field_settings); - } - } - - // Migrate display settings for extra fields. - if (isset($variable_value['extra_fields']['display'])) { - foreach ($variable_value['extra_fields']['display'] as $field_name => $field_settings) { - foreach ($field_settings as $view_mode => $display_options) { - // Determine name and create initial entry in the $displays array - // if it does not exist yet. - $display_id = $entity_type . '.' . $bundle . '.' . $view_mode; - if (!isset($displays[$display_id])) { - $displays[$display_id] = _update_8000_entity_get_display($entity_type, $bundle, $view_mode); - } - - // Set options in the display. - $new_options = array('visible' => $display_options['visible']); - // The display object only stores the weight for 'visible' extra - // fields. - if ($display_options['visible']) { - $new_options['weight'] = $display_options['weight']; - } - $displays[$display_id]->set("content.$field_name", $new_options); - } - } - } - - // Migrate view mode settings. - if (isset($variable_value['view_modes'])) { - foreach ($variable_value['view_modes'] as $view_mode => $view_mode_settings) { - // Determine name and create initial entry in the $displays array - // if it does not exist yet. - $display_id = $entity_type . '.' . $bundle . '.' . $view_mode; - if (!isset($displays[$display_id])) { - $displays[$display_id] = _update_8000_entity_get_display($entity_type, $bundle, $view_mode); - } - $displays[$display_id]->set('status', $view_mode_settings['custom_settings']); - } - } - - // Remove the variable. - update_variable_del($variable_name); - } - } - - // Save the form displays to configuration. - foreach ($form_displays as $config) { - $config->save(); - } - - // Save the displays to configuration. - foreach ($displays as $config) { - $config->save(); - } -} - -/** - * Convert fields and instances to config. - */ -function field_update_8003() { - - $uuid = \Drupal::service('uuid'); - $state = \Drupal::state(); - $deleted_fields = $state->get('field.field.deleted') ?: array(); - $deleted_instances = $state->get('field.instance.deleted') ?: array(); - - $field_data = array(); - - // Migrate field definitions. - $records = db_query("SELECT DISTINCT entity_type, fc.* FROM {field_config} fc INNER JOIN {field_config_instance} fci ON fc.id = fci.field_id")->fetchAll(PDO::FETCH_ASSOC); - foreach ($records as $record) { - $record['data'] = unserialize($record['data']); - - $config = array( - 'id' => $record['entity_type'] . '.' . $record['field_name'], - 'name' => $record['field_name'], - 'uuid' => $uuid->generate(), - 'type' => $record['type'], - 'module' => $record['module'], - 'entity_type' => $record['entity_type'], - 'settings' => $record['data']['settings'], - 'locked' => $record['locked'], - 'cardinality' => $record['cardinality'], - 'translatable' => $record['translatable'], - 'indexes' => $record['data']['indexes'] ?: array(), - 'status' => 1, - 'langcode' => 'und', - ); - - // Reassign all list.module fields to be controlled by options.module. - if ($config['module'] == 'list') { - $config['module'] = 'options'; - } - - // Save in either config or state. - if (!$record['deleted']) { - \Drupal::config('field.field.' . $config['id']) - ->setData($config) - ->save(); - } - else { - $config['deleted'] = TRUE; - $deleted_fields[$config['uuid']] = $config; - // This will not be saved but the DatabaseStorageController helpers need - // the field object. - $field = new Field($config); - // Additionally, rename the data tables for deleted fields. - $tables = array( - "field_deleted_data_{$record['id']}" => 'old_' . FieldableDatabaseStorageController::_fieldTableName($field), - "field_deleted_revision_{$record['id']}" => 'old_' . FieldableDatabaseStorageController::_fieldRevisionTableName($field), - ); - foreach ($tables as $table_old => $table_new) { - if (db_table_exists($table_old)) { - db_rename_table($table_old, $table_new); - } - } - } - - // Store the UUID and field type, they will be used when processing - // instances. - $field_data[$record['entity_type'] . ':' . $record['id']] = array( - 'uuid' => $config['uuid'], - 'type' => $record['type'], - 'name' => $record['field_name'], - ); - } - - // Migrate instance definitions. - $records = db_query("SELECT * FROM {field_config_instance}")->fetchAll(PDO::FETCH_ASSOC); - foreach ($records as $record) { - $record['data'] = unserialize($record['data']); - - $field_data_key = $record['entity_type'] . ':' . $record['field_id']; - $config = array( - 'id' => $record['entity_type'] . '.' . $record['bundle'] . '.' . $record['field_name'], - 'uuid' => $uuid->generate(), - 'field_uuid' => $field_data[$field_data_key]['uuid'], - 'field_name' => $field_data[$field_data_key]['name'], - 'field_type' => $field_data[$field_data_key]['type'], - 'entity_type' => $record['entity_type'], - 'bundle' => $record['bundle'], - 'label' => $record['data']['label'], - 'description' => $record['data']['description'], - 'required' => $record['data']['required'], - 'default_value' => isset($record['data']['default_value']) ? $record['data']['default_value'] : array(), - 'default_value_function' => isset($record['data']['default_value_function']) ? $record['data']['default_value_function'] : '', - 'settings' => $record['data']['settings'], - 'status' => 1, - 'langcode' => 'und', - ); - - // Save in either config or state. - if (!$record['deleted']) { - \Drupal::config('field.instance.' . $config['id']) - ->setData($config) - ->save(); - } - else { - $config['deleted'] = TRUE; - $deleted_instances[$config['uuid']] = $config; - } - - // Update {file_usage} table in case this instance has a default image. - if (!empty($config['settings']['default_image'])) { - db_update('file_usage') - ->fields(array('id' => $config['field_uuid'])) - ->condition('type', 'default_image') - ->condition('module', 'image') - ->condition('id', $record['field_id']) - ->condition('fid', $config['settings']['default_image']) - ->execute(); - } - } - - // Save the deleted fields and instances in state. - $state->set('field.field.deleted', $deleted_fields); - $state->set('field.instance.deleted', $deleted_instances); -} - -/** - * Moves field_language_fallback to config. - * - * @ingroup config_upgrade - */ -function field_update_8004() { - // Do nothing: the former update code has been moved to locale_update_8018(). -} - -/** - * Removes the 'user_register_form' setting from field instances and populates - * the user.user.register form display. - */ -function field_update_8005() { - $uuid = \Drupal::service('uuid'); - - $user_default_form_display = \Drupal::config('entity.form_display.user.user.default'); - $user_register_config_data = array( - 'id' => 'user.user.register', - 'uuid' => $uuid->generate(), - 'targetEntityType' => 'user', - 'bundle' => 'user', - 'mode' => 'register', - 'content' => array(), - ); - foreach (config_get_storage_names_with_prefix('field.instance.') as $config_id) { - $instance_config = \Drupal::config($config_id); - if ($instance_config->get('entity_type') == 'user' && $instance_config->get('settings.user_register_form')) { - list(, , $field_id) = explode('.', $instance_config->get('id')); - $user_register_config_data['content'][$field_id] = $user_default_form_display->get('content.' . $field_id); - } - $settings = $instance_config->get('settings'); - unset($settings['user_register_form']); - $instance_config->set('settings', $settings)->save(); - } - - // Save the new 'register' form display. - \Drupal::config('entity.form_display.user.user.register') - ->setData($user_register_config_data) - ->save(); -} - - -/** - * Splits the field storage tables by entity type and also migrate langcode. - */ -function field_update_8006(&$sandbox) { - // Get field definitions from config, and deleted fields from state system. - $config_names = config_get_storage_names_with_prefix('field.field.'); - $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); - // Ditch UUID keys, we will iterate through deleted fields using a numeric - // index. - $deleted_fields = array_values($deleted_fields); - - if (empty($config_names) && empty($deleted_fields)) { - return; - } - - if (!isset($sandbox['index'])) { - $sandbox['index'] = 0; - $sandbox['max'] = count($config_names) + count($deleted_fields); - } - - // Retrieve the next field definition. When the index exceeds the number of - // 'configuration' fields, use it to iterate on deleted fields. - if (isset($config_names[$sandbox['index']])) { - $field_config = \Drupal::config($config_names[$sandbox['index']])->get(); - } - else { - $field_config = $deleted_fields[$sandbox['index'] - count($config_names)]; - } - - // Prepare updated schema data structures. - $field = new Field($field_config); - $tables = array( - array( - 'old_table' => 'field_data_' . $field_config['name'], - 'new_table' => FieldableDatabaseStorageController::_fieldTableName($field), - 'primary_key' => array( - 'entity_id', - 'deleted', - 'delta', - 'langcode', - ), - ), - array( - 'old_table' => 'field_revision_' . $field_config['name'], - 'new_table' => FieldableDatabaseStorageController::_fieldRevisionTableName($field), - 'primary_key' => array( - 'entity_id', - 'revision_id', - 'deleted', - 'delta', - 'langcode', - ), - ), - ); - - // Move the field data to the new table. - foreach ($tables as $table_data) { - // Split data from the old "per field" table to the new "per entity type and - // field" table. - $new_table = $table_data['new_table']; - $original_table = empty($field_config['deleted']) ? $table_data['old_table'] : 'old_' . $new_table; - if (db_table_exists($original_table)) { - // Create the new table, with the same schema as the old one. - if (!db_table_exists($new_table)) { - db_copy_table_schema($original_table, $new_table); - } - // Copy relevant rows. - $from_query = db_select($original_table, 'original') - ->fields('original') - ->condition('entity_type', $field_config['entity_type']); - db_insert($new_table) - ->from($from_query) - ->execute(); - // Drop the 'entity_type' column and previous primary key. - db_drop_primary_key($new_table); - db_drop_field($new_table, 'entity_type'); - // Rename 'language' to 'langcode'. Tables created during the upgrade - // before this update function might already have the langcode column. - if (db_field_exists($new_table, 'language')) { - db_drop_index($new_table, 'language'); - db_change_field($new_table, 'language', 'langcode', array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'default' => '', - )); - db_add_index($new_table, 'langcode', array('langcode')); - } - // Create new primary key. - db_add_primary_key($new_table, $table_data['primary_key']); - } - } - - $sandbox['index']++; - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['index'] / $sandbox['max']); -} - - - -/** - * @} End of "addtogroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/field_ui/field_ui.install b/core/modules/field_ui/field_ui.install deleted file mode 100644 index 604660bb56f3..000000000000 --- a/core/modules/field_ui/field_ui.install +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -/** - * @file - * Install, update, and uninstall functions for the Field UI module. - */ - -/** - * Upgrade Field UI permissions. - */ -function field_ui_update_8001() { - $replace = array( - 'administer comments' => array( - 'administer comments', - 'administer comment fields', - 'administer comment display', - ), - 'administer content types' => array( - 'administer content types', - 'administer node fields', - 'administer node display', - ), - 'administer users' => array( - 'administer users', - 'administer user fields', - 'administer user display', - ), - 'administer taxonomy' => array( - 'administer taxonomy', - 'administer taxonomy_term fields', - 'administer taxonomy_term display', - ), - ); - update_replace_permissions($replace); -} - -/** - * Installs default config for Field UI. - * - * @ingroup config_upgrade - */ -function field_ui_update_8002() { - update_install_default_config('module', 'field_ui.settings'); -} diff --git a/core/modules/file/file.install b/core/modules/file/file.install index 8fd5a37bc8c1..5d5f6c56f71b 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -206,124 +206,3 @@ function file_requirements($phase) { return $requirements; } - -/** - * Implements hook_update_dependencies(). - */ -function file_update_dependencies() { - // Convert fields and instances to ConfigEntities after the {file_usage}.id - // column has moved to varchar. - $dependencies['field'][8003] = array( - 'file' => 8001, - ); - - // Convert the 'fid' column of file fields to 'target_id' after the field - // tables have been reorganized. - $dependencies['file'][8003] = array( - 'field' => 8006, - ); - return $dependencies; -} - -/** -* Converts default_file_main variable to config. -* -* @ingroup config_upgrade -*/ -function file_update_8000() { - update_variables_to_config('file.settings', array( - 'file_description_type' => 'description.type', - 'file_description_length'=>'description.length', - 'file_icon_directory'=>'icon.directory', - )); -} - -/* - * Convert the 'id' column in {file_usage} to accept UUIDs. - */ -function file_update_8001() { - $spec = array( - 'description' => 'The primary key of the object using the file.', - 'type' => 'varchar', - 'length' => 64, - 'not null' => TRUE, - 'default' => '', - ); - db_change_field('file_usage', 'id', 'id', $spec); -} - -/** - * Convert the 'module' column in {file_usage} to the maximum shortname length. - */ -function file_update_8002() { - if (db_field_exists('file_usage', 'module')) { - $spec = array( - 'description' => 'The name of the module that is using the file.', - 'type' => 'varchar', - 'length' => 50, - 'not null' => TRUE, - 'default' => '', - ); - db_change_field('file_usage', 'module', 'module', $spec); - } -} - -/** - * Update file field tables to use target_id instead of fid. - */ -function file_update_8003() { - foreach (config_get_storage_names_with_prefix('field.field.') as $config_name) { - $field_config = \Drupal::config($config_name); - // Only update file fields that use the default SQL storage. - if (in_array($field_config->get('type'), array('file', 'image'))) { - $field = new Field($field_config->get()); - - if (db_table_exists(FieldableDatabaseStorageController::_fieldTableName($field))) { - $tables = array( - FieldableDatabaseStorageController::_fieldTableName($field), - FieldableDatabaseStorageController::_fieldRevisionTableName($field), - ); - - foreach ($tables as $table_name) { - // Skip fields which were created during the upgrade process. - if (!db_field_exists($table_name, $field->name . '_fid')) { - continue 2; - } - - db_change_field($table_name, $field->name . '_fid', $field->name . '_target_id', array( - 'description' => 'The ID of the target entity.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - )); - - // Change the index. - db_drop_index($table_name, $field->name . '_fid'); - db_add_index($table_name, $field->name . '_target_id', array($field->name . '_target_id')); - } - - // Update the indexes in field config as well. - $indexes = $field_config->get('indexes'); - unset($indexes['fid']); - $indexes['target_id'] = array('target_id'); - $field_config->set('indexes', $indexes); - $field_config->save(); - } - } - } -} - -/* - * Convert the 'filesize' column in {file_managed} to a bigint. - */ -function file_update_8004() { - $spec = array( - 'description' => 'The size of the file in bytes.', - 'type' => 'int', - 'size' => 'big', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ); - db_change_field('file_managed', 'filesize', 'filesize', $spec); -} diff --git a/core/modules/filter/filter.install b/core/modules/filter/filter.install deleted file mode 100644 index 7d0212da9ead..000000000000 --- a/core/modules/filter/filter.install +++ /dev/null @@ -1,60 +0,0 @@ -<?php - -/** - * @file - * Install, update, and uninstall functions for the Filter module. - */ - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Moves filter_fallback settings from variable to config. - * - * @ingroup config_upgrade - */ -function filter_update_8000() { - update_variables_to_config('filter.settings', array( - 'filter_fallback_format' => 'fallback_format', - )); -} - -/** - * Migrate filter formats into configuration. - * - * @ingroup config_upgrade - */ -function filter_update_8001() { - $uuid = \Drupal::service('uuid'); - $result = db_query('SELECT format, name, cache, status, weight FROM {filter_format}', array(), array('fetch' => PDO::FETCH_ASSOC)); - foreach ($result as $format) { - $id = $format['format']; - - // Generate a UUID. - $format['uuid'] = $uuid->generate(); - - // Retrieve and prepare all filters. - $filters = db_query('SELECT name, module, status, weight, settings FROM {filter} WHERE format = :format ORDER BY weight, module, name', array( - ':format' => $id, - ), array('fetch' => PDO::FETCH_ASSOC))->fetchAllAssoc('name'); - foreach ($filters as &$filter) { - // The filter name is used as key only. - unset($filter['name']); - $filter['settings'] = unserialize($filter['settings']); - } - $format['filters'] = $filters; - $format['status'] = (bool) $format['status']; - - // Save the config object. - $config = \Drupal::config('filter.format.' . $id); - $config->setData($format); - $config->save(); - } -} - -/** - * @} End of "defgroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 257972d4b68d..e13002aea818 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -253,138 +253,3 @@ function forum_schema() { function forum_update_last_removed() { return 7003; } - -/** - * Moves forum settings from variable to config. - * - * @ingroup config_upgrade - */ -function forum_update_8000() { - $map = db_query('SELECT vid, machine_name FROM {taxonomy_vocabulary}')->fetchAllKeyed(); - $forum_vid = update_variable_get('forum_nav_vocabulary', FALSE); - if (!empty($map[$forum_vid])) { - // Update the variable to reference the machine name instead of the vid. - update_variable_set('forum_nav_vocabulary', $map[$forum_vid]); - } - update_variables_to_config('forum.settings', array( - 'forum_hot_topic' => 'topics.hot_threshold', - 'forum_per_page' => 'topics.page_limit', - 'forum_order' => 'topics.order', - 'forum_nav_vocabulary' => 'vocabulary', - 'forum_block_num_active' => 'block.active.limit', - 'forum_block_num_new' => 'block.new.limit', - )); -} - -/** - * Implements hook_update_dependencies(). - */ -function forum_update_dependencies() { - // Convert containers to field after the fields and instances are converted to - // ConfigEntities. - $dependencies['forum'][8001] = array( - 'field' => 8003, - 'taxonomy' => 8007, - ); - return $dependencies; -} - -/** - * Adds the forum_container field and copies the values over. - */ -function forum_update_8001() { - $vocabulary = config('forum.settings')->get('vocabulary'); - // Create the field and instance. - $field = array( - 'id' => 'taxonomy_term.forum_container', - 'name' => 'forum_container', - 'entity_type' => 'taxonomy_term', - 'module' => 'options', - 'type' => 'list_boolean', - 'cardinality' => 1, - 'locked' => TRUE, - 'indexes' => array(), - 'settings' => array( - 'allowed_values' => array('', ''), - 'allowed_values_function' => '', - ), - 'schema' => array( - 'columns' => array( - 'value' => array( - 'type' => 'int', - 'not null' => FALSE, - ), - ), - 'indexes' => array(), - 'foreign keys' => array(), - ), - ); - _update_8003_field_create_field($field); - - $instance = array( - 'id' => 'taxonomy_term.' . $vocabulary . '.forum_container', - 'entity_type' => 'taxonomy_term', - 'label' => 'Container', - 'bundle' => $vocabulary, - 'description' => '', - 'required' => TRUE, - 'settings' => array(), - 'default_value' => array('value' => 0), - ); - _update_8003_field_create_instance($field, $instance); -} - -/** - * Migrate forum containers from variable to field values. - */ -function forum_update_8002(&$sandbox) { - // Initialize total values to process. - if (!isset($sandbox['total'])) { - $containers = update_variable_get('forum_containers', array()); - $vocabulary = config('forum.settings')->get('vocabulary'); - $sandbox['containers'] = $containers; - $sandbox['vocabulary'] = $vocabulary; - $sandbox['total'] = count($containers); - $sandbox['processed'] = 0; - } - - if ($sandbox['total']) { - // Retrieve next 20 containers to migrate. - $containers = array_splice($containers, $sandbox['processed'], 20); - foreach ($containers as $tid) { - // Add a row to the field data and revision tables. - db_insert('taxonomy_term__forum_container') - ->fields(array( - 'bundle' => $sandbox['vocabulary'], - 'entity_id' => $tid, - 'revision_id' => $tid, - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'delta' => 0, - 'forum_container_value' => 1, - )) - ->execute(); - db_insert('taxonomy_term_revision__forum_container') - ->fields(array( - 'bundle' => $vocabulary, - 'entity_id' => $tid, - 'revision_id' => $tid, - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'delta' => 0, - 'forum_container_value' => 1, - )) - ->execute(); - } - - // Report status. - $sandbox['processed'] += count($containers); - } - $sandbox['#finished'] = $sandbox['total'] ? $sandbox['processed'] / $sandbox['total'] : 1; - -} - -/** - * Remove the forum_containers variable. - */ -function forum_update_8003() { - update_variable_del('forum_containers'); -} diff --git a/core/modules/image/image.install b/core/modules/image/image.install index bdd6f36fa575..fd14d038de9d 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -61,233 +61,3 @@ function image_requirements($phase) { return $requirements; } - -/** - * Implements hook_update_dependencies(). - */ -function image_update_dependencies() { - // Convert image field and instance setting 'default_image' from integer to - // array only after fields and instances were converted to config. - $dependencies['image'][8003] = array('field' => 8006); - - return $dependencies; -} - -/** - * Loads all effects for an image style from backend. - * - * @param array $style - * The image style (array) to retrieve effects for. - * - * @return array - * An array of effects keyed by UUIDs. - * - * @see image_update_8000() - */ -function _image_update_get_backend_effects(array $style) { - $result = db_select('image_effects', NULL, array('fetch' => PDO::FETCH_ASSOC)) - ->fields('image_effects') - ->condition('isid', $style['isid']) - ->execute(); - $effects = array(); - foreach ($result as $effect) { - $effect['data'] = unserialize($effect['data']); - $effects[] = $effect; - } - - return _image_update_convert_effects($effects); -} - -/** - * Retuns the default image styles shipped with Drupal 7. - * - * @return array - * An associative array keyed by style id, having the style and associated - * effects as values. The array values are defined to be usable in - * image_update_8000(). - * - * @see image_update_8000() - * @see https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_image_default_styles/7 - */ -function _image_update_get_default_styles() { - // Clone from Drupal 7 image_image_default_styles(). - $styles = array( - 'thumbnail' => array( - 'label' => 'Thumbnail (100x100)', - 'effects' => array( - array( - 'name' => 'image_scale', - 'data' => array( - 'width' => '100', - 'height' => '100', - 'upscale' => '1', - ), - 'weight' => '0', - ), - ), - ), - 'medium' => array( - 'label' => 'Medium (220x220)', - 'effects' => array( - array( - 'name' => 'image_scale', - 'data' => array( - 'width' => '220', - 'height' => '220', - 'upscale' => '1', - ), - 'weight' => '0', - ), - ), - ), - 'large' => array( - 'label' => 'Large (480x480)', - 'effects' => array( - array( - 'name' => 'image_scale', - 'data' => array( - 'width' => '480', - 'height' => '480', - 'upscale' => '0', - ), - 'weight' => '0', - ), - ), - ), - ); - - // Add uuid, status, langcode and convert effects. - $langcode = language_default()->id; - $uuid = \Drupal::service('uuid'); - foreach ($styles as $id => $style) { - $styles[$id]['name'] = $id; - $styles[$id]['uuid'] = $uuid->generate(); - $styles[$id]['status'] = 1; - $styles[$id]['langcode'] = $langcode; - $styles[$id]['effects'] = _image_update_convert_effects($style['effects']); - } - - return $styles; -} - -/** - * Normalizes effects from Drupal 7 to Drupal 8 format. - * - * @param array $legacy_effects - * An array containing a list of effects obtained from database or from code. - * - * @return array - * A list of effects keyed by effect uuid and having the effect definition in - * a Drupal 8 configuration format. - */ -function _image_update_convert_effects(array $legacy_effects) { - $uuid = \Drupal::service('uuid'); - $effects = array(); - - foreach ($legacy_effects as $effect) { - $effect['uuid'] = $uuid->generate(); - - // Use 'id' instead of 'name'. - $effect['id'] = $effect['name']; - - // Clear out legacy keys, if case. - unset($effect['isid'], $effect['ieid'], $effect['name']); - - $effects[$effect['uuid']] = $effect; - } - - return $effects; -} - -/** - * Convert existing image styles to the new config system. - */ -function image_update_8000() { - $langcode = language_default()->id; - $uuid = \Drupal::service('uuid'); - - $result = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC)) - ->fields('image_styles') - ->execute(); - - // Prepare image styles from backend. - $styles = array(); - foreach ($result as $style) { - $styles[$style['name']] = array( - 'name' => $style['name'], - 'label' => $style['label'], - 'uuid' => $uuid->generate(), - 'status' => 1, - 'langcode' => $langcode, - 'effects' => _image_update_get_backend_effects($style), - ); - } - - // Append Drupal 7 default image styles from code. Note that some of them may - // be overwritten in the backend. Using this array operator assures that we - // are migrating the overwritten version of the image style. - $styles += _image_update_get_default_styles(); - - // Save as Drupal 8 configuration. - foreach ($styles as $id => $style) { - \Drupal::config('image.style.' . $id) - ->setData($style) - ->save(); - } -} - -/** - * Empty update. See http://drupal.org/node/1980058. - */ -function image_update_8001() { -} - -/** - * Moves image module settings from variable to config. - * - * @ingroup config_upgrade - */ -function image_update_8002() { - update_variables_to_config('image.settings', array( - 'image_style_preview_image' => 'preview_image', - )); -} - -/** - * Convert image field and instance setting 'default_image' from integer to - * array by adding alt, title, width, and height options. - */ -function image_update_8003() { - $image_factory = \Drupal::service('image.factory'); - foreach (array('field', 'instance') as $type) { - $prefix = 'field.' . $type . '.'; - foreach (config_get_storage_names_with_prefix($prefix) as $config_id) { - $config = \Drupal::config($config_id); - $is_image = ($type == 'field' && $config->get('type') == 'image') || ($type == 'instance' && $config->get('field_type') == 'image'); - // Not dealing with an image field or image field instance? - if (!$is_image) { - continue; - } - $width = 0; - $height = 0; - if ($fid = (int) $config->get('settings.default_image')) { - $uri = db_query('SELECT fid FROM {file_managed} WHERE fid = :fid', array(':fid' => $fid))->fetchField(); - if ($uri) { - $image = $image_factory->get($uri); - $width = $image->getWidth(); - $height = $image->getHeight(); - } - } - $default_image = array( - 'fid' => $fid ?: NULL, - 'alt' => '', - 'title' => '', - 'width' => $width ?: NULL, - 'height' => $height ?: NULL, - ); - $config - ->set('settings.default_image', $default_image) - ->save(); - } - } -} diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index 708fe6a7704e..c62c842eab99 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -343,587 +343,3 @@ function locale_requirements($phase) { } return $requirements; } - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Drops textgroup support. - * - * Update assumes i18n migrated this data before the update happened. Core never - * used textgroups for anything, so it is not our job to find a place for the - * data elsewhere. - */ -function locale_update_8000() { - $subquery = db_select('locales_source', 'ls') - ->fields('ls', array('lid')) - ->condition('ls.textgroup', 'default', '<>'); - db_delete('locales_target') - ->condition('lid', $subquery, 'IN') - ->execute(); - db_delete('locales_source') - ->condition('textgroup', 'default', '<>') - ->execute(); - db_drop_field('locales_source', 'textgroup'); -} - -/** - * Language type 'language' renamed to 'language_interface'. - * - * @ingroup config_upgrade - */ -function locale_update_8001() { - // Only change language_types if we had this setting saved. Keep order - // of types because that is significant for value dependency. - $types = update_variable_get('language_types', NULL); - if (!empty($types) && isset($types['language'])) { - $new_types = array(); - foreach ($types as $key => $type) { - $new_types[$key == 'language' ? 'language_interface' : $key] = $type; - } - update_variable_set('language_types', $new_types); - } - - // Rename language_negotiation_language setting if exists. - $setting = update_variable_get('language_negotiation_language', NULL); - if ($setting !== NULL) { - update_variable_set('language_negotiation_language_interface', $setting); - update_variable_del('language_negotiation_language'); - } - - // Rename locale_language_providers_weight_language setting if exists. - $weight = update_variable_get('locale_language_providers_weight_language', NULL); - if ($weight !== NULL) { - update_variable_set('locale_language_providers_weight_language_interface', $weight); - update_variable_del('locale_language_providers_weight_language'); - } - - // Update block data in all core block related tables. Contributed modules - // storing data for blocks will need to update for themselves. - $block_tables = array('block', 'block_node_type', 'block_role'); - foreach ($block_tables as $table) { - // Perform the update only if the language switcher block data is available. - $block_data = db_query_range('SELECT 1 FROM {' . $table . '} WHERE delta = :delta AND module = :module', 0, 1, array(':delta' => 'language', ':module' => 'locale')) - ->fetchField(); - if ($block_data) { - // If block information is rebuilt before performing the update, we might - // already have data for the new delta. In this case we need to remove it - // to avoid integrity constraint violation errors. - db_delete($table) - ->condition('delta', 'language_interface') - ->condition('module', 'locale') - ->execute(); - db_update($table) - ->fields(array( - 'delta' => 'language_interface', - )) - ->condition('delta', 'language') - ->condition('module', 'locale') - ->execute(); - } - } -} - -/** - * Removes duplicates in {locales_source}. - * - * Aggressively removes duplicates that has not already been removed by - * locale_update_7004() in Drupal 7.x. - */ -function locale_update_8002() { - // Look up all duplicates. - $results = db_query("SELECT source, context FROM {locales_source} GROUP BY source, context HAVING COUNT(*) > 1"); - - // For each set of duplicates, select one row that should survive, preferably - // one that has been translated, and delete the rest. - foreach ($results as $row) { - $lid = db_query("SELECT s.lid FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = :source AND s.context = :context ORDER BY translation IS NULL", array( - ':source' => $row->source, - ':context' => $row->context, - ))->fetchField(); - db_delete('locales_source') - ->condition('source', $row->source) - ->condition('context', $row->context) - ->condition('lid', $lid, '<>') - ->execute(); - } - - // Finally remove any rows from {locales_target} that refer to non-existing - // lids. - $subquery = db_select('locales_source', 't')->fields('t', array('lid')); - db_delete('locales_target')->condition('lid', $subquery, 'NOT IN')->execute(); -} - -/** - * Converts language domains to new format. - * - * @ingroup config_upgrade - */ -function locale_update_8003() { - $message = ''; - $config = \Drupal::config('language.negotiation'); - - $domains = $config->get('url.domains') ?: array(); - // $used_domains keeps track of the domain names in use. - $used_domains = array(); - foreach ($domains as $langcode => $domain) { - // Domain names can not contain protocol and/or ports. - if (!empty($domain)) { - $host = 'http://' . str_replace(array('http://', 'https://'), '', $domain); - if (parse_url($host, PHP_URL_HOST) != $domain) { - $domains[$langcode] = parse_url($host, PHP_URL_HOST); - } - if (array_key_exists($domain, $used_domains)) { - if (empty($message)) { - $message = 'Some languages are using the same domain name, you should change these domain names at ' . l('URL language detection configuration', 'admin/config/regional/language/configure/url' . '.'); - } - } - else { - $used_domains[$domain] = $domain; - } - } - } - $config->set('url.domains', $domains)->save(); - - if (!empty($message)) { - return $message; - } -} - -/** - * Rename language providers to language negotiation methods. - * - * @ingroup config_upgrade - */ -function locale_update_8004() { - $types = update_variable_get('language_types', NULL); - if (!empty($types)) { - foreach ($types as $type => $configurable) { - // Change the structure of the language negotiation configuration. - $negotiation = update_variable_get('language_negotiation_' . $type, NULL); - if (!empty($negotiation)) { - update_variable_set('language_negotiation_' . $type, array_keys($negotiation)); - } - - // Rename the language negotiation methods weight variable. - $weight = update_variable_get('locale_language_providers_weight_' . $type , NULL); - if ($weight !== NULL) { - update_variable_set('language_negotiation_methods_weight_' . $type , $weight); - update_variable_del('locale_language_providers_weight_' . $type); - } - } - } -} - -/** - * Update plural interface translations to new format. - * - * See http://drupal.org/node/532512#comment-5679184 for the details of the - * structures handled in this update. - */ -function locale_update_8005() { - // Collect all LIDs that are sources to plural variants. - $results = db_query("SELECT lid, plid FROM {locales_target} WHERE plural <> 0"); - $plural_lids = array(); - foreach ($results as $row) { - // Need to collect both LID and PLID. The LID for the first (singular) - // string can only be retrieved from the first plural's PLID given no - // other indication. The last plural variant is never referenced, so we - // need to store the LID directly for that. We never know whether we are - // on the last plural though, so we always remember LID too. - $plural_lids[] = $row->lid; - $plural_lids[] = $row->plid; - } - $plural_lids = array_unique($plural_lids); - - if (!empty($plural_lids)) { - // Look up all translations for these source strings. Ordering by language - // will group the strings by language, the 'plid' order will get the strings - // in singular/plural order and 'plural' will get them in precise sequential - // order needed. - $results = db_query("SELECT s.lid, s.source, t.translation, t.plid, t.plural, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid IN (:lids) ORDER BY t.language, t.plid, t.plural", array(':lids' => $plural_lids)); - - // Collect the strings into an array and combine values as we go. - $strings = array(); - $parents_to_sources = array(); - $remove_lids = array(); - foreach ($results as $child) { - $strings[$child->language][$child->lid] = array( - 'source' => array($child->source), - 'translation' => array($child->translation), - ); - - if (empty($child->plid)) { - // Non-children strings point to themselves as parents. This makes it - // easy to look up the utmost parents for any plurals. - $parents_to_sources[$child->lid] = $child->lid; - } - else { - // Children strings point to their utmost parents. Because we get data - // in PLID order, we can ensure that all previous parents have data now, - // so we can just copy the parent's data about their parent, etc. - $parents_to_sources[$child->lid] = $parents_to_sources[$child->plid]; - - // Append translation to the utmost parent's translation string. - $utmost_parent = &$strings[$child->language][$parents_to_sources[$child->plid]]; - // Drop the Drupal-specific numbering scheme from the end of plural - // formulas. - $utmost_parent['translation'][] = str_replace('@count[' . $child->plural .']', '@count', $child->translation); - if (count($utmost_parent['source']) < 2) { - // Append source to the utmost parent's source string only if it is - // the plural variant. Further Drupal specific plural variants are not - // to be retained for source strings. - $utmost_parent['source'][] = $child->source; - } - - // All plural variant LIDs are to be removed with their translations. - // Only the singular LIDs will be kept. - $remove_lids[] = $child->lid; - } - } - - // Do updates for all source strings and all translations. - $updated_sources = array(); - foreach ($strings as $langcode => $translations) { - foreach($translations as $lid => $translation) { - if (!in_array($lid, $updated_sources)) { - // Only update source string if not yet updated. We merged these - // within the translation lookups because plural information was only - // available with the translation, but we don't need to save it again - // for every language. - db_update('locales_source') - ->fields(array( - 'source' => implode(LOCALE_PLURAL_DELIMITER, $translation['source']), - )) - ->condition('lid', $lid) - ->execute(); - $updated_sources[] = $lid; - } - db_update('locales_target') - ->fields(array( - 'translation' => implode(LOCALE_PLURAL_DELIMITER, $translation['translation']), - )) - ->condition('lid', $lid) - ->condition('language', $langcode) - ->execute(); - } - } - - // Remove all plural LIDs from source and target. only keep those which were - // originally used for the singular strings (now updated to contain the - // serialized version of plurals). - $remove_lids = array_unique($remove_lids); - db_delete('locales_source') - ->condition('lid', $remove_lids, 'IN') - ->execute(); - db_delete('locales_target') - ->condition('lid', $remove_lids, 'IN') - ->execute(); - } - - // Drop the primary key because it contains 'plural'. - db_drop_primary_key('locales_target'); - - // Remove the 'plid' and 'plural' columns and indexes. - db_drop_index('locales_target', 'plid'); - db_drop_field('locales_target', 'plid'); - db_drop_index('locales_target', 'plural'); - db_drop_field('locales_target', 'plural'); - - // Add back a primary key without 'plural'. - db_add_primary_key('locales_target', array('language', 'lid')); -} - -/** - * Convert language_negotiation_* variables. - * - * @ingroup config_upgrade - */ -function locale_update_8007() { - // Add all language type weight variables. As the function language_types() - // is not available its functionality is rebuild. - $language_types = update_variable_get('language_types', array( - Language::TYPE_INTERFACE => TRUE, - Language::TYPE_CONTENT => FALSE, - Language::TYPE_URL => FALSE, - )); - foreach ($language_types as $language_type => $configurable) { - $variable_names['language_negotiation_' . $language_type] = 'language_negotiation_methods_weight_' . $language_type; - } - - $type_map = array( - 'locale-interface' => 'language-interface', - 'locale-url' => 'language-url', - 'locale-url-fallback' => 'language-url-fallback', - 'locale-browser' => 'language-browser', - 'locale-user' => 'language-user', - 'locale-session' => 'language-session', - ); - foreach ($variable_names as $variable_name => $weight_variable_name) { - $value = update_variable_get($weight_variable_name); - // Skip processing if the variable is not stored in the db. - if ($value === NULL) { - update_variable_del($variable_name); - continue; - } - $new_value = array(); - foreach ($value as $type => $weight) { - // Convert the type. - if (isset($type_map[$type])) { - $type = $type_map[$type]; - } - $new_value[$type] = $weight; - } - asort($new_value); - update_variable_set($variable_name, $new_value); - update_variable_del($weight_variable_name); - } -} - -/** - * Update locale variables to config or state systems as appropriate. - * - * @ingroup config_upgrade - */ -function locale_update_8008() { - update_variables_to_config('locale.settings', array( - 'locale_cache_strings' => 'cache_strings', - 'locale_js_directory' => 'javascript.directory', - )); - - update_variables_to_config('language.negotiation', array( - 'locale_language_negotiation_session_param' => 'session.parameter', - 'locale_language_negotiation_url_part' => 'url.source', - )); -} - -/** - * Convert locale blocks to language blocks. - */ -function locale_update_8009() { - $block_tables = array('block', 'block_node_type', 'block_role'); - foreach ($block_tables as $table) { - db_update($table) - ->fields(array('module' => 'language')) - ->condition('module', 'locale') - ->execute(); - } -} - -/** - * Add {locale_file} table. - */ -function locale_update_8010() { - $table = array( - 'description' => 'File import status information for interface translation files.', - 'fields' => array( - 'langcode' => array( - 'description' => 'Reference to the {languages}.langcode for this translation.', - 'type' => 'varchar', - 'length' => '12', - 'not null' => TRUE, - ), - 'filename' => array( - 'description' => 'Filename for importing the file.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'uri' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'timestamp' => array( - 'description' => 'Unix timestamp of the file itself from the point when it was last imported.', - 'type' => 'int', - 'not null' => FALSE, - 'default' => 0, - ), - ), - 'primary key' => array('uri', 'langcode'), - ); - db_create_table('locale_file', $table); -} - -/** - * Add a cache table and locale_project table for the locale module. - */ -function locale_update_8011() { - - // Add locale_project table. - db_create_table('locale_project', array( - 'description' => 'Translation status information for projects and server data.', - 'fields' => array( - 'name' => array( - 'description' => 'A unique short name to identify the project.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - ), - 'project_type' => array( - 'description' => 'Project type, may be core, module, theme', - 'type' => 'varchar', - 'length' => 15, - 'not null' => TRUE, - ), - 'core' => array( - 'description' => 'Core compatibility string for this project.', - 'type' => 'varchar', - 'length' => 4, - 'not null' => TRUE, - 'default' => '', - ), - 'version' => array( - 'description' => 'The release version of the project.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - ), - 'server_pattern' => array( - 'description' => 'Pattern of path and name of the gettext file at the translation server.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'status' => array( - 'description' => 'The update status of the project.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 1, - ), - ), - 'primary key' => array('name'), - )); -} - -/** - * Renames language_default language negotiation method to language_selected. - */ -function locale_update_8013() { - $weight = update_variable_get('language_negotiation_language_interface', NULL); - if ($weight !== NULL) { - $weight[LanguageNegotiationSelected::METHOD_ID] = $weight['language-default']; - unset($weight['language-default']); - update_variable_set('language_negotiation_language_interface', $weight); - } -} - -/** - * Drop old 'location' field. - */ -function locale_update_8014() { - db_drop_field('locales_source', 'location'); -} - -/** - * Build a new {locale_file} table. - */ -function locale_update_8015() { - // The existing table has a primary key on uri and langcode. The new key - // is on project and langcode. There is no project data in the existing table, - // and it may not be possible to generate this reliably. Therefore we drop - // the table and build it again. - db_drop_table('locale_file'); - - $table = array( - 'description' => 'File import status information for interface translation files.', - 'fields' => array( - 'project' => array( - 'type' => 'varchar', - 'length' => '255', - 'not null' => TRUE, - 'default' => '', - 'description' => 'A unique short name to identify the project the file belongs to.', - ), - 'langcode' => array( - 'type' => 'varchar', - 'length' => '12', - 'not null' => TRUE, - 'default' => '', - 'description' => 'Language code of this translation. References {language}.langcode.', - ), - 'filename' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Filename of the imported file.', - ), - 'version' => array( - 'type' => 'varchar', - 'length' => '128', - 'not null' => TRUE, - 'default' => '', - 'description' => 'Version tag of the imported file.', - ), - 'uri' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'URI of the remote file, the resulting local file or the locally imported file.', - ), - 'timestamp' => array( - 'type' => 'int', - 'not null' => FALSE, - 'default' => 0, - 'description' => 'Unix timestamp of the imported file.', - ), - 'last_checked' => array( - 'type' => 'int', - 'not null' => FALSE, - 'default' => 0, - 'description' => 'Unix timestamp of the last time this translation was confirmed to be the most recent release available.', - ), - ), - 'primary key' => array('project', 'langcode'), - ); - db_create_table('locale_file', $table); -} - -/** - * Converts localized date formats. - */ -function locale_update_8016() { - // Fetch all date types from {date_format_type}. - $result = db_query('SELECT * FROM {date_format_locale}'); - foreach ($result as $format) { - // Create config objects for the language if not yet done. - $config_name = \Drupal::configFactory()->getLanguageConfigName($format->language, 'system.date_format.' . $format->type); - \Drupal::config($config_name) - ->set('pattern.php', $format->format) - ->save(); - } -} - -/** - * Moves locale translation directory settings from variable to config. - * - * @ingroup config_upgrade - */ -function locale_update_8017() { - update_variables_to_config('locale.settings', array( - 'locale_translate_file_directory' => 'translation.path', - )); -} - -/** - * Removes the field language fallback settings as it is no longer supported. - * - * @ingroup config_upgrade - */ -function locale_update_8018() { - update_variable_del('locale_field_language_fallback'); -} - -/** - * @} End of "addtogroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/menu/menu.install b/core/modules/menu/menu.install index de0415fb9eaf..c1615921aec8 100644 --- a/core/modules/menu/menu.install +++ b/core/modules/menu/menu.install @@ -35,99 +35,3 @@ function menu_install() { function menu_uninstall() { menu_router_rebuild(); } - -/** - * Moves menu settings from variables to config. - * - * @ingroup config_upgrade - */ -function menu_update_8000() { - update_variables_to_config('menu.settings', array( - 'menu_main_links_source' => 'main_links', - 'menu_secondary_links_source' => 'secondary_links', - )); -} - -/** - * Rename default menu names. - */ -function menu_update_8001() { - // Only the internal identifiers are updated; the labels and descriptions - // might have been customized and do not have to be renamed. - $map = array( - 'navigation' => 'tools', - 'management' => 'admin', - 'user-menu' => 'account', - 'main-menu' => 'main', - ); - foreach ($map as $old => $new) { - db_update('menu_custom') - ->condition('menu_name', $old) - ->fields(array('menu_name' => $new)) - ->execute(); - } -} - -/** - * Adds the footer menu to custom menus. - */ -function menu_update_8002() { - db_insert('menu_custom') - ->fields(array( - 'menu_name' => 'footer', - 'title' => 'Footer menu', - 'description' => 'Use this for linking to site information.', - )) - ->execute(); -} - -/** - * Moves menu_override_parent_selector from variables to config. - * - * @ingroup config_upgrade - */ -function menu_update_8003() { - update_variables_to_config('menu.settings', array( - 'menu_override_parent_selector' => 'override_parent_selector', - )); -} - -/** - * Migrate menus into configuration. - * - * @ingroup config_upgrade - */ -function menu_update_8004() { - $uuid = \Drupal::service('uuid'); - $result = db_query('SELECT * FROM {menu_custom}'); - foreach ($result as $menu) { - // Save the config object. - \Drupal::config('system.menu.' . $menu->menu_name) - ->set('id', $menu->menu_name) - ->set('uuid', $uuid->generate()) - ->set('label', $menu->title) - ->set('description', $menu->description) - ->save(); - } -} - -/** - * Ensure menu settings exist for all node types. - * - * @ingroup config_upgrade - */ -function menu_update_8005() { - if (\Drupal::moduleHandler()->moduleExists('node')) { - $node_types = array_keys(node_type_get_names()); - foreach ($node_types as $type_id) { - $menu_settings = \Drupal::config("menu.entity.node.$type_id"); - if ($menu_settings->isNew()) { - $menu_settings - ->set('available_menus', array('main')) - ->set('parent', 'main:0') - ->save(); - } - } - } -} - diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 91589a020290..ba15fa3d82f4 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -456,707 +456,3 @@ function node_uninstall() { // Delete any stored state. \Drupal::state()->delete('node.cron_last'); } - -/** - * Fetches node types directly from the database. - * - * @ingroup update_api - */ -function _update_7000_node_get_types() { - $node_types = db_query('SELECT * FROM {node_type}')->fetchAllAssoc('type', PDO::FETCH_OBJ); - - // Create default settings for orphaned nodes. - $all_types = db_query('SELECT DISTINCT type FROM {node}')->fetchCol(); - $extra_types = array_diff($all_types, array_keys($node_types)); - - foreach ($extra_types as $type) { - $type_object = new stdClass(); - $type_object->type = $type; - // In Drupal 6, whether you have a body field or not is a flag in the node - // type table. If it's enabled, nodes may or may not have an empty string - // for the bodies. As we can't detect what this setting should be in - // Drupal 7 without access to the Drupal 6 node type settings, we assume - // the default, which is to enable the body field. - $type_object->has_body = 1; - $type_object->body_label = 'Body'; - $node_types[$type_object->type] = $type_object; - } - return $node_types; -} - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Implements hook_update_dependency(). - */ -function node_update_dependency() { - $dependencies['node'][8013] = array( - 'user' => 8002, - ); -} - -/** - * Rename node type language variable names. - * - * @see http://drupal.org/node/540294 - * - * @ingroup config_upgrade - */ -function node_update_8001() { - $types = db_query('SELECT type FROM {node_type}')->fetchCol(); - foreach ($types as $type) { - $node_type_language = update_variable_get('language_content_type_' . $type); - if (isset($node_type_language)) { - update_variable_set('node_type_language_' . $type, $node_type_language); - } - update_variable_del('language_content_type_' . $type); - } -} - -/** - * Rename node.language field to node.langcode. - */ -function node_update_8002() { - $spec = array( - 'description' => 'The {language}.langcode of this node.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ); - db_change_field('node', 'language', 'langcode', $spec); -} - -/** - * Rename node type language variable names. - */ -function node_update_8003() { - $types = db_query('SELECT type FROM {node_type}')->fetchCol(); - foreach ($types as $type) { - update_variable_set('node_type_language_default_' . $type, Language::LANGCODE_NOT_SPECIFIED); - $node_type_language = update_variable_get('node_type_language_' . $type, 0); - if ($node_type_language == 0) { - update_variable_set('node_type_language_show_' . $type, FALSE); - } - if ($node_type_language == 2) { - // Translation was enabled, so enable it again and - // unhide the language selector. Because if language is - // Language::LANGCODE_NOT_SPECIFIED and the selector hidden, translation - // cannot be enabled. - update_variable_set('node_type_language_show_' . $type, TRUE); - update_variable_set('node_type_language_translation_enabled_' . $type, TRUE); - } - update_variable_del('node_type_language_' . $type); - } -} - -/** - * Create a UUID column for nodes. - */ -function node_update_8004() { - $spec = array( - 'description' => 'Unique Key: Universally unique identifier for this entity.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - ); - $keys = array( - 'unique keys' => array( - 'uuid' => array('uuid'), - ), - ); - // Account for sites having the contributed UUID module installed. - if (db_field_exists('node', 'uuid')) { - db_change_field('node', 'uuid', 'uuid', $spec, $keys); - } - else { - db_add_field('node', 'uuid', $spec, $keys); - } -} - -/** - * Make *id fields unsigned. - */ -function node_update_8005() { - db_drop_index('node', 'uid'); - db_change_field('node', 'uid', 'uid', - array( - 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - array('indexes' => array( - 'uid' => array('uid'), - )) - ); - - db_drop_index('node_revision', 'uid'); - db_change_field('node_revision', 'uid', 'uid', - array( - 'description' => 'The {users}.uid that created this version.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - array('indexes' => array( - 'uid' => array('uid'), - )) - ); - - db_drop_primary_key('history'); - db_drop_index('history', 'nid'); - db_change_field('history', 'uid', 'uid', - array( - 'description' => 'The {users}.uid that read the {node} nid.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ) - ); - db_change_field('history', 'nid', 'nid', - array( - 'description' => 'The {node}.nid that was read.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - array('primary key' => array('uid', 'nid'), 'indexes' => array( - 'nid' => array('nid'), - )) - ); -} - -/** - * Generate a UUID for all nodes. - */ -function node_update_8006(&$sandbox) { - if (!isset($sandbox['progress'])) { - $sandbox['progress'] = 0; - $sandbox['last'] = 0; - $sandbox['max'] = db_query('SELECT COUNT(nid) FROM {node} WHERE uuid IS NULL')->fetchField(); - } - - $nids = db_query_range('SELECT nid FROM {node} WHERE nid > :nid AND uuid IS NULL ORDER BY nid ASC', 0, 10, array(':nid' => $sandbox['last']))->fetchCol(); - update_add_uuids($sandbox, 'node', 'nid', $nids); - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); -} - -/** - * Move the language default values to config. - */ -function node_update_8007() { - $types = db_query('SELECT type FROM {node_type}')->fetchCol(); - foreach ($types as $type) { - $language_default = update_variable_get('node_type_language_default_' . $type, NULL); - $language_show = update_variable_get('node_type_language_show_' . $type, NULL); - if (isset($language_default) || isset($language_show)) { - $values = array('langcode' => $language_default, 'language_show' => $language_show); - \Drupal::config('language.settings')->set('node.' . $type . '.language.default_configuration', $values)->save(); - } - } -} - -/** - * Rename default menu names. - */ -function node_update_8008() { - // System menu's new block deltas are prefixed with 'menu-'. - $map = array( - 'navigation' => 'menu-tools', - 'management' => 'menu-admin', - 'user-menu' => 'menu-account', - 'main-menu' => 'menu-main', - ); - foreach ($map as $old => $new) { - db_update('block_node_type') - ->condition('module', 'system') - ->condition('delta', $old) - ->fields(array('delta' => $new)) - ->execute(); - } -} - -/** - * Coverts default_nodes_main variable to config. - * - * @ingroup config_upgrade - */ -function node_update_8009() { - update_variables_to_config('node.settings', array('default_nodes_main' => 'items_per_page')); -} - -/** - * Moves node_access_needs_rebuild from variable to state. - * - * @ingroup config_upgrade - */ -function node_update_8010() { - update_variables_to_state(array('node_access_needs_rebuild' => 'node.node_access_needs_rebuild')); -} - -/** - * Moves node cron last run time from variable to state. - * - * @ingroup config_upgrade - */ -function node_update_8011() { - update_variables_to_state(array('node_cron_last' =>'node.cron_last')); -} - -/** - * Enable History module. - */ -function node_update_8012() { - // Enable the history module without re-installing the schema. - \Drupal::moduleHandler()->install(array('history')); -} - -/** - * Renames global revision permissions to use the word 'all'. - */ -function node_update_8013() { - update_replace_permissions(array( - 'view revisions' => array('view all revisions'), - 'revert revisions' => array('revert all revisions'), - 'delete revisions' => array('delete all revisions'), - )); -} - -/** - * Empty update. See https://drupal.org/node/2006484. - */ -function node_update_8014() { -} - -/** - * Add language support to the {node_access} table. - */ -function node_update_8015() { - // Add the langcode field. - $langcode_field = array( - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The {language}.langcode of this node.', - ); - db_add_field('node_access', 'langcode', $langcode_field); - - // Add the fallback field. - $fallback_field = array( - 'description' => 'Boolean indicating whether this record should be used as a fallback if a language condition is not provided.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 1, - ); - db_add_field('node_access', 'fallback', $fallback_field); - - db_drop_primary_key('node_access'); - db_add_primary_key('node_access', array('nid', 'gid', 'realm', 'langcode')); -} - -/** - * Upgrade node schema to the standard entity SQL schema: schema definition. - */ -function _node_update_8016_schema() { - $schema = array(); - - // Node field storage. - $schema['node_field_data'] = array( - 'description' => 'Data table for node base fields.', - 'fields' => array( - 'nid' => array( - 'description' => 'The primary identifier for a node.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - ), - 'vid' => array( - 'description' => 'The current {node_field_revision}.vid version identifier.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - ), - 'type' => array( - 'description' => 'The {node_type}.type of this node.', - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'default' => '', - ), - 'langcode' => array( - 'description' => 'The {language}.langcode of these node property values.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ), - 'default_langcode' => array( - 'description' => 'Boolean indicating whether the property values are in the {language}.langcode of this node.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 1, - ), - 'title' => array( - 'description' => 'The title of this node, always treated as non-markup plain text.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'uid' => array( - 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - 'status' => array( - 'description' => 'Boolean indicating whether the node translation is published (visible to non-administrators).', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 1, - ), - 'created' => array( - 'description' => 'The Unix timestamp when the node translation was created.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'changed' => array( - 'description' => 'The Unix timestamp when the node translation was most recently saved.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'promote' => array( - 'description' => 'Boolean indicating whether the node translation should be displayed on the front page.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'sticky' => array( - 'description' => 'Boolean indicating whether the node translation should be displayed at the top of lists in which it appears.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'indexes' => array( - 'node_changed' => array('changed'), - 'node_created' => array('created'), - 'node_default_langcode' => array('default_langcode'), - 'node_langcode' => array('langcode'), - 'node_frontpage' => array('promote', 'status', 'sticky', 'created'), - 'node_status_type' => array('status', 'type', 'nid'), - 'node_title_type' => array('title', array('type', 4)), - 'node_type' => array(array('type', 4)), - 'vid' => array('vid'), - 'uid' => array('uid'), - ), - 'foreign keys' => array( - 'node_base' => array( - 'table' => 'node', - 'columns' => array('nid' => 'nid'), - ), - 'node_author' => array( - 'table' => 'users', - 'columns' => array('uid' => 'uid'), - ), - ), - 'primary key' => array('nid', 'langcode'), - ); - - $schema['node_field_revision'] = array( - 'description' => 'Revision table for node base fields.', - 'fields' => array( - 'nid' => array( - 'description' => 'The {node} this version belongs to.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - ), - 'vid' => array( - 'description' => 'The primary identifier for this version.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - ), - 'langcode' => array( - 'description' => 'The {language}.langcode of this version.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ), - 'default_langcode' => array( - 'description' => 'Boolean indicating whether the property values of this version are in the {language}.langcode of this node.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 1, - ), - 'title' => array( - 'description' => 'The title of this version, always treated as non-markup plain text.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'uid' => array( - 'description' => 'The {users}.uid that created this node.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - 'status' => array( - 'description' => 'Boolean indicating whether the node (at the time of this revision) is published (visible to non-administrators).', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 1, - ), - 'created' => array( - 'description' => 'The Unix timestamp when the node was created.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'changed' => array( - 'description' => 'The Unix timestamp when the version was most recently saved.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'promote' => array( - 'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed on the front page.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'sticky' => array( - 'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed at the top of lists in which it appears.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'indexes' => array( - 'uid' => array('uid'), - 'node_default_langcode' => array('default_langcode'), - 'node_langcode' => array('langcode'), - ), - 'foreign keys' => array( - 'versioned_node' => array( - 'table' => 'node', - 'columns' => array('nid' => 'nid'), - ), - 'node_author' => array( - 'table' => 'users', - 'columns' => array('uid' => 'uid'), - ), - ), - 'primary key' => array('vid', 'langcode'), - ); - - return $schema; -} - -/** - * Upgrade node schema to the standard entity SQL schema: prepare schema. - */ -function node_update_8016() { - foreach (_node_update_8016_schema() as $table => $table_schema) { - db_create_table($table, $table_schema); - } - - $spec = array( - 'description' => 'The {language}.langcode of this version.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ); - $keys_new = array('indexes' => array('node_langcode' => array('langcode'))); - db_add_field('node_revision', 'langcode', $spec, $keys_new); - - $spec = array( - 'description' => 'The Unix timestamp when the version was created.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ); - db_change_field('node_revision', 'timestamp', 'revision_timestamp', $spec); - - db_drop_index('node_revision', 'uid'); - $spec = array( - 'description' => 'The {users}.uid that created this version.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ); - db_change_field('node_revision', 'uid', 'revision_uid', $spec); - db_add_index('node_revision', 'revision_uid', array('revision_uid')); -} - -/** - * Upgrade node schema to the standard entity SQL schema: migrate data. - */ -function node_update_8017(&$sandbox) { - if (!isset($sandbox['progress'])) { - // Initialize the batch status. - $sandbox['progress'] = 0; - $sandbox['max'] = db_query('SELECT COUNT(vid) FROM {node_revision}')->fetchField(); - } - - // Prepare the new records. - $queries = array(); - $schema = _node_update_8016_schema(); - $result = db_query_range('SELECT nr.*, nr.revision_timestamp, nr.revision_uid, 1 AS default_langcode, n.langcode, n.vid = nr.vid AS default_revision, n.uid, n.changed, n.created, n.type FROM {node_revision} nr JOIN {node} n ON nr.nid = n.nid ORDER BY nr.nid ASC, nr.vid ASC', $sandbox['progress'], 50); - - foreach ($result as $row) { - $sandbox['progress']++; - - foreach ($schema as $table => $table_schema) { - // We need to store the data table record only when dealing with the - // default revision. - if ($row->default_revision || $table == 'node_field_revision') { - $fields = array_keys($table_schema['fields']); - $record = array(); - foreach ($fields as $field) { - if (isset($row->{$field})) { - $record[$field] = $row->{$field}; - } - } - if (!isset($queries[$table])) { - $queries[$table] = db_insert($table)->fields($fields); - } - $queries[$table]->values($record); - } - } - - // Populate the langcode column with the same value for each revision as we - // have no other data available. - db_update('node_revision') - ->fields(array('langcode' => $row->langcode)) - ->condition('vid', $row->vid) - ->execute(); - } - - // Store the new records. - foreach ($queries as $query) { - $query->execute(); - } - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); -} - -/** - * Upgrade node schema to the standard entity SQL schema: delete old fields. - */ -function node_update_8018() { - $indexes = array('node_changed', 'node_created', 'node_frontpage', 'node_status_type', 'node_title_type', 'uid'); - foreach ($indexes as $index) { - db_drop_index('node', $index); - } - $fields = array('title', 'uid', 'status', 'created', 'changed', 'promote', 'sticky', 'langcode'); - foreach ($fields as $field) { - db_drop_field('node', $field); - } - $fields = array('title', 'status', 'comment', 'promote', 'sticky'); - foreach ($fields as $field) { - db_drop_field('node_revision', $field); - } -} - -/** - * Convert the 'module' column in {node_type} to the maximum shortname length. - */ -function node_update_8019() { - if (db_field_exists('node_type', 'module')) { - $spec = array( - 'description' => 'The module defining this node type.', - 'type' => 'varchar', - 'length' => 50, - 'not null' => TRUE, - ); - db_change_field('node_type', 'module', 'module', $spec); - } -} - -/** - * Convert node types into configuration. - * - * @ingroup config_upgrade -*/ -function node_update_8020() { - $uuid = \Drupal::service('uuid'); - // Properties to drop: custom, disabled. - $locked = array(); - // Note: {node_type}.name was the label, .type the machine name. - $result = db_query('SELECT * FROM {node_type}') - ->fetchAllAssoc('type', PDO::FETCH_ASSOC); - foreach ($result as $id => $node_type) { - $config = \Drupal::config('node.type.' . $id); - // Node type. - $config->setData($node_type); - $config->set('uuid', $uuid->generate()); - $config->set('langcode', Language::LANGCODE_NOT_SPECIFIED); - - // Node type settings. - $variables = db_query('SELECT name, value FROM {variable} WHERE name IN (:names)', array( - ':names' => array( - 'node_submitted_' . $id, - 'node_preview_' . $id, - 'node_options_' . $id, - ), - ))->fetchAllKeyed(); - $variables = array_map('unserialize', $variables); - // There are not necessarily values for all settings, so pollute defaults. - $variables += array( - 'node_submitted_' . $id => TRUE, - 'node_preview_' . $id => 1, // DRUPAL_OPTIONAL - 'node_options_' . $id => array('status', 'promote'), - ); - foreach ($variables as $name => $value) { - // Turn e.g. 'node_submitted_ID' into 'submitted'. - $name = str_replace(array('node_', '_' . $id), '', $name); - $config->set('settings.node.' . $name, $value); - - update_variable_del($name); - } - $config->save(); - // Convert the 'base' property to state. Note that we could have disabled - // modules at this time but we still need to preserve the relation. - if ($node_type['base'] !== 'node_content') { - $locked[$id] = $node_type['base']; - } - } - \Drupal::state()->set('node.type.locked', $locked); -} - -/** - * Converts node_admin_theme variable to config. - * - * @ingroup config_upgrade - */ -function node_update_8021() { - update_variables_to_config('node.settings', array( - 'node_admin_theme' => 'use_admin_theme' - )); -} - -/** - * @} End of "addtogroup updates-7.x-to-8.x" - * The next series of updates should start at 9000. - */ diff --git a/core/modules/rdf/rdf.install b/core/modules/rdf/rdf.install deleted file mode 100644 index 3d060ed41cb8..000000000000 --- a/core/modules/rdf/rdf.install +++ /dev/null @@ -1,60 +0,0 @@ -<?php - -/** - * @file - * Install, update and uninstall functions for the rdf module. - */ - -use Drupal\Component\Uuid\Uuid; - -/** - * Convert RDF mappings to configuration. - * - * @ingroup config_upgrade - */ -function rdf_update_8000() { - $uuid = \Drupal::service('uuid'); - $query = db_query("SELECT * FROM {rdf_mapping}"); - - // Iterate through all the stored mappings. - while ($row = $query->fetchAssoc()) { - $mapping = unserialize($row['mapping']); - $entity_type = $row['type']; - $bundle = $row['bundle']; - - // Create a config object for the mapping. - $config = \Drupal::config("rdf.mapping.$entity_type.$bundle") - ->set('id', "$entity_type.$bundle") - ->set('uuid', $uuid->generate()) - ->set('targetEntityType', $entity_type) - ->set('bundle', $bundle); - - // Add the bundle and field mappings. - $field_mappings = array(); - foreach ($mapping as $key => $value) { - // If this is the rdftype entry, add the types to the config object. - if ($key == 'rdftype') { - $config->set('types', $value); - } - // Otherwise, this key is a field. Process the field mapping into the new - // structure. - else { - // Since reverse relations are not supported in D8, drop any mappings - // which use the 'rev' type. - if (!empty($value['type'])) { - if ($value['type'] == 'rev') { - continue; - } - $field_mappings[$key]['mapping_type'] = $value['type']; - } - !empty($value['predicates']) ? $field_mappings[$key]['properties'] = $value['predicates'] : NULL; - !empty($value['datatype']) ? $field_mappings[$key]['datatype'] = $value['datatype'] : NULL; - !empty($value['callback']) ? $field_mappings[$key]['datatype_callback']['callable'] = $value['callback'] : NULL; - } - } - $config->set('fieldMappings', $field_mappings); - - // Save the mapping config object. - $config->save(); - } -} diff --git a/core/modules/search/search.install b/core/modules/search/search.install index 955bfed400e1..1d8df5b919a1 100644 --- a/core/modules/search/search.install +++ b/core/modules/search/search.install @@ -122,95 +122,3 @@ function search_schema() { return $schema; } - -/** - * Update search module to use the configuration system. - * - * @ingroup config_upgrade - */ -function search_update_8000() { - // Run this first so the config is sure to be empty. - _search_update_8000_modules_mapto_plugins(array('user' => 'user_search', 'node' => 'node_search')); - $active_plugins = \Drupal::config('search.settings')->get('active_plugins'); - update_variables_to_config('search.settings', array( - 'minimum_word_size' => 'index.minimum_word_size', - 'overlap_cjk' => 'index.overlap_cjk', - 'search_cron_limit' => 'index.cron_limit', - 'search_tag_weights' => 'index.tag_weights', - 'search_and_or_limit' => 'and_or_limit', - )); - // update_variables_to_config() merges in all the default values from the YAML - // file, so we need re-save the list of active plugins we found. - \Drupal::config('search.settings')->set('active_plugins', $active_plugins)->save(); -} - -/** - * Update search module variables to plugin IDs. - * - * This function may also be called by contributed modules that implement a - * search plugin that is an update of a hook_search_info() implementation. - */ -function _search_update_8000_modules_mapto_plugins(array $map) { - $active_modules = update_variable_get('search_active_modules', array('node', 'user')); - $config = \Drupal::config('search.settings'); - $active_plugins = $config->get('active_plugins'); - foreach($active_modules as $idx => $module) { - if (isset($map[$module])) { - $plugin_id = $map[$module]; - $active_plugins[$plugin_id] = $plugin_id; - unset($active_modules[$idx]); - } - } - $config->set('active_plugins', $active_plugins); - if ($active_modules) { - update_variable_set('search_active_modules', $active_modules); - } - else { - update_variable_del('search_active_modules'); - } - $default_module = update_variable_get('search_default_module', 'node'); - if (isset($map[$default_module])) { - $config->set('default_page', $map[$default_module]); - update_variable_del('search_default_module'); - } - $config->save(); -} - -/** - * Adds the langcode field and indexes to {search_dataset} and {search_index}. - */ -function search_update_8001() { - // In order to upgrade the existing entries to have the correct langcode we - // need to recreate search data through running cron. - db_truncate('search_dataset'); - db_truncate('search_index'); - // This table is no longer used. - db_drop_table('search_node_links'); - - // Add the fields and indexes. - db_drop_primary_key('search_dataset'); - db_add_field('search_dataset', 'langcode', array( - 'type' => 'varchar', - 'length' => '12', - 'not null' => TRUE, - 'description' => 'The {languages}.langcode of the item variant.', - 'default' => '', - )); - db_add_primary_key('search_dataset', array('sid', 'langcode', 'type')); - - db_drop_primary_key('search_index'); - db_drop_index('search_index', 'sid_type'); - db_add_field('search_index', 'langcode', array( - 'type' => 'varchar', - 'length' => '12', - 'not null' => TRUE, - 'description' => 'The {languages}.langcode of the item variant.', - 'default' => '', - ), - array( - 'indexes' => array( - 'sid_type' => array('sid', 'langcode', 'type'), - ), - )); - db_add_primary_key('search_index', array('word', 'sid', 'langcode', 'type')); -} diff --git a/core/modules/shortcut/shortcut.install b/core/modules/shortcut/shortcut.install index 3a00775d5b43..b7ed49c9906e 100644 --- a/core/modules/shortcut/shortcut.install +++ b/core/modules/shortcut/shortcut.install @@ -139,186 +139,3 @@ function shortcut_schema() { return $schema; } - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Migrate shortcut sets into configuration. - */ -function shortcut_update_8000() { - $uuid = \Drupal::service('uuid'); - $result = db_query('SELECT * from {shortcut_set}'); - $ids = array(); - foreach ($result as $set) { - // Save a config object. - if ($set->set_name == 'shortcut-set-1') { - // Change default shortcut id. - $set->set_name = 'default'; - // Update menu links. - db_update('menu_links') - ->fields(array( - 'menu_name' => 'shortcut-default' - )) - ->condition('menu_name', 'shortcut-set-1') - ->execute(); - } - \Drupal::config('shortcut.set.' . $set->set_name) - ->set('id', $set->set_name) - ->set('label', $set->title) - ->set('uuid', $uuid->generate()) - ->save(); - $ids[] = $set->set_name; - } -} - -/** - * Drop the {shortcut_set} table. - */ -function shortcut_update_8001() { - db_drop_table('shortcut_set'); -} - -/** - * Create the database tables for the new 'shortcut' entity type. - */ -function shortcut_update_8002() { - $tables['shortcut'] = array( - 'description' => 'Stores shortcut items.', - 'fields' => array( - 'id' => array( - 'type' => 'serial', - 'not null' => TRUE, - 'description' => 'Primary Key: Unique shortcut ID.', - ), - 'uuid' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - 'description' => 'Unique Key: Universally unique identifier for this shortcut.', - ), - 'shortcut_set' => array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The bundle of the shortcut.', - ), - 'langcode' => array( - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The {language}.langcode of the original variant of this shortcut.', - ), - 'weight' => array( - 'description' => 'Weight among shortcuts in the same shortcut set.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'route_name' => array( - 'description' => 'The machine name of a defined Symfony Route this menu item represents.', - 'type' => 'varchar', - 'length' => 255, - ), - 'route_parameters' => array( - 'description' => 'Serialized array of route parameters of this shortcut.', - 'type' => 'blob', - 'size' => 'big', - 'not null' => FALSE, - 'serialize' => TRUE, - ), - ), - 'primary key' => array('id'), - 'unique keys' => array( - 'uuid' => array('uuid'), - ), - ); - - $tables['shortcut_field_data'] = array( - 'description' => 'Stores shortcut properties.', - 'fields' => array( - 'id' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'The {shortcut}.id of the shortcut.', - ), - 'langcode' => array( - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The {language}.langcode of this variant of this shortcut.', - ), - 'default_langcode' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 1, - 'description' => 'Boolean indicating whether the current variant is in the original entity language.', - ), - 'title' => array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => FALSE, - 'description' => 'The title of the shortcut.', - ), - ), - 'foreign keys' => array( - 'shortcut' => array( - 'table' => 'shortcut', - 'columns' => array('id' => 'id'), - ), - ), - 'primary key' => array('id', 'langcode'), - ); - - $schema = Database::getConnection()->schema(); - $schema->createTable('shortcut', $tables['shortcut']); - $schema->createTable('shortcut_field_data', $tables['shortcut_field_data']); -} - -/** - * Migrate shortcuts into their own storage tables. - */ -function shortcut_update_8003() { - $shortcuts = db_select('menu_links', 'ml') - ->fields('ml') - ->condition('menu_name', 'shortcut-%', 'LIKE') - ->execute() - ->fetchAllAssoc('mlid'); - - foreach ($shortcuts as $shortcut) { - $record_id = db_insert('shortcut') - ->fields(array( - 'uuid' => $shortcut->uuid, - 'shortcut_set' => substr($shortcut->menu_name, 9), - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'weight' => $shortcut->weight, - 'route_name' => $shortcut->route_name, - 'route_parameters' => $shortcut->route_parameters, - )) - ->execute(); - db_insert('shortcut_field_data') - ->fields(array( - 'id' => $record_id, - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'default_langcode' => 1, - 'title' => $shortcut->link_title, - )) - ->execute(); - } - if (!empty($shortcuts)) { - db_delete('menu_links') - ->condition('mlid', array_keys($shortcuts), 'IN') - ->execute(); - } -} - -/** - * @} End of "addtogroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/simpletest/simpletest.install b/core/modules/simpletest/simpletest.install index a863581192be..3421dd0a7452 100644 --- a/core/modules/simpletest/simpletest.install +++ b/core/modules/simpletest/simpletest.install @@ -162,16 +162,3 @@ function simpletest_uninstall() { // Remove generated files. file_unmanaged_delete_recursive('public://simpletest'); } - -/** - * Move simpletest settings from variables to config. - */ -function simpletest_update_8000() { - update_variables_to_config('simpletest.settings', array( - 'simpletest_clear_results' => 'clear_results', - 'simpletest_httpauth_method' => 'httpauth.method', - 'simpletest_httpauth_password' => 'httpauth.password', - 'simpletest_httpauth_username' => 'httpauth.username', - 'simpletest_verbose' => 'verbose', - )); -} diff --git a/core/modules/statistics/statistics.install b/core/modules/statistics/statistics.install index 9b443e5f7aa0..44513411f68b 100644 --- a/core/modules/statistics/statistics.install +++ b/core/modules/statistics/statistics.install @@ -57,44 +57,3 @@ function statistics_schema() { return $schema; } - -/** - * Moves statistics settings from variables to config. - * - * @ingroup config_upgrade - */ -function statistics_update_8000() { - update_variables_to_config('statistics.settings', array( - 'statistics_count_content_views' => 'count_content_views', - 'statistics_block_top_day_num' => 'block.popular.top_day_limit', - 'statistics_block_top_all_num' => 'block.popular.top_all_limit', - 'statistics_block_top_last_num' => 'block.popular.top_recent_limit', - )); -} - -/** - * Make *id fields unsigned. - */ -function statistics_update_8001() { - db_drop_primary_key('node_counter'); - db_change_field('node_counter', 'nid', 'nid', - array( - 'description' => 'The {node}.nid for these statistics.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - array('primary key' => array('nid')) - ); -} - -/** - * Convert variables to state. - */ -function statistics_update_8002() { - update_variables_to_state(array( - 'node_cron_views_scale' => 'statistics.node_counter_scale', - 'statistics_day_timestamp' => 'statistics.day_timestamp', - )); -} diff --git a/core/modules/syslog/syslog.install b/core/modules/syslog/syslog.install index c36feeb8fa4d..8a2350a78fc1 100644 --- a/core/modules/syslog/syslog.install +++ b/core/modules/syslog/syslog.install @@ -13,24 +13,3 @@ function syslog_install() { // to be set dynamically during installation. \Drupal::config('syslog.settings')->set('facility', defined('LOG_LOCAL0') ? LOG_LOCAL0 : LOG_USER)->save(); } - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Update settings to the new configuration system. - **/ -function syslog_update_8000() { - update_variables_to_config('syslog.settings', array( - 'syslog_identity' => 'identity', - 'syslog_facility' => 'facility', - 'syslog_format' => 'format', - )); -} - -/** - * @} End of "addtogroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/DependencyHookInvocationTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyHookInvocationTest.php index 154643bd48c6..f9b0a86509f4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Update/DependencyHookInvocationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyHookInvocationTest.php @@ -19,7 +19,7 @@ class DependencyHookInvocationTest extends WebTestBase { * * @var array */ - public static $modules = array('update_test_1', 'update_test_2'); + public static $modules = array('update_test_0', 'update_test_1', 'update_test_2'); public static function getInfo() { return array( @@ -39,8 +39,8 @@ function setUp() { */ function testHookUpdateDependencies() { $update_dependencies = update_retrieve_dependencies(); - $this->assertTrue($update_dependencies['system'][8000]['update_test_1'] == 8000, 'An update function that has a dependency on two separate modules has the first dependency recorded correctly.'); - $this->assertTrue($update_dependencies['system'][8000]['update_test_2'] == 8001, 'An update function that has a dependency on two separate modules has the second dependency recorded correctly.'); - $this->assertTrue($update_dependencies['system'][8001]['update_test_1'] == 8002, 'An update function that depends on more than one update from the same module only has the dependency on the higher-numbered update function recorded.'); + $this->assertTrue($update_dependencies['update_test_0'][8001]['update_test_1'] == 8001, 'An update function that has a dependency on two separate modules has the first dependency recorded correctly.'); + $this->assertTrue($update_dependencies['update_test_0'][8001]['update_test_2'] == 8002, 'An update function that has a dependency on two separate modules has the second dependency recorded correctly.'); + $this->assertTrue($update_dependencies['update_test_0'][8002]['update_test_1'] == 8003, 'An update function that depends on more than one update from the same module only has the dependency on the higher-numbered update function recorded.'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/DependencyMissingTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyMissingTest.php index 6c7137174dc4..167beea91c0c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Update/DependencyMissingTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyMissingTest.php @@ -19,7 +19,7 @@ class DependencyMissingTest extends WebTestBase { * * @var array */ - public static $modules = array('update_test_2'); + public static $modules = array('update_test_0', 'update_test_2'); public static function getInfo() { return array( @@ -38,11 +38,11 @@ function setUp() { function testMissingUpdate() { $starting_updates = array( - 'update_test_2' => 8000, + 'update_test_2' => 8001, ); $update_graph = update_resolve_dependencies($starting_updates); - $this->assertTrue($update_graph['update_test_2_update_8000']['allowed'], "The module's first update function is allowed to run, since it does not have any missing dependencies."); - $this->assertFalse($update_graph['update_test_2_update_8001']['allowed'], "The module's second update function is not allowed to run, since it has a direct dependency on a missing update."); - $this->assertFalse($update_graph['update_test_2_update_8002']['allowed'], "The module's third update function is not allowed to run, since it has an indirect dependency on a missing update."); + $this->assertTrue($update_graph['update_test_2_update_8001']['allowed'], "The module's first update function is allowed to run, since it does not have any missing dependencies."); + $this->assertFalse($update_graph['update_test_2_update_8002']['allowed'], "The module's second update function is not allowed to run, since it has a direct dependency on a missing update."); + $this->assertFalse($update_graph['update_test_2_update_8003']['allowed'], "The module's third update function is not allowed to run, since it has an indirect dependency on a missing update."); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php index b00754682d44..5667be099c28 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php @@ -19,7 +19,7 @@ class DependencyOrderingTest extends WebTestBase { * * @var array */ - public static $modules = array('update_test_1', 'update_test_2', 'update_test_3'); + public static $modules = array('update_test_0', 'update_test_1', 'update_test_2', 'update_test_3'); public static function getInfo() { return array( @@ -39,12 +39,12 @@ function setUp() { */ function testUpdateOrderingSingleModule() { $starting_updates = array( - 'update_test_1' => 8000, + 'update_test_1' => 8001, ); $expected_updates = array( - 'update_test_1_update_8000', 'update_test_1_update_8001', 'update_test_1_update_8002', + 'update_test_1_update_8003', ); $actual_updates = array_keys(update_resolve_dependencies($starting_updates)); $this->assertEqual($expected_updates, $actual_updates, 'Updates within a single module run in the correct order.'); @@ -55,14 +55,14 @@ function testUpdateOrderingSingleModule() { */ function testUpdateOrderingModuleInterdependency() { $starting_updates = array( - 'update_test_2' => 8000, - 'update_test_3' => 8000, + 'update_test_2' => 8001, + 'update_test_3' => 8001, ); $update_order = array_keys(update_resolve_dependencies($starting_updates)); // Make sure that each dependency is satisfied. - $first_dependency_satisfied = array_search('update_test_2_update_8000', $update_order) < array_search('update_test_3_update_8000', $update_order); + $first_dependency_satisfied = array_search('update_test_2_update_8001', $update_order) < array_search('update_test_3_update_8001', $update_order); $this->assertTrue($first_dependency_satisfied, 'The dependency of the second module on the first module is respected by the update function order.'); - $second_dependency_satisfied = array_search('update_test_3_update_8000', $update_order) < array_search('update_test_2_update_8001', $update_order); + $second_dependency_satisfied = array_search('update_test_3_update_8001', $update_order) < array_search('update_test_2_update_8002', $update_order); $this->assertTrue($second_dependency_satisfied, 'The dependency of the first module on the second module is respected by the update function order.'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/InvalidUpdateHook.php b/core/modules/system/lib/Drupal/system/Tests/Update/InvalidUpdateHook.php new file mode 100644 index 000000000000..460d03fbdad7 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Update/InvalidUpdateHook.php @@ -0,0 +1,63 @@ +<?php + +/** + * @file + * Definition of Drupal\system\Tests\Update\InvalidUpdateHook. + */ + +namespace Drupal\system\Tests\Update; + +use Drupal\simpletest\WebTestBase; +use Drupal\Core\Extension\ExtensionSchemaVersionException; + +/** + * Tests for missing update dependencies. + */ +class InvalidUpdateHook extends WebTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('update_test_invalid_hook', 'update_script_test', 'dblog'); + + /** + * URL for the upgrade script. + * + * @var string + */ + private $update_url; + + /** + * A user account with upgrade permission. + * + * @var \Drupal\user\UserInterface + */ + private $update_user; + + public static function getInfo() { + return array( + 'name' => 'Invalid update hook', + 'description' => 'Tests that a module implementing hook_update_8000() causes an error to be displayed on update.', + 'group' => 'Update API', + ); + } + + function setUp() { + parent::setUp(); + require_once DRUPAL_ROOT . '/core/includes/update.inc'; + + $this->update_url = $GLOBALS['base_url'] . '/core/update.php'; + $this->update_user = $this->drupalCreateUser(array('administer software updates')); + } + + function testInvalidUpdateHook() { + // Confirm that a module with hook_update_8000() cannot be updated. + $this->drupalLogin($this->update_user); + $this->drupalGet($this->update_url); + $this->drupalPostForm($this->update_url, array(), t('Continue'), array('external' => TRUE)); + $this->assertText(t('Some of the pending updates cannot be applied because their dependencies were not met.')); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php index d581147cc67e..463b48688798 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php @@ -40,6 +40,28 @@ function setUp() { $this->update_user = $this->drupalCreateUser(array('administer software updates')); } + /** + * Tests that updates from schema versions prior to 8000 are prevented. + */ + function testInvalidMigration() { + // Mock a D7 system table so that the schema value of the system module + // can be retrieved. + db_create_table('system', $this->getSystemSchema()); + // Assert that the table exists. + $this->assertTrue(db_table_exists('system'), 'The table exists.'); + // Insert a value for the system module. + db_insert('system') + ->fields(array( + 'name' => 'system', + 'schema_version' => 7000, + )) + ->execute(); + $system_schema = db_query('SELECT schema_version FROM {system} WHERE name = :system', array(':system' => 'system'))->fetchField(); + $this->drupalGet($this->update_url, array('external' => TRUE)); + $text = 'Your system schema version is ' . $system_schema . '. Updating directly from a schema version prior to 8000 is not supported. You must <a href="https://drupal.org/node/2179269">migrate your site to Drupal 8</a> first.'; + $this->assertRaw($text, 'Updates from schema versions prior to 8000 are prevented.'); + } + /** * Tests access to the update script. */ @@ -99,7 +121,7 @@ function testRequirements() { $this->assertNoText('This is a requirements warning provided by the update_script_test module.'); $this->drupalPostForm(NULL, array(), t('Continue')); $this->drupalPostForm(NULL, array(), 'Apply pending updates'); - $this->assertText(t('The update_script_test_update_8000() update was executed successfully.'), 'End of update process was reached.'); + $this->assertText(t('The update_script_test_update_8001() update was executed successfully.'), 'End of update process was reached.'); // Confirm that all caches were cleared. $this->assertText(t('hook_cache_flush() invoked for update_script_test.module.'), 'Caches were cleared after resolving a requirements warning and applying updates.'); @@ -165,20 +187,46 @@ function testNoUpdateFunctionality() { * Tests update.php after performing a successful update. */ function testSuccessfulUpdateFunctionality() { - drupal_set_installed_schema_version('update_script_test', drupal_get_installed_schema_version('update_script_test') - 1); + $schema_version = drupal_get_installed_schema_version('update_script_test'); + $this->assertEqual($schema_version, 8001, 'update_script_test is initially installed with schema version 8001.'); + + // Set the installed schema version to one less than the current update. + drupal_set_installed_schema_version('update_script_test', $schema_version - 1); + $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE); + $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.'); + // Click through update.php with 'administer software updates' permission. $this->drupalLogin($this->update_user); $this->drupalPostForm($this->update_url, array(), t('Continue'), array('external' => TRUE)); $this->drupalPostForm(NULL, array(), t('Apply pending updates')); + + // Verify that updates were completed successfully. $this->assertText('Updates were attempted.'); $this->assertLink('site'); + $this->assertText('The update_script_test_update_8001() update was executed successfully.'); + + // Verify that no 7.x updates were run. + $this->assertNoText('The update_script_test_update_7200() update was executed successfully.'); + $this->assertNoText('The update_script_test_update_7201() update was executed successfully.'); + + // Verify that there are no links to different parts of the workflow. $this->assertNoLink('Administration pages'); $this->assertNoLinkByHref('update.php', 0); $this->assertNoLink('logged'); + + // Verify the front page can be visited following the upgrade. $this->clickLink('Front page'); $this->assertResponse(200); - drupal_set_installed_schema_version('update_script_test', drupal_get_installed_schema_version('update_script_test') - 1); + // Reset the static cache to ensure we have the most current setting. + $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE); + $this->assertEqual($schema_version, 8001, 'update_script_test schema version is 8001 after updating.'); + + // Set the installed schema version to one less than the current update. + drupal_set_installed_schema_version('update_script_test', $schema_version - 1); + $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE); + $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.'); + // Click through update.php with 'access administration pages' and // 'access site reports' permissions. $admin_user = $this->drupalCreateUser(array('administer software updates', 'access administration pages', 'access site reports')); @@ -192,4 +240,78 @@ function testSuccessfulUpdateFunctionality() { $this->clickLink('Administration pages'); $this->assertResponse(200); } + + /** + * Returns the Drupal 7 system table schema. + */ + public function getSystemSchema() { + return array( + 'description' => "A list of all modules, themes, and theme engines that are or have been installed in Drupal's file system.", + 'fields' => array( + 'filename' => array( + 'description' => 'The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'name' => array( + 'description' => 'The name of the item; e.g. node.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'type' => array( + 'description' => 'The type of the item, either module, theme, or theme_engine.', + 'type' => 'varchar', + 'length' => 12, + 'not null' => TRUE, + 'default' => '', + ), + 'owner' => array( + 'description' => "A theme's 'parent' . Can be either a theme or an engine.", + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'status' => array( + 'description' => 'Boolean indicating whether or not this item is enabled.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + 'bootstrap' => array( + 'description' => "Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted).", + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + 'schema_version' => array( + 'description' => "The module's database schema version number. -1 if the module is not installed (its tables do not exist); \Drupal::CORE_MINIMUM_SCHEMA_VERSION or the largest N of the module's hook_update_N() function that has either been run or existed when the module was first installed.", + 'type' => 'int', + 'not null' => TRUE, + 'default' => -1, + 'size' => 'small', + ), + 'weight' => array( + 'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.", + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + 'info' => array( + 'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.", + 'type' => 'blob', + 'not null' => FALSE, + ), + ), + 'primary key' => array('filename'), + 'indexes' => array( + 'system_list' => array('status', 'bootstrap', 'type', 'weight', 'name'), + 'type_name' => array('type', 'name'), + ), + ); + } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/UpdatesWith7x.php b/core/modules/system/lib/Drupal/system/Tests/Update/UpdatesWith7x.php new file mode 100644 index 000000000000..4d85f9dc890d --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Update/UpdatesWith7x.php @@ -0,0 +1,63 @@ +<?php + +/** + * @file + * Definition of Drupal\system\Tests\Update\UpdatesWith7x. + */ + +namespace Drupal\system\Tests\Update; + +use Drupal\simpletest\WebTestBase; + +/** + * Tests for missing update dependencies. + */ +class UpdatesWith7x extends WebTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('update_test_with_7x'); + + /** + * The URL for the update page. + */ + private $update_url; + + /** + * An administrative user. + */ + private $update_user; + + public static function getInfo() { + return array( + 'name' => '7.x update hooks', + 'description' => 'Tests that the minimum schema version is correct even if only 7.x update hooks are retained .', + 'group' => 'Update API', + ); + } + + function setUp() { + parent::setUp(); + require_once DRUPAL_ROOT . '/core/includes/update.inc'; + $this->update_url = $GLOBALS['base_url'] . '/core/update.php'; + $this->update_user = $this->drupalCreateUser(array('administer software updates')); + } + + function testWith7x() { + // Ensure that the minimum schema version is 8000, despite 7200 update + // hooks and a 7XXX hook_update_last_removed(). + $this->assertEqual(drupal_get_installed_schema_version('update_test_with_7x'), 8000); + + // Try to manually set the schema version to 7110 and ensure that no + // updates are allowed. + drupal_set_installed_schema_version('update_test_with_7x', 7110); + + // Click through update.php with 'administer software updates' permission. + $this->drupalLogin($this->update_user); + $this->drupalPostForm($this->update_url, array(), t('Continue'), array('external' => TRUE)); + $this->assertText(t('Some of the pending updates cannot be applied because their dependencies were not met.')); + } +} diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 6c8361115f8b..a3b9d67425b9 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -2258,22 +2258,24 @@ function hook_install() { * The numbers are composed of three parts: * - 1 digit for Drupal core compatibility. * - 1 digit for your module's major release version (e.g., is this the 8.x-1.* - * (1) or 8.x-2.* (2) series of your module?). This digit should be 0 for - * initial porting of your module to a new Drupal core API. - * - 2 digits for sequential counting, starting with 00. + * (1) or 8.x-2.* (2) series of your module). + * - 2 digits for sequential counting, starting with 01. * * Examples: - * - mymodule_update_8000(): This is the required update for mymodule to run - * with Drupal core API 8.x when upgrading from Drupal core API 7.x. * - mymodule_update_8100(): This is the first update to get the database ready * to run mymodule 8.x-1.*. * - mymodule_update_8200(): This is the first update to get the database ready - * to run mymodule 8.x-2.*. Users can directly update from 7.x-2.* to 8.x-2.* - * and they get all 80xx and 82xx updates, but not 81xx updates, because - * those reside in the 8.x-1.x branch only. + * to run mymodule 8.x-2.*. + * + * As of Drupal 8.0, the database upgrade system no longer supports updating a + * database from an earlier major version of Drupal: update.php can be used to + * upgrade from 7.x-1.x to 7.x-2.x, or 8.x-1.x to 8.x-2.x, but not from 7.x to + * 8.x. Therefore, only update hooks numbered 8001 or later will run for + * Drupal 8. 8000 is reserved for the minimum core schema version and defining + * mymodule_update_8000() will result in an exception. Use the + * @link https://drupal.org/node/2127611 Migration API @endlink instead to + * migrate data from an earlier major version of Drupal. * - * A good rule of thumb is to remove updates older than two major releases of - * Drupal. See hook_update_last_removed() to notify Drupal about the removals. * For further information about releases and release numbers see: * @link http://drupal.org/node/711070 Maintaining a drupal.org project with Git @endlink * @@ -2398,21 +2400,21 @@ function hook_update_N(&$sandbox) { * @see hook_update_N() */ function hook_update_dependencies() { - // Indicate that the mymodule_update_8000() function provided by this module - // must run after the another_module_update_8002() function provided by the + // Indicate that the mymodule_update_8001() function provided by this module + // must run after the another_module_update_8003() function provided by the // 'another_module' module. - $dependencies['mymodule'][8000] = array( - 'another_module' => 8002, + $dependencies['mymodule'][8001] = array( + 'another_module' => 8003, ); - // Indicate that the mymodule_update_8001() function provided by this module - // must run before the yet_another_module_update_8004() function provided by + // Indicate that the mymodule_update_8002() function provided by this module + // must run before the yet_another_module_update_8005() function provided by // the 'yet_another_module' module. (Note that declaring dependencies in this // direction should be done only in rare situations, since it can lead to the // following problem: If a site has already run the yet_another_module // module's database updates before it updates its codebase to pick up the // newest mymodule code, then the dependency declared here will be ignored.) - $dependencies['yet_another_module'][8004] = array( - 'mymodule' => 8001, + $dependencies['yet_another_module'][8005] = array( + 'mymodule' => 8002, ); return $dependencies; } @@ -2434,9 +2436,9 @@ function hook_update_dependencies() { * @see hook_update_N() */ function hook_update_last_removed() { - // We've removed the 5.x-1.x version of mymodule, including database updates. - // The next update function is mymodule_update_5200(). - return 5103; + // We've removed the 8.x-1.x version of mymodule, including database updates. + // The next update function is mymodule_update_8200(). + return 8103; } /** @@ -3232,10 +3234,10 @@ function hook_link_alter(&$variables) { * API function including the module's name. * * Examples: - * - _update_7000_mymodule_save(): This function performs a save operation - * without invoking any hooks using the 7.x schema. - * - _update_8000_mymodule_save(): This function performs the same save - * operation using the 8.x schema. + * - _update_8001_mymodule_save(): This function performs a save operation + * without invoking any hooks using the original 8.x schema. + * - _update_8002_mymodule_save(): This function performs the same save + * operation using an updated 8.x schema. * * The utility function should not invoke any hooks, and should perform database * operations using functions from the @@ -3244,69 +3246,69 @@ function hook_link_alter(&$variables) { * * If a change to the schema necessitates a change to the utility function, a * new function should be created with a name based on the version of the schema - * it acts on. See _update_8000_bar_get_types() and _update_8001_bar_get_types() + * it acts on. See _update_8002_bar_get_types() and _update_8003_bar_get_types() * in the code examples that follow. * * For example, foo.install could contain: * @code * function foo_update_dependencies() { - * // foo_update_8010() needs to run after bar_update_8000(). + * // foo_update_8010() needs to run after bar_update_8002(). * $dependencies['foo'][8010] = array( - * 'bar' => 8000, + * 'bar' => 8002, * ); * - * // foo_update_8036() needs to run after bar_update_8001(). + * // foo_update_8036() needs to run after bar_update_8003(). * $dependencies['foo'][8036] = array( - * 'bar' => 8001, + * 'bar' => 8003, * ); * * return $dependencies; * } * - * function foo_update_8000() { + * function foo_update_8002() { * // No updates have been run on the {bar_types} table yet, so this needs - * // to work with the 7.x schema. - * foreach (_update_7000_bar_get_types() as $type) { + * // to work with the original 8.x schema. + * foreach (_update_8001_bar_get_types() as $type) { * // Rename a variable. * } * } * * function foo_update_8010() { - * // Since foo_update_8010() is going to run after bar_update_8000(), it + * // Since foo_update_8010() is going to run after bar_update_8002(), it * // needs to operate on the new schema, not the old one. - * foreach (_update_8000_bar_get_types() as $type) { + * foreach (_update_8002_bar_get_types() as $type) { * // Rename a different variable. * } * } * * function foo_update_8036() { - * // This update will run after bar_update_8001(). - * foreach (_update_8001_bar_get_types() as $type) { + * // This update will run after bar_update_8003(). + * foreach (_update_8003_bar_get_types() as $type) { * } * } * @endcode * * And bar.install could contain: * @code - * function bar_update_8000() { + * function bar_update_8002() { * // Type and bundle are confusing, so we renamed the table. * db_rename_table('bar_types', 'bar_bundles'); * } * - * function bar_update_8001() { + * function bar_update_8003() { * // Database table names should be singular when possible. * db_rename_table('bar_bundles', 'bar_bundle'); * } * - * function _update_7000_bar_get_types() { + * function _update_8001_bar_get_types() { * db_query('SELECT * FROM {bar_types}')->fetchAll(); * } * - * function _update_8000_bar_get_types() { + * function _update_8002_bar_get_types() { * db_query('SELECT * FROM {bar_bundles'})->fetchAll(); * } * - * function _update_8001_bar_get_types() { + * function _update_8003_bar_get_types() { * db_query('SELECT * FROM {bar_bundle}')->fetchAll(); * } * @endcode diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 25f75c7934ac..8fdd9989c182 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1133,1134 +1133,3 @@ function system_schema() { return $schema; } - -/** - * The cache schema corresponding to Drupal 8.0. - * - * Helper function to add cache tables in the Drupal 7 to 8 upgrade path - * without relying on system_schema(), which may change with future updates. - */ -function system_schema_cache_8007() { - return array( - 'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.', - 'fields' => array( - 'cid' => array( - 'description' => 'Primary Key: Unique cache ID.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'data' => array( - 'description' => 'A collection of data to cache.', - 'type' => 'blob', - 'not null' => FALSE, - 'size' => 'big', - ), - 'expire' => array( - 'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'created' => array( - 'description' => 'A Unix timestamp indicating when the cache entry was created.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'serialized' => array( - 'description' => 'A flag to indicate whether content is serialized (1) or not (0).', - 'type' => 'int', - 'size' => 'small', - 'not null' => TRUE, - 'default' => 0, - ), - 'tags' => array( - 'description' => 'Space-separated list of cache tags for this entry.', - 'type' => 'text', - 'size' => 'big', - 'not null' => FALSE, - ), - 'checksum_invalidations' => array( - 'description' => 'The tag invalidation sum when this entry was saved.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'checksum_deletions' => array( - 'description' => 'The tag deletion sum when this entry was saved.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'indexes' => array( - 'expire' => array('expire'), - ), - 'primary key' => array('cid'), - ); -} - -// Updates for core. - -function system_update_last_removed() { - return 7069; -} - -//Do not copy @defgroup to other files. Use @addtogroup instead. -/** - * @defgroup config_upgrade Configuration system upgrade functions - * @{ - * Module update functions that - * - update variables prior to configuration system conversions - * - convert variables to the new configuration system - * - update configuration system values after conversion - * - * @} End of "defgroup config_upgrade". - */ - -/** - * @defgroup updates-7.x-to-8.x Updates from 7.x to 8.x - * @{ - * Update functions from 7.x to 8.x. - */ - -/** - * Move from the Garland theme. - */ -function system_update_8001() { - $themes = array('theme_default', 'maintenance_theme', 'admin_theme'); - foreach ($themes as $theme) { - if (update_variable_get($theme) == 'garland') { - update_variable_set($theme, 'bartik'); - } - } -} - -/** - * Set 'node' as front page path and Bartik as default theme if it implicitly was before. - * - * Node module became optional. The default front page path was changed to - * 'user'. Since 'node' was the implicit default front page path previously and - * may not have been explicitly configured as such, this update ensures that the - * old implicit default is still the default. - * - * @see http://drupal.org/node/375397 - * - * The default theme for Drupal core was changed from Bartik to Stark. - * Installation profiles (including Standard and Minimal) were changed to - * explicitly configure Bartik as default theme. Since Bartik was the default - * theme by default and may not have been explicitly configured as such - * previously, this update ensures that the implicit Bartik default is still the - * default. - * - * @see http://drupal.org/node/1181776 - * - * @ingroup config_upgrade - */ -function system_update_8002() { - $front_page = update_variable_get('site_frontpage'); - if (!isset($front_page)) { - update_variable_set('site_frontpage', 'node'); - } - $theme = update_variable_get('theme_default'); - if (!isset($theme)) { - update_variable_set('theme_default', 'bartik'); - } -} - -/** - * Create {cache_config} cache table for the new configuration system. - */ -function system_update_8003() { - // Moved to update_prepare_d8_bootstrap. -} - -/** - * Add {file_managed}.langcode field. - * - * @see http://drupal.org/node/1454538 - */ -function system_update_8004() { - $langcode_field = array( - 'description' => 'The {language}.langcode of this file.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ); - - // If a Drupal 7 contrib module already added a langcode field to support - // internationalization, keep it, but standardize the specification. - // Otherwise, add the field. - if (db_field_exists('file_managed', 'langcode')) { - // According to the documentation of db_change_field(), indices using the - // field should be dropped first; if the contrib module created any indices, - // it is its responsibility to drop them in an update function that runs - // before this one, which it can enforce via hook_update_dependencies(). - db_change_field('file_managed', 'langcode', 'langcode', $langcode_field); - } - else { - // Files can be language-specific (e.g., a scanned document) or not (e.g., - // a photograph). For a site being updated, Drupal does not have a way to - // determine which existing files are language-specific and in what - // language. Our best guess is to set all of them to Language::LANGCODE_NOT_SPECIFIED. - $langcode_field['initial'] = Language::LANGCODE_NOT_SPECIFIED; - db_add_field('file_managed', 'langcode', $langcode_field); - } -} - -/** - * Remove the obsolete {session}.cache column. - */ -function system_update_8005() { - db_drop_field('session', 'cache'); -} - -/** - * Add the {cache_tags} table. - */ -function system_update_8006() { - // Moved to update_prepare_d8_bootstrap. -} - -/** - * Modify existing cache tables, adding support for cache tags. - */ -function system_update_8007() { - // Moved to update_prepare_d8_bootstrap. -} - -/** - * Remove the 'clean_url' configuration variable. - */ -function system_update_8008() { - update_variable_del('clean_url'); -} - -/** - * Move cron system settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8009() { - update_variables_to_config('system.cron', array( - 'cron_safe_threshold' => 'threshold.autorun', - 'cron_threshold_warning' => 'threshold.requirements_warning', - 'cron_threshold_error' => 'threshold.requirements_error', - )); -} - -/** - * Move RSS system settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8010() { - update_variables_to_config('system.rss', array( - 'feed_description' => 'channel.description', - 'feed_default_items' => 'items.limit', - 'feed_item_length' => 'items.view_mode', - )); -} - -/** - * Update the module and base fields for the blog node type. - */ -function system_update_8011() { - db_update('node_type') - ->fields(array( - 'module' => 'node', - 'base' => 'node_content', - )) - ->condition('module', 'blog') - ->execute(); -} - -/** - * Move site system settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8012() { - update_variables_to_config('system.site', array( - 'site_name' => 'name', - 'site_mail' => 'mail', - 'site_slogan' => 'slogan', - 'site_frontpage' => 'page.front', - 'site_403' => 'page.403', - 'site_404' => 'page.404', - 'drupal_weight_select_max' => 'weight_select_max', - )); -} - -/** - * Add description_callback and description_arguments fields to {menu_router}. - */ -function system_update_8013() { - if (!db_field_exists('menu_router', 'description_callback')) { - $spec = array( - 'description' => 'A function which will alter the description. Defaults to t().', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ); - db_add_field('menu_router', 'description_callback', $spec); - } - if (!db_field_exists('menu_router', 'description_arguments')) { - $spec = array( - 'description' => 'A serialized array of arguments for the description callback. If empty, the description will be used as the sole argument for the description callback.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ); - db_add_field('menu_router', 'description_arguments', $spec); - } -} - -/** - * Move system logging settings from variables to config. - * - * @ingroup config_upgrade - */ -function system_update_8014() { - // Not using update_variables_to_config(), since the only value is - // 'error_level', which needs to be mapped to a new value. - $config = \Drupal::config('system.logging'); - $error_level = db_query("SELECT value FROM {variable} WHERE name = 'error_level'")->fetchField(); - if ($error_level !== FALSE) { - $error_level = unserialize($error_level); - $map = array( - '0' => 'hide', - '1' => 'some', - '2' => 'all', - '3' => 'verbose', - ); - // Update error_level value to a string identifier. - $config->set('error_level', $map[$error_level]); - // Delete the migrated variable. - db_delete('variable')->condition('name', 'error_level')->execute(); - } - else { - // Set error_level to the default value. - $config->set('error_level', 'all'); - } - $config->save(); -} - -/** - * Create a UUID column for managed files. - */ -function system_update_8015() { - $spec = array( - 'description' => 'Unique Key: Universally unique identifier for this entity.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - ); - $keys = array( - 'unique keys' => array( - 'uuid' => array('uuid'), - ), - ); - // Account for sites having the contributed UUID module installed. - if (db_field_exists('file_managed', 'uuid')) { - db_change_field('file_managed', 'uuid', 'uuid', $spec, $keys); - } - else { - db_add_field('file_managed', 'uuid', $spec, $keys); - } -} - -/** - * Move the system maintenance settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8016() { - update_variables_to_config('system.maintenance', array( - 'maintenance_mode_message' => 'message', - )); - update_variables_to_state(array( - 'maintenance_mode' => 'system.maintenance_mode', - )); -} - -/** - * Move system performance settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8017() { - update_variables_to_config('system.performance', array( - 'cache' => 'cache.page.use_internal', - 'page_cache_maximum_age' => 'cache.page.max_age', - 'page_compression' => 'response.gzip', - 'preprocess_css' => 'css.preprocess', - 'preprocess_js' => 'js.preprocess', - 'stale_file_threshold' => 'stale_file_threshold', - )); -} - -/** - * Remove the registry tables. - */ -function system_update_8019() { - db_drop_table('registry'); - db_drop_table('registry_file'); -} - -/** - * Conditionally enable the new Ban module. - */ -function system_update_8020() { - $blocked_ips_exists = db_query_range('SELECT 1 FROM {blocked_ips}', 0, 1)->fetchField(); - if ($blocked_ips_exists) { - // Rename the permission name. - update_replace_permissions(array( - 'block IP addresses' => array('ban IP addresses'), - )); - // Rename {blocked_ips} table into {ban_ip}. - db_rename_table('blocked_ips', 'ban_ip'); - // Remove all references to the removed action callback. - db_delete('actions') - ->condition('callback', 'system_block_ip_action') - ->execute(); - db_delete('actions') - ->condition('aid', 'system_block_ip_action') - ->execute(); - // Enable the new Ban module. - \Drupal::moduleHandler()->install(array('ban')); - } - else { - // Drop old table. - db_drop_table('blocked_ips'); - } -} - -/** - * Enable the Actions module. - */ -function system_update_8021() { - // Enable the module without re-installing the schema. - \Drupal::moduleHandler()->install(array('action')); - // Rename former System module actions. - $map = array( - 'system_message_action' => 'action_message_action', - 'system_send_email_action' => 'action_send_email_action', - 'system_goto_action' => 'action_goto_action', - ); - foreach ($map as $old => $new) { - // Rename all references to the action callback. - db_update('actions') - ->fields(array('callback' => $new)) - ->condition('callback', $old) - ->execute(); - // Rename the action's aid. - db_update('actions') - ->fields(array('aid' => $new)) - ->condition('aid', $old) - ->execute(); - } -} - -/** - * Create the new routing table. - */ -function system_update_8022() { - - $tables['router'] = array( - 'description' => 'Maps paths to various callbacks (access, page and title)', - 'fields' => array( - 'name' => array( - 'description' => 'Primary Key: Machine name of this route', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'path' => array( - 'description' => 'The path for this URI', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'pattern_outline' => array( - 'description' => 'The pattern', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'provider' => array( - 'description' => 'The provider grouping to which a route belongs.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'fit' => array( - 'description' => 'A numeric representation of how specific the path is.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'route' => array( - 'description' => 'A serialized Route object', - 'type' => 'text', - ), - 'number_parts' => array( - 'description' => 'Number of parts in this router path.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'small', - ), - ), - 'indexes' => array( - 'pattern_outline_fit' => array('pattern_outline', 'fit'), - 'provider' => array('provider'), - ), - 'primary key' => array('name'), - ); - - $schema = Database::getConnection()->schema(); - - $schema->dropTable('router'); - - $schema->createTable('router', $tables['router']); -} - -/** - * Create the 'key_value_expire' table. - */ -function system_update_8023() { - // Moved to update_fix_d8_requirements() as it is required early. -} - -/** - * Generate a UUID for all files. - */ -function system_update_8024(&$sandbox) { - if (!isset($sandbox['progress'])) { - $sandbox['progress'] = 0; - $sandbox['last'] = 0; - $sandbox['max'] = db_query('SELECT COUNT(fid) FROM {file_managed} WHERE uuid IS NULL')->fetchField(); - } - - $fids = db_query_range('SELECT fid FROM {file_managed} WHERE fid > :fid AND uuid IS NULL ORDER BY fid ASC', 0, 10, array(':fid' => $sandbox['last']))->fetchCol(); - update_add_uuids($sandbox, 'file_managed', 'fid', $fids); - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); -} - -/** - * Remove {system} table. - */ -function system_update_8025() { - db_drop_table('system'); -} - -/** - * Clean up javascript_parsed variable. - * - * @ingroup system_upgrade - */ -function system_update_8027() { - update_variable_del('javascript_parsed'); -} - -/** - * Remove the 'menu_masks' configuration variable. - */ -function system_update_8028() { - // No upgrade path needed since the menu router will be rebuilt during the - // Drupal 7 to Drupal 8 upgrade. - update_variable_del('menu_masks'); -} - -/** - * Convert path_alias_whitelist variable to state API. - * - * @ingroup state_upgrade - */ -function system_update_8029() { - if ($value = update_variable_get('path_alias_whitelist', FALSE)) { - \Drupal::state()->set('system.path_alias_whitelist', $value); - } - update_variable_del('path_alias_whitelist'); -} - - /** - * Move authorize system settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8030() { - update_variables_to_config('system.authorize', array( - 'authorize_filetransfer_default' => 'filetransfer_default', - )); -} - -/** - * Rename default menu names. - */ -function system_update_8031() { - $map = array( - 'navigation' => 'tools', - 'management' => 'admin', - 'user-menu' => 'account', - 'main-menu' => 'main', - ); - foreach ($map as $old => $new) { - db_update('menu_links') - ->condition('menu_name', $old) - ->fields(array('menu_name' => $new)) - ->execute(); - } -} - -/** - * Remove the drupal_js_cache_files and css_js_query_string variables. - * - * @ingroup config_upgrade - */ -function system_update_8032() { - update_variable_del('drupal_js_cache_files'); - update_variable_del('css_js_query_string'); -} - -/** - * Convert active_menus_default variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8033() { - update_variables_to_config('system.menu', array( - 'menu_default_active_menus' => 'active_menus_default' - )); -} - -/** - * Move cron last run time and cron key from variable to state. - * - * @ingroup config_upgrade - */ -function system_update_8034() { - update_variables_to_state(array( - 'cron_last' => 'system.cron_last', - 'cron_key' => 'system.cron_key', - )); -} - -/** - * Move filter_allowed_protocols variable to config. - * - * This config is provided now by the system module because it is used by - * \Drupal\Component\Utility\Url::stripDangerousProtocols() and must to be - * available before the filter module be installed. - * - * @ingroup config_upgrade - */ -function system_update_8035() { - update_variables_to_config('system.filter', array( - 'filter_allowed_protocols' => 'protocols', - )); -} - -/** - * Move the admin_compact_mode setting from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8036() { - update_variables_to_config('system.site', array( - 'admin_compact_mode' => 'admin_compact_mode', - )); -} - -/** - * Remove the 'password_count_log2' variable. - * - * @ingroup config_upgrade - */ -function system_update_8037() { - update_variable_del('password_count_log2'); -} - -/** - * Move site system regional settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8038() { - update_variables_to_config('system.date', array( - 'site_default_country' => 'country.default', - 'date_first_day' => 'first_day', - 'date_default_timezone' => 'timezone.default', - 'configurable_timezones' => 'timezone.user.configurable', - 'empty_timezone_message' => 'timezone.user.warn', - 'user_default_timezone' => 'timezone.user.default', - )); -} - -/** - * Convert css and js gzip compression variables to config. - * - * @ingroup config_upgrade - */ -function system_update_8039() { - $variable_map = array( - 'css_gzip_compression' => 'css.gzip', - 'js_gzip_compression' => 'js.gzip' - ); - update_variables_to_config('system.performance', $variable_map); -} - -/** - * Move action_max_stack from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8040() { - update_variables_to_config('action.settings', array( - 'actions_max_stack' => 'recursion_limit', - )); -} - -/** - * Convert admin_theme variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8041() { - update_variables_to_config('system.theme', array( - 'admin_theme' => 'admin', - 'theme_default' => 'default' - )); -} - -/** - * Enable the new Entity module. - */ -function system_update_8042() { - \Drupal::moduleHandler()->install(array('entity')); -} - -/** - * Move system fast 404 settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8044() { - update_variables_to_config('system.performance', array( - 'fast_404_html' => 'fast_404.html', - 'fast_404_paths' => 'fast_404.paths', - 'fast_404_paths_exclude' => 'fast_404.exclude_paths', - )); -} - -/** - * Convert existing date formats to the new config system. - * - * @ingroup config_upgrade - */ -function system_update_8045() { - $uuid = \Drupal::service('uuid'); - // Fetch all date types from {date_format_type}. - $date_formats = db_query('SELECT * FROM {date_format_type}')->fetchAllAssoc('type', PDO::FETCH_ASSOC); - if (!empty($date_formats)) { - foreach ($date_formats as $type => $format) { - // Set name and locked properties. - $config = \Drupal::config("system.date_format.$type") - ->set('id', $type) - ->set('label', $format['title']) - ->set('locked', $format['locked']) - ->set('status', 1) - ->set('uuid', $uuid->generate()); - - // Get the default date format for this type. - $variable_name = 'date_format_' . $type; - $default_format = update_variable_get($variable_name, NULL); - if ($default_format) { - // In Drupal 7 we only used PHP date types. - $config->set('pattern.php', $default_format); - - // Delete the migrated variables. - update_variable_del($variable_name); - } - // Save the date configuration object. - $config->save(); - } - } - - // Install the new HTML date formats. - $new_formats = array( - 'system.date_format.fallback', - 'system.date_format.html_date', - 'system.date_format.html_datetime', - 'system.date_format.html_month', - 'system.date_format.html_time', - 'system.date_format.html_week', - 'system.date_format.html_year', - 'system.date_format.html_yearless_date', - ); - foreach ($new_formats as $new_format) { - update_install_default_config('module', $new_format); - } -} - -/** - * Install new default views. - */ -function system_update_8046() { - update_install_default_config('module', 'views.view.user_admin_people', 'user'); - update_install_default_config('module', 'views.view.content', 'node'); - - $front_page = \Drupal::config('system.site')->get('page.front') ?: 'node'; - if ($front_page == 'node') { - // This imports the node frontpage view. - update_install_default_config('module', 'views.view.frontpage', 'node'); - } -} - -/** - * Move site system settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8047() { - update_variables_to_config('system.file', array( - 'allow_insecure_uploads' => 'allow_insecure_uploads', - 'file_default_scheme' => 'default_scheme', - // Note: the chmod variables were later moved to the settings system. - 'file_chmod_directory' => 'chmod.directory', - 'file_chmod_file' => 'chmod.file', - 'file_private_path' => 'path.private', - 'file_temporary_path' => 'path.temporary', - )); -} - -/** - * Enable the new Menu link module. - * - * Creates the langcode and UUID columns for menu links. - */ -function system_update_8048() { - // Enable the module without re-installing the schema. - \Drupal::moduleHandler()->install(array('menu_link')); - - // Add the langcode column if it doesn't exist. - if (!db_field_exists('menu_inks', 'langcode')) { - $column = array( - 'description' => 'The {language}.langcode of this entity.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ); - db_add_field('menu_links', 'langcode', $column); - } - - // Add the UUID column. - $column = array( - 'description' => 'Unique Key: Universally unique identifier for this entity.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - ); - $keys = array( - 'unique keys' => array( - 'uuid' => array('uuid'), - ), - ); - db_add_field('menu_links', 'uuid', $column, $keys); -} - -/** - * Create the 'config_snapshot' table. - */ -function system_update_8049() { - $table = array( - 'description' => 'Stores a snapshot of the last imported configuration.', - 'fields' => array( - 'name' => array( - 'description' => 'The identifier for the config object (the name of the file, minus the file extension).', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'data' => array( - 'description' => 'The raw data for this configuration object.', - 'type' => 'blob', - 'not null' => TRUE, - 'size' => 'big', - ), - ), - 'primary key' => array('name'), - ); - - db_create_table('config_snapshot', $table); -} - -/** - * Convert mail settings to config. - * - * @ingroup config_upgrade - */ -function system_update_8050() { - // Update any mail interfaces to their Drupal 8 equivalents. - $old_mail_system_settings = update_variable_get('mail_system'); - - if ($old_mail_system_settings) { - $new_mail_system_settings = array(); - - foreach ($old_mail_system_settings as $key => $mailer_class) { - // Update old class name to PSR-0. - if ($mailer_class == 'DefaultMailSystem') { - $mailer_class = 'Drupal\Core\Mail\PhpMail'; - } - // New default key. - if ($key == 'default-system') { - $new_mail_system_settings['default'] = $mailer_class; - unset($old_mail_system_settings[$key]); - } - } - if (count($old_mail_system_settings)) { - // Warn about non-core classes which may need to be updated. - drupal_set_message(format_string('The following mail backends need to be re-configured: @list.', array('@list' => implode(', ', $old_mail_system_settings))), 'warning'); - } - - $new_mail_system_settings += $old_mail_system_settings; - // Save the updated variable, and let update_variables_to_config convert it. - if ($new_mail_system_settings) { - update_variable_set('mail_system', $new_mail_system_settings); - } - } - update_variables_to_config('system.mail', array( - 'mail_system' => 'interface', - )); -} - -/** - * Add route_name column to the menu_links table. - */ -function system_update_8051() { - $spec = array( - 'description' => 'The machine name of a defined Symfony Route this menu item represents.', - 'type' => 'varchar', - 'length' => 255, - ); - - db_add_field('menu_links', 'route_name', $spec); -} - -/** - * Move image toolkit settings from variable to config. - * - * @ingroup config_upgrade - */ -function system_update_8052() { - update_variables_to_config('system.image', array( - 'image_toolkit' => 'toolkit', - )); - update_variables_to_config('system.image.gd', array( - 'image_jpeg_quality' => 'jpeg_quality', - )); -} - -/** - * Remove {cache_form} table. - */ -function system_update_8053() { - db_drop_table('cache_form'); -} - -/** - * Add route_name column to the menu_router table. - */ -function system_update_8054() { - $spec = array( - 'description' => 'The machine name of a defined Symfony Route this menu item represents.', - 'type' => 'varchar', - 'length' => 255, - ); - - db_add_field('menu_router', 'route_name', $spec); -} - -/** - * Move system theme settings from variables to config. - */ -function system_update_8055() { - // Install the global theme settings from the system module. - update_install_default_config('module', 'system.theme.global'); - // Add the global settings to a map for variable to configuration conversion. - $theme_settings_to_config_map = array('theme_settings' => 'system.theme.global'); - - // Can only upgrade core themes since if you follow the instructions in - // UPGRADE.txt list_themes() would only return core themes at this point. - // Therefore limit to a hard coded list to ensure that this update only - // applies to core provided themes. - $core_themes = array( - 'bartik', - 'seven', - 'stark', - ); - - // Add the core theme to the variable to configuration conversion map and - // install the default configuration. - foreach ($core_themes as $theme) { - $variable = 'theme_' . $theme . '_settings'; - $config_name = $theme . '.settings'; - $theme_settings_to_config_map[$variable] = $config_name; - update_install_default_config('theme', $config_name); - } - - // Convert array of theme settings from Drupal 7's variable system to Drupal - // 8's configuration management system. - foreach ($theme_settings_to_config_map as $variable => $config_name) { - $config = \Drupal::config($config_name); - $theme_settings = update_variable_get($variable); - if (!empty($theme_settings)) { - theme_settings_convert_to_config($theme_settings, $config)->save(); - } - update_variable_del($variable); - } -} - -/** - * Move entity view modes to config. - * - * @ingroup config_upgrade - */ -function system_update_8056() { - // We cannot call entity_get_info() in an update hook, so we hardcode the view - // modes. Only the node entity type's teaser view mode is set to custom by - // default, we check specifically for that below. The only way to add custom - // view modes in Drupal 7 was hook_entity_info_alter(), which still works in - // Drupal 8. - $entity_view_modes = array( - 'node' => array( - 'full' => 'Full content', - 'teaser' => 'Teaser', - 'rss' => 'RSS', - 'search_index' => 'Search index', - 'search_result' => 'Search result', - 'print' => 'Print', - ), - 'comment' => array( - 'full' => 'Full comment', - ), - 'user' => array( - 'full' => 'User account', - 'compact' => 'Compact', - ), - 'taxonomy_term' => array( - 'full' => 'Taxonomy term page', - ), - ); - - foreach ($entity_view_modes as $entity_type => $view_modes) { - foreach ($view_modes as $key => $name) { - $status = in_array($key, array('teaser', 'compact')); - \Drupal::config("entity.view_mode.$entity_type.$key") - ->set('id', "$entity_type.$key") - ->set('label', $name) - ->set('targetEntityType', $entity_type) - ->set('status', $status) - ->save(); - } - } -} - -/** - * Convert actions to configuration. - * - * @ingroup config_upgrade - */ -function system_update_8057() { - $actions = db_query("SELECT * FROM {actions}")->fetchAllAssoc('aid', PDO::FETCH_ASSOC); - $action_plugins = \Drupal::service('plugin.manager.action')->getDefinitions(); - foreach ($actions as $action) { - if (isset($action_plugins[$action['callback']])) { - if (is_numeric($action['aid'])) { - $action['aid'] = $action['callback'] . '_' . $action['aid']; - } - $configuration = unserialize($action['parameters']) ?: array(); - \Drupal::config('system.action.' . $action['aid']) - ->set('id', $action['aid']) - ->set('label', $action['label']) - ->set('status', '1') - ->set('type', $action['type']) - ->set('plugin', $action['callback']) - ->set('configuration', $configuration) - ->save(); - } - } -} - -/** - * Change the length of the 'module' column to the maximum length. - * - * @see system_update_8048() - */ -function system_update_8058() { - if (db_field_exists('menu_links', 'module')) { - $spec = array( - 'description' => 'The name of the module that generated this link.', - 'type' => 'varchar', - 'length' => 50, - 'not null' => TRUE, - 'default' => 'system', - ); - db_change_field('menu_links', 'module', 'module', $spec); - } -} - -/** - * Move variable language_types to config. - * - * @ingroup config_upgrade - */ -function system_update_8059() { - update_variables_to_config('language.types', array( - 'language_interface' => 'configurable.language_interface', - 'language_content' => 'configurable.language_content', - 'language_url' => 'configurable.language_content', - )); -} - -/** - * Move the file_public_path variable to settings. - */ -function system_upgrade_8060() { - if ($path = update_variable_get('file_public_path')) { - drupal_rewrite_settings(array('settings' => array('file_public_path' => $path))); - } -} - -/** - * Add route_parameters column to the menu_links table. - */ -function system_update_8060() { - $spec = array( - 'description' => 'Serialized array of route parameters of this menu link.', - 'type' => 'blob', - 'size' => 'big', - 'not null' => FALSE, - 'serialize' => TRUE, - ); - - db_add_field('menu_links', 'route_parameters', $spec); -} - -/** - * @} End of "defgroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/system/tests/modules/update_script_test/update_script_test.install b/core/modules/system/tests/modules/update_script_test/update_script_test.install index 594dfa350249..0f1718d7d609 100644 --- a/core/modules/system/tests/modules/update_script_test/update_script_test.install +++ b/core/modules/system/tests/modules/update_script_test/update_script_test.install @@ -37,9 +37,30 @@ function update_script_test_requirements($phase) { return $requirements; } +/** + * Implements hook_update_last_removed(). + */ +function update_script_test_update_last_removed() { + return 7110; +} + +/** + * Dummy update_script_test update 7200. + */ +function update_script_test_update_7200() { + return 'The update_script_test_update_7200() update was executed successfully.'; +} + +/** + * Dummy update_script_test update 7201. + */ +function update_script_test_update_7201() { + return 'The update_script_test_update_7201() update was executed successfully.'; +} + /** * Dummy update function to run during the tests. */ -function update_script_test_update_8000() { - return t('The update_script_test_update_8000() update was executed successfully.'); +function update_script_test_update_8001() { + return 'The update_script_test_update_8001() update was executed successfully.'; } diff --git a/core/modules/system/tests/modules/update_test_0/update_test_0.info.yml b/core/modules/system/tests/modules/update_test_0/update_test_0.info.yml new file mode 100644 index 000000000000..d9f07cd263df --- /dev/null +++ b/core/modules/system/tests/modules/update_test_0/update_test_0.info.yml @@ -0,0 +1,7 @@ +name: 'Update test 0' +type: module +description: 'Support module for update testing.' +package: Testing +version: VERSION +core: 8.x +hidden: true diff --git a/core/modules/system/tests/modules/update_test_0/update_test_0.install b/core/modules/system/tests/modules/update_test_0/update_test_0.install new file mode 100644 index 000000000000..16e0c38438c4 --- /dev/null +++ b/core/modules/system/tests/modules/update_test_0/update_test_0.install @@ -0,0 +1,24 @@ +<?php + +/** + * @file + * Install, update and uninstall functions for the update_test_0 module. + */ + +/** + * Dummy update_test_0 update 8001. + */ +function update_test_0_update_8001() { +} + +/** + * Dummy update_test_0 update 8002. + */ +function update_test_0_update_8002() { +} + +/** + * Dummy update_test_0 update 8003. + */ +function update_test_0_update_8003() { +} diff --git a/core/modules/system/tests/modules/update_test_0/update_test_0.module b/core/modules/system/tests/modules/update_test_0/update_test_0.module new file mode 100644 index 000000000000..b3d9bbc7f371 --- /dev/null +++ b/core/modules/system/tests/modules/update_test_0/update_test_0.module @@ -0,0 +1 @@ +<?php diff --git a/core/modules/system/tests/modules/update_test_1/update_test_1.install b/core/modules/system/tests/modules/update_test_1/update_test_1.install index bfb7170d8118..7ef5d98adc98 100644 --- a/core/modules/system/tests/modules/update_test_1/update_test_1.install +++ b/core/modules/system/tests/modules/update_test_1/update_test_1.install @@ -15,32 +15,27 @@ function update_test_1_update_dependencies() { // These dependencies are used in combination with those declared in // update_test_2_update_dependencies() for the sole purpose of testing that // the results of hook_update_dependencies() are collected correctly and have - // the correct array structure. Therefore, we use updates from System module - // (which have already run), so that they will not get in the way of other - // tests. - $dependencies['system'][8000] = array( - // Compare to update_test_2_update_dependencies(), where the same System - // module update function is forced to depend on an update function from a - // different module. This allows us to test that both dependencies are - // correctly recorded. - 'update_test_1' => 8000, + // the correct array structure. Therefore, we use updates from the + // update_test_0 module (which will be installed first) that they will not + // get in the way of other tests. + $dependencies['update_test_0'][8001] = array( + // Compare to update_test_2_update_dependencies(), where the same + // update_test_0 module update function is forced to depend on an update + // function from a different module. This allows us to test that both + // dependencies are correctly recorded. + 'update_test_1' => 8001, ); - $dependencies['system'][8001] = array( - // Compare to update_test_2_update_dependencies(), where the same System - // module update function is forced to depend on a different update - // function within the same module. This allows us to test that only the - // dependency on the higher-numbered update function is recorded. - 'update_test_1' => 8002, + $dependencies['update_test_0'][8002] = array( + // Compare to update_test_2_update_dependencies(), where the same + // update_test_0 module update function is forced to depend on a + // different update function within the same module. This allows us to + // test that only the dependency on the higher-numbered update function + // is recorded. + 'update_test_1' => 8003, ); return $dependencies; } -/** - * Dummy update_test_1 update 8000. - */ -function update_test_1_update_8000() { -} - /** * Dummy update_test_1 update 8001. */ @@ -52,3 +47,9 @@ function update_test_1_update_8001() { */ function update_test_1_update_8002() { } + +/** + * Dummy update_test_1 update 8003. + */ +function update_test_1_update_8003() { +} diff --git a/core/modules/system/tests/modules/update_test_2/update_test_2.install b/core/modules/system/tests/modules/update_test_2/update_test_2.install index c73271a1fb00..42027204fda5 100644 --- a/core/modules/system/tests/modules/update_test_2/update_test_2.install +++ b/core/modules/system/tests/modules/update_test_2/update_test_2.install @@ -14,32 +14,26 @@ function update_test_2_update_dependencies() { // Combined with update_test_3_update_dependencies(), we are declaring here // that these two modules run updates in the following order: - // 1. update_test_2_update_8000() - // 2. update_test_3_update_8000() - // 3. update_test_2_update_8001() - // 4. update_test_2_update_8002() - $dependencies['update_test_2'][8001] = array( - 'update_test_3' => 8000, + // 1. update_test_2_update_8001() + // 2. update_test_3_update_8001() + // 3. update_test_2_update_8002() + // 4. update_test_2_update_8003() + $dependencies['update_test_2'][8002] = array( + 'update_test_3' => 8001, ); // These are coordinated with the corresponding dependencies declared in // update_test_1_update_dependencies(). - $dependencies['system'][8000] = array( - 'update_test_2' => 8001, + $dependencies['update_test_0'][8001] = array( + 'update_test_2' => 8002, ); - $dependencies['system'][8001] = array( - 'update_test_1' => 8001, + $dependencies['update_test_0'][8002] = array( + 'update_test_1' => 8002, ); return $dependencies; } -/** - * Dummy update_test_2 update 8000. - */ -function update_test_2_update_8000() { -} - /** * Dummy update_test_2 update 8001. */ @@ -51,3 +45,9 @@ function update_test_2_update_8001() { */ function update_test_2_update_8002() { } + +/** + * Dummy update_test_2 update 8003. + */ +function update_test_2_update_8003() { +} diff --git a/core/modules/system/tests/modules/update_test_3/update_test_3.install b/core/modules/system/tests/modules/update_test_3/update_test_3.install index 96830c816f9c..ae2da4b09a2e 100644 --- a/core/modules/system/tests/modules/update_test_3/update_test_3.install +++ b/core/modules/system/tests/modules/update_test_3/update_test_3.install @@ -11,14 +11,14 @@ * @see update_test_2_update_dependencies() */ function update_test_3_update_dependencies() { - $dependencies['update_test_3'][8000] = array( - 'update_test_2' => 8000, + $dependencies['update_test_3'][8001] = array( + 'update_test_2' => 8001, ); return $dependencies; } /** - * Dummy update_test_3 update 8000. + * Dummy update_test_3 update 8001. */ -function update_test_3_update_8000() { +function update_test_3_update_8001() { } diff --git a/core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.info.yml b/core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.info.yml new file mode 100644 index 000000000000..a41ace9e3a27 --- /dev/null +++ b/core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.info.yml @@ -0,0 +1,7 @@ +name: 'Update test with an invalid hook_update_8000().' +type: module +description: 'Support module for update testing.' +package: Testing +version: VERSION +core: 8.x +hidden: true diff --git a/core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.install b/core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.install new file mode 100644 index 000000000000..0a33af74da55 --- /dev/null +++ b/core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.install @@ -0,0 +1,12 @@ +<?php + +/** + * @file + * Install, update and uninstall functions for the update_test_invalid_hook module. + */ + +/** + * Hook implementation using the reserved schema version 8000. + */ +function update_test_invalid_hook_update_8000() { +} diff --git a/core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.module b/core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.module new file mode 100644 index 000000000000..b3d9bbc7f371 --- /dev/null +++ b/core/modules/system/tests/modules/update_test_invalid_hook/update_test_invalid_hook.module @@ -0,0 +1 @@ +<?php diff --git a/core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.info.yml b/core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.info.yml new file mode 100644 index 000000000000..3ac4a357d10e --- /dev/null +++ b/core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.info.yml @@ -0,0 +1,7 @@ +name: 'Update test with 7.x updates left in the codebase.' +type: module +description: 'Support module for update testing.' +package: Testing +version: VERSION +core: 8.x +hidden: true diff --git a/core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.install b/core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.install new file mode 100644 index 000000000000..fd5c65b0a1db --- /dev/null +++ b/core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.install @@ -0,0 +1,25 @@ +<?php + +/** + * @file + * Install, update and uninstall functions for the update_test_with_7x module. + */ + +/** + * Dummy update_test_with_7x update 7200. + */ +function update_test_with_7x_update_7200() { +} + +/** + * Dummy update_test_with_7x update 7201. + */ +function update_test_with_7x_update_7201() { +} + +/** + * Implements hook_update_last_removed(). + */ +function update_test_with_7x_update_last_removed() { + return 7110; +} diff --git a/core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.module b/core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.module new file mode 100644 index 000000000000..b3d9bbc7f371 --- /dev/null +++ b/core/modules/system/tests/modules/update_test_with_7x/update_test_with_7x.module @@ -0,0 +1 @@ +<?php diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 7b247c93e875..defe1655c0b9 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -163,265 +163,3 @@ function taxonomy_schema() { return $schema; } - -/** - * Implements hook_update_dependencies(). - */ -function taxonomy_update_dependencies() { - // Convert the 'tid' column of the taxonomy reference field to 'target_id' - // after the field tables have been reorganized. - $dependencies['taxonomy'][8007] = array( - 'field' => 8006, - ); - return $dependencies; -} - -/** - * Remove the {taxonomy_vocabulary}.module field. - */ -function taxonomy_update_8000() { - db_drop_field('taxonomy_vocabulary', 'module'); -} - -/** - * Adds langcode field to {taxonomy_term_data} and {taxonomy_vocabulary}. - * - * @see http://drupal.org/node/1454538 - */ -function taxonomy_update_8001() { - $descriptions = array( - 'taxonomy_term_data' => 'The {language}.langcode of this term.', - 'taxonomy_vocabulary' => 'The {language}.langcode of this vocabulary.', - ); - foreach ($descriptions as $table => $description) { - $langcode_field = array( - 'description' => $description, - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ); - - // If a Drupal 7 contrib module already added a langcode field to support - // internationalization, keep it, but standardize the specification. - // Otherwise, add the field. - if (db_field_exists($table, 'langcode')) { - // According to the documentation of db_change_field(), indices using the - // field should be dropped first; if the contrib module created any - // indices, it is its responsibility to drop them in an update function - // that runs before this one, which it can enforce via - // hook_update_dependencies(). - db_change_field($table, 'langcode', 'langcode', $langcode_field); - } - else { - // When updating from a site that did not already have taxonomy - // internationalization, initialize all existing vocabularies and terms as - // being in the site's default language. - $langcode_field['initial'] = language_default()->id; - db_add_field($table, 'langcode', $langcode_field); - } - } -} - -/** - * Create a UUID column for taxonomy terms. - */ -function taxonomy_update_8002() { - $spec = array( - 'description' => 'Unique Key: Universally unique identifier for this entity.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - ); - $keys = array( - 'unique keys' => array( - 'uuid' => array('uuid'), - ), - ); - // Account for sites having the contributed UUID module installed. - if (db_field_exists('taxonomy_term_data', 'uuid')) { - db_change_field('taxonomy_term_data', 'uuid', 'uuid', $spec, $keys); - } - else { - db_add_field('taxonomy_term_data', 'uuid', $spec, $keys); - } -} - -/** - * Generate a UUID for all terms. - */ -function taxonomy_update_8003(&$sandbox) { - if (!isset($sandbox['progress'])) { - $sandbox['progress'] = 0; - $sandbox['last'] = 0; - $sandbox['max'] = db_query('SELECT COUNT(tid) FROM {taxonomy_term_data} WHERE uuid IS NULL')->fetchField(); - } - - $tids = db_query_range('SELECT tid FROM {taxonomy_term_data} WHERE tid > :tid AND uuid IS NULL ORDER BY tid ASC', 0, 10, array(':tid' => $sandbox['last']))->fetchCol(); - update_add_uuids($sandbox, 'taxonomy_term_data', 'tid', $tids); - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); -} - -/** - * Moves taxonomy settings from variable to config. - */ -function taxonomy_update_8004() { - update_variables_to_config('taxonomy.settings', array( - 'taxonomy_override_selector' => 'override_selector', - 'taxonomy_terms_per_page_admin' => 'terms_per_page_admin', - 'taxonomy_maintain_index_table' => 'maintain_index_table', - )); -} - -/** - * Convert vocabularies into configuration. - */ -function taxonomy_update_8005() { - $uuid = \Drupal::service('uuid'); - - $result = db_query('SELECT * FROM {taxonomy_vocabulary}'); - foreach ($result as $vocabulary) { - $config = \Drupal::config('taxonomy.vocabulary.' . $vocabulary->machine_name) - ->set('vid', $vocabulary->machine_name) - ->set('name', $vocabulary->name) - ->set('uuid', !empty($vocabulary->uuid) ? $vocabulary->uuid : $uuid->generate()) - ->set('description', $vocabulary->description) - ->set('hierarchy', $vocabulary->hierarchy) - ->set('weight', $vocabulary->weight) - ->set('langcode', $vocabulary->langcode) - ->save(); - } -} - -/** - * Change {taxonomy_term_data}.vid into a string holding the vocabulary machine name. - */ -function taxonomy_update_8006() { - db_drop_index('taxonomy_term_data', 'taxonomy_tree'); - db_drop_index('taxonomy_term_data', 'vid_name'); - db_change_field('taxonomy_term_data', 'vid', 'vid', array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The ID of the vocabulary to which the term is assigned.', - )); - db_add_index('taxonomy_term_data', 'taxonomy_tree', array(array('vid', 64), 'weight', 'name')); - db_add_index('taxonomy_term_data', 'vid_name', array(array('vid', 64), 'name')); - - $map = db_query('SELECT vid, machine_name FROM {taxonomy_vocabulary}')->fetchAllKeyed(); - foreach ($map as $vid => $machine_name) { - db_update('taxonomy_term_data') - ->condition('vid', $vid) - ->fields(array('vid' => $machine_name)) - ->execute(); - } -} - -/** - * Update taxonomy_term_reference field tables to use target_id instead of tid. - */ -function taxonomy_update_8007() { - foreach (config_get_storage_names_with_prefix('field.field.') as $config_name) { - $field_config = \Drupal::config($config_name); - // Only update taxonomy reference fields that use the default SQL storage. - if ($field_config->get('type') == 'taxonomy_term_reference') { - $field = new Field($field_config->get()); - - if (db_table_exists(FieldableDatabaseStorageController::_fieldTableName($field))) { - $tables = array( - FieldableDatabaseStorageController::_fieldTableName($field), - FieldableDatabaseStorageController::_fieldRevisionTableName($field), - ); - - foreach ($tables as $table_name) { - db_change_field($table_name, $field->name . '_tid', $field->name . '_target_id', array( - 'description' => 'The ID of the target entity.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => FALSE, - )); - - // Change the index. - db_drop_index($table_name, $field->name . '_tid'); - db_add_index($table_name, $field->name . '_target_id', array($field->name . '_target_id')); - } - - // Update the indexes in field config as well. - $indexes = $field_config->get('indexes'); - unset($indexes['tid']); - $indexes['target_id'] = array('target_id'); - $field_config->set('indexes', $indexes); - $field_config->save(); - } - } - } -} - -/** - * Add a changed column for taxonomy terms. - */ -function taxonomy_update_8008() { - $spec = array( - 'description' => 'The Unix timestamp when the term was most recently saved.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'initial' => REQUEST_TIME, - ); - db_add_field('taxonomy_term_data', 'changed', $spec); -} - -/** - * Convert numeric IDs to UUIDs to ensure config deployability. - */ -function taxonomy_update_8009() { - foreach (config_get_storage_names_with_prefix('field.instance.') as $instance_config_name) { - $instance_config = \Drupal::config($instance_config_name); - if ($instance_config->get('field_type') == 'taxonomy_term_reference') { - $default_value = $instance_config->get('default_value'); - $ids = array(); - // Load all referenced taxonomy_terms in default_value. - foreach ($default_value as $delta => $value) { - $ids[] = $value['tid']; - } - if ($ids) { - $entities = db_select('taxonomy_term_data', 't') - ->fields('t', array('tid', 'uuid')) - ->condition('t.tid', $ids) - ->execute()->fetchAllAssoc('tid'); - - // Convert IDs to UUIDs and save the new default_value. - foreach ($default_value as $delta => &$value) { - $value = array( - 'target_uuid' => $entities[$value['tid']]->uuid, - 'revision_id' => '', - ); - } - $instance_config->set('default_value', $default_value)->save(); - } - } - } -} - -/** - * Rename the 'description' and 'format' columns for taxonomy terms. - */ -function taxonomy_update_8010() { - $description = array( - 'type' => 'text', - 'not null' => FALSE, - 'size' => 'big', - 'description' => 'A description of the term.', - ); - db_change_field('taxonomy_term_data', 'description', 'description__value', $description); - - $format = array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'description' => 'The filter format ID of the description.', - ); - db_change_field('taxonomy_term_data', 'format', 'description__format', $format); -} diff --git a/core/modules/text/text.install b/core/modules/text/text.install deleted file mode 100644 index 4dcf943a1a1a..000000000000 --- a/core/modules/text/text.install +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -/** - * @file - * Install, update, and uninstall functions for the Text module. - */ - -/** - * Moves teaser length from variable to config. - * - * @ingroup config_upgrade - */ -function text_update_8000() { - update_variables_to_config('text.settings', array( - 'teaser_length' => 'default_summary_length', - )); -} diff --git a/core/modules/toolbar/toolbar.install b/core/modules/toolbar/toolbar.install deleted file mode 100644 index 13e2d89b620b..000000000000 --- a/core/modules/toolbar/toolbar.install +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * @file - * Install, update and uninstall functions for the toolbar module. - */ - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Enable the Breakpoint and Config modules. - * - * The 7.x version of the Toolbar module had no dependencies. The 8.x version - * depends on the Breakpoint and Configuration manager modules. - */ -function toolbar_update_8000() { - // Enable the modules without re-installing the schema. - \Drupal::moduleHandler()->install(array('breakpoint')); -} - -/** - * @} End of "addtogroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/tracker/tracker.install b/core/modules/tracker/tracker.install index bc6499e99c06..5f3e5a0fd1f0 100644 --- a/core/modules/tracker/tracker.install +++ b/core/modules/tracker/tracker.install @@ -116,51 +116,3 @@ function tracker_schema() { return $schema; } - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * Moves tracker settings from variable to config. - */ -function tracker_update_8000() { - update_variables_to_config('tracker.settings', array( - 'tracker_batch_size' => 'cron_index_limit', - )); -} - -/** - * Make *id fields unsigned. - */ -function tracker_update_8001() { - db_drop_primary_key('tracker_user'); - db_drop_index('tracker_user', 'tracker'); - db_change_field('tracker_user', 'uid', 'uid', - array( - 'description' => 'The {users}.uid of the node author or commenter.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - array('primary key' => array('nid', 'uid'), 'indexes' => array( - 'tracker' => array('uid', 'published', 'changed'), - )) - ); -} - -/** - * Convert tracker_index_nid variable to state system. - * - * @ingroup state_upgrade - */ -function tracker_update_8002() { - update_variables_to_state(array('tracker_index_nid' => 'tracker.index_nid')); -} - -/** - * @} End of "defgroup updates-7.x-to-8.x". - * The next series of updates should start at 9000. - */ diff --git a/core/modules/update/update.install b/core/modules/update/update.install index 99ca307bce7a..568d17914a2b 100644 --- a/core/modules/update/update.install +++ b/core/modules/update/update.install @@ -137,38 +137,3 @@ function _update_requirement_check($project, $type) { $requirement['value'] = l($requirement_label, update_manager_access() ? 'admin/reports/updates/update' : 'admin/reports/updates'); return $requirement; } - -/** - * Moves update settings from variables to config. - */ -function update_update_8000() { - update_variables_to_config('update.settings', array( - 'update_check_disabled' => 'check.disabled_extensions', - 'update_check_frequency' => 'check.interval_days', - 'update_fetch_url' => 'fetch.url', - 'update_max_fetch_attempts' => 'fetch.max_attempts', - 'update_max_fetch_time' => 'fetch.timeout', - 'update_notify_emails' => 'notification.emails', - 'update_notification_threshold' => 'notification.threshold', - )); -} - -/** - * Convert update_last_check, last_email_notification variables to state API. - * - * @ingroup config_upgrade - */ -function update_update_8001() { - $variable_map = array( - 'update_last_check' => 'update.last_check', - 'update_last_email_notification' => 'update.last_email_notification' - ); - update_variables_to_state($variable_map); -} - -/** - * Deletes the {cache_update} table. - */ -function update_update_8002() { - db_drop_table('cache_update'); -} diff --git a/core/modules/user/user.install b/core/modules/user/user.install index a2aebfa46e72..c21e2959b13e 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -245,809 +245,3 @@ function user_install() { )) ->execute(); } - -/** - * Implements hook_update_dependencies(). - */ -function user_update_dependencies() { - // Convert user picture to field after the fields and instances are converted - // to ConfigEntities and the tables are split. - $dependencies['user'][8011] = array( - 'field' => 8006, - ); - return $dependencies; -} - - -/** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** - * The 'Member for' extra field has moved one level up in the array. - */ -function user_update_8000() { - $settings = update_variable_get('field_bundle_settings_user__user', array()); - if (isset($settings['extra_fields']['display']['summary'])) { - $settings['extra_fields']['display']['member_for'] = $settings['extra_fields']['display']['summary']; - unset($settings['extra_fields']['display']['summary']); - update_variable_set('field_bundle_settings_user__user', $settings); - } -} - -/** - * Splits {users}.language field to langcode and preferred_langcode. - * - * @see http://drupal.org/node/1454538 - */ -function user_update_8001() { - // The former language field is the language preference of the user. Rename - // this to preferred_langcode in order to distinguish it from the langcode - // field common to all entity types, used for identifying the language of the - // entity itself. - $preferred_langcode_field = array( - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The {language}.langcode that the user prefers for receiving emails and viewing the site.', - ); - db_change_field('users', 'language', 'preferred_langcode', $preferred_langcode_field); - - // Add the langcode field. - $langcode_field = array( - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'description' => "The {language}.langcode of the user's profile.", - ); - db_add_field('users', 'langcode', $langcode_field); - - // Since distinguishing the language of the user entity from the user's - // preferred language is a new feature in Drupal 8, assume that for updated - // sites, existing user entities are in the user's preferred language. - db_update('users')->expression('langcode', 'preferred_langcode')->execute(); -} - -/** - * Replace serial role IDs with machine name strings. - */ -function user_update_8002() { - // Change serial rid columns into strings. - $column = array( - 'type' => 'varchar', - 'length' => 64, - 'not null' => TRUE, - 'description' => 'Primary Key: Unique role ID.', - ); - db_change_field('role', 'rid', 'rid', $column); - - $column['description'] = 'Primary Key: {role}.rid for role.'; - db_change_field('users_roles', 'rid', 'rid', $column); - - // Enlarge the role name (label) column. - $column = array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Role label.', - ); - db_change_field('role', 'name', 'name', $column); - // Remove unique index. - db_drop_unique_key('role', 'name'); - - // Rename the built-in serial role IDs into the hardcoded machine names. - foreach (array(1, 2) as $rid) { - db_update('role') - ->fields(array('rid' => _user_update_map_rid($rid))) - ->condition('rid', $rid) - ->execute(); - db_update('users_roles') - ->fields(array('rid' => _user_update_map_rid($rid))) - ->condition('rid', $rid) - ->execute(); - } -} - -/** - * Create a UUID column for users. - */ -function user_update_8003() { - $spec = array( - 'description' => 'Unique Key: Universally unique identifier for this entity.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - ); - $keys = array( - 'unique keys' => array( - 'uuid' => array('uuid'), - ), - ); - // Account for sites having the contributed UUID module installed. - if (db_field_exists('users', 'uuid')) { - db_change_field('users', 'uuid', 'uuid', $spec, $keys); - } - else { - db_add_field('users', 'uuid', $spec, $keys); - } -} - -/** - * Moves account settings from variable to config. - * - * @ingroup config_upgrade - */ -function user_update_8004() { - update_variables_to_config('user.settings', array( - 'anonymous' => 'anonymous', - 'user_admin_role' => 'admin_role', - 'user_register' => 'register', - 'user_signatures' => 'signatures', - 'user_cancel_method' => 'cancel_method', - 'user_mail_status_activated_notify' => 'notify.status_activated', - 'user_mail_status_blocked_notify' => 'notify.status_blocked', - 'user_mail_status_cancelled_notify' => 'notify.status_cancelled', - 'user_email_verification' => 'verify_mail', - 'user_password_reset_timeout' => 'password_reset_timeout', - )); - - // Convert the user.settings:register numeric value to text value. - $map = array( - '0' => 'admin_only', - '1' => 'visitors', - '2' => 'visitors_admin_approval', - ); - - $config = \Drupal::config('user.settings'); - $user_register = $config->get('register'); - $user_cancel_method = $config->get('cancel_method'); - - if (is_numeric($user_register) && isset($map[$user_register])) { - $config->set('register', $map[$user_register])->save(); - } - - // Convert user.settings:cancel_method numeric value to text value. - $cancel_map = array( - '0' => 'user_cancel_block', - '1' => 'user_cancel_block_unpublish', - '2' => 'user_cancel_block_reassign', - '3' => 'user_cancel_block_delete', - ); - - if (is_numeric($user_cancel_method) && isset($cancel_map[$user_cancel_method])) { - $config->set('cancel_method', $$cancel_map[$user_cancel_method])->save(); - } -} - -/** - * Creates a preferred_admin_langcode column. - */ -function user_update_8005() { - $spec = array( - 'description' => 'The {language}.langcode that the user prefers for viewing administration pages.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ); - db_add_field('users', 'preferred_admin_langcode', $spec); -} - -/** - * Moves user mail settings from variable to config. - * - * @ingroup config_upgrade - */ -function user_update_8006() { - update_variables_to_config('user.mail', array( - 'register_admin_created_subject' => 'register_admin_created.subject', - 'register_admin_created_body' => 'register_admin_created.body', - 'register_pending_approval_subject' => 'register_pending_approval.subject', - 'register_pending_approval_body' => 'register_pending_approval.body', - 'register_pending_approval_admin_body' => 'register_pending_approval_admin.body', - 'register_pending_approval_admin_subject' => 'register_pending_approval_admin.subject', - 'register_no_approval_required_subject' => 'register_no_approval_required.subject', - 'register_no_approval_required_body' => 'register_no_approval_required.body', - 'password_reset_subject' => 'password_reset.subject', - 'password_reset_body' => 'password_reset.body', - 'status_activated_subject' => 'status_activated.subject', - 'status_activated_body' => 'status_activated.body', - 'status_blocked_subject' => 'status_blocked.subject', - 'status_blocked_body' => 'status_blocked.body', - 'cancel_confirm_subject' => 'cancel_confirm.subject', - 'cancel_confirm_body' => 'cancel_confirm.body', - 'status_canceled_subject' => 'status_canceled.subject', - 'status_canceled_body' => 'status_canceled.body', - )); -} - -/** - * Moves login flood settings from variable to config. - * - * @ingroup config_upgrade - */ -function user_update_8007() { - update_variables_to_config('user.flood', array( - 'user_failed_login_identifier_uid_only' => 'uid_only', - 'user_failed_login_ip_limit' => 'ip_limit', - 'user_failed_login_ip_window' => 'ip_window', - 'user_failed_login_user_limit' => 'user_limit', - 'user_failed_login_user_window' => 'user_window', - )); -} - -/** - * Make *id fields unsigned. - */ -function user_update_8008() { - db_change_field('authmap', 'uid', 'uid', - array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => "User's {users}.uid.", - ) - ); -} - -/** - * Generate a UUID for all users. - */ -function user_update_8009(&$sandbox) { - if (!isset($sandbox['progress'])) { - $sandbox['progress'] = 0; - // The first user id is 0, so it needs to start with -1. - $sandbox['last'] = -1; - $sandbox['max'] = db_query('SELECT COUNT(uid) FROM {users} WHERE uuid IS NULL')->fetchField(); - } - - $uids = db_query_range('SELECT uid FROM {users} WHERE uid > :uid AND uuid IS NULL ORDER BY uid ASC', 0, 10, array(':uid' => $sandbox['last']))->fetchCol(); - update_add_uuids($sandbox, 'users', 'uid', $uids); - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); -} - -/** - * Create user picture field. - */ -function user_update_8011() { - global $user; - - // User pictures can only be migrated to the new user picture image field - // if Image module is installed. - if (!\Drupal::moduleHandler()->moduleExists('image')) { - $old_schema = \Drupal::moduleHandler()->install(array('image')); - if ($old_schema['image'] == SCHEMA_UNINSTALLED) { - // Install image.module with schema version 8003 as a previous version - // would have to create tables that would be removed again. - update_set_schema('image', 8003); - // Inlined version of image_install(), make sure that the styles - // directory exists. - $directory = update_variable_get('file_default_scheme', 'public') . '://styles'; - file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); - } - } - - if ($default_image = update_variable_get('user_picture_default', '')) { - $picture_directory = update_variable_get('file_default_scheme', 'public') . '://' . update_variable_get('user_picture_path', 'pictures'); - file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY); - $destination = file_stream_wrapper_uri_normalize($picture_directory . '/' . drupal_basename($default_image)); - // The file entity needs to be created manually as entities can not be - // created/saved during the upgrade path. Attempt to replicate the behavior - // of file_save_data() by updating an eventually existing record for that - // file. - file_unmanaged_save_data($default_image, $destination, FILE_EXISTS_REPLACE); - $uuid = \Drupal::service('uuid'); - db_merge('file_managed') - ->key(array( - 'uri' => $destination, - )) - ->fields(array( - 'uid' => $user->id(), - 'status' => FILE_STATUS_PERMANENT, - 'filename' => drupal_basename($destination), - 'uuid' => $uuid->generate(), - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'filesize' => filesize($destination), - 'filemime' => file_get_mimetype($destination), - 'created' => REQUEST_TIME, - 'changed' => REQUEST_TIME, - )) - ->execute(); - $default_image_fid = db_query('SELECT fid FROM {file_managed} WHERE uri = :uri', array(':uri' => $destination))->fetchField(); - } - - // Create the field and instance. - $field = array( - 'name' => 'user_picture', - 'entity_type' => 'user', - 'module' => 'image', - 'type' => 'image', - 'cardinality' => 1, - 'locked' => FALSE, - 'indexes' => array('target_id' => array('target_id')), - 'settings' => array( - 'uri_scheme' => 'public', - 'default_image' => FALSE, - ), - 'schema' => array( - 'columns' => array( - 'target_id' => array( - 'description' => 'The ID of the target entity.', - 'type' => 'int', - 'not null' => TRUE, - 'unsigned' => TRUE, - ), - 'alt' => array( - 'description' => "Alternative image text, for the image's 'alt' attribute.", - 'type' => 'varchar', - 'length' => 512, - 'not null' => FALSE, - ), - 'title' => array( - 'description' => "Image title text, for the image's 'title' attribute.", - 'type' => 'varchar', - 'length' => 1024, - 'not null' => FALSE, - ), - 'width' => array( - 'description' => 'The width of the image in pixels.', - 'type' => 'int', - 'unsigned' => TRUE, - ), - 'height' => array( - 'description' => 'The height of the image in pixels.', - 'type' => 'int', - 'unsigned' => TRUE, - ), - ), - 'indexes' => array( - 'target_id' => array('target_id'), - ), - 'foreign keys' => array( - 'target_id' => array( - 'table' => 'file_managed', - 'columns' => array('target_id' => 'fid'), - ), - ), - ), - ); - _update_8003_field_create_field($field); - - $instance = array( - 'entity_type' => 'user', - 'bundle' => 'user', - 'label' => 'Picture', - 'description' => update_variable_get('user_picture_guidelines', ''), - 'required' => FALSE, - 'settings' => array( - 'file_extensions' => 'png gif jpg jpeg', - 'file_directory' => update_variable_get('user_picture_path', 'pictures'), - 'max_filesize' => update_variable_get('user_picture_file_size', '30') . ' KB', - 'alt_field' => 0, - 'title_field' => 0, - 'max_resolution' => update_variable_get('user_picture_dimensions', '85x85'), - 'min_resolution' => '', - 'default_image' => !empty($default_image_fid) ? $default_image_fid : 0, - ), - ); - _update_8003_field_create_instance($field, $instance); - - module_load_install('entity'); - if (update_variable_get('user_pictures', 0)) { - $formatter = 'image'; - $widget = 'image_image'; - } - else { - $formatter = $widget = 'hidden'; - } - - // Assign form settings for the 'default' form mode. - $form_display = _update_8000_entity_get_form_display('user', 'user', 'default', TRUE); - $form_display->set('content.user_picture', array( - 'type' => $widget, - 'settings' => array( - 'progress_indicator' => 'throbber', - 'preview_image_style' => 'thumbnail', - ), - 'weight' => -1, - )) - ->set('status', 1) - ->save(); - - // Assign display settings for the 'default' and 'compact' view modes. - $display = _update_8000_entity_get_display('user', 'user', 'default'); - $display->set('content.user_picture', array( - 'label' => 'hidden', - 'type' => $formatter, - 'settings' => array( - 'image_style' => 'thumbnail', - 'image_link' => 'content', - ), - 'weight' => 0, - )) - ->set('status', 1) - ->save(); - - $display = _update_8000_entity_get_display('user', 'user', 'compact'); - $display->set('content.user_picture', array( - 'label' => 'hidden', - 'type' => $formatter, - 'settings' => array( - 'image_style' => update_variable_get('user_picture_style', ''), - 'image_link' => 'content', - ), - 'weight' => 0, - )) - ->set('status', 1) - ->set('hidden.member_for', TRUE); - $display->save(); - - // Add file usage for the default field. - if (!empty($default_image_fid)) { - db_insert('file_usage') - ->fields(array( - 'fid' => $default_image_fid, - 'module' => 'image', - 'type' => 'default_image', - 'id' => $field['uuid'], - 'count' => 1, - )) - ->execute(); - } - - // Delete old variables. - update_variable_del('user_pictures'); - update_variable_del('user_picture_path'); - update_variable_del('user_picture_default'); - update_variable_del('user_picture_style'); - update_variable_del('user_picture_dimensions'); - update_variable_del('user_picture_file_size'); - update_variable_del('user_picture_guidelines'); -} - -/** - * Migrate {users}.picture to 'user_picture' image field. - */ -function user_update_8012(&$sandbox) { - // Initialize total values to process. - if (!isset($sandbox['total'])) { - $sandbox['total'] = (int) db_query('SELECT COUNT(picture) FROM {users} WHERE picture > 0')->fetchField(); - $sandbox['processed'] = 0; - } - - if ($sandbox['total']) { - // Retrieve next 20 rows to migrate. - $rows = db_query_range('SELECT uid, picture FROM {users} WHERE picture > 0', 0, 20)->fetchAllKeyed(); - foreach ($rows as $uid => $fid) { - // Add a row to the field data and revision tables. - db_insert('user__user_picture') - ->fields(array( - 'bundle' => 'user', - 'entity_id' => $uid, - 'revision_id' => $uid, - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'delta' => 0, - 'user_picture_target_id' => $fid, - )) - ->execute(); - db_insert('user_revision__user_picture') - ->fields(array( - 'bundle' => 'user', - 'entity_id' => $uid, - 'revision_id' => $uid, - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'delta' => 0, - 'user_picture_target_id' => $fid, - )) - ->execute(); - - // Update file usage from user to file module. - // @see file_field_insert() - // Old: file_usage_add($picture, 'user', 'user', $entity->id(); - // New: file_usage_add(file_load($item['fid']), 'file', $entity_type, $id); - db_update('file_usage') - ->condition('fid', $fid) - ->condition('module', 'user') - ->condition('type', 'user') - ->condition('id', $uid) - ->fields(array( - 'module' => 'file', - )) - ->execute(); - } - - // Set picture column of the migrated users to 0. - db_update('users') - ->fields(array( - 'picture' => 0, - )) - ->condition('uid', array_keys($rows)) - ->execute(); - - // Report status. - $sandbox['processed'] += count($rows); - } - $sandbox['#finished'] = $sandbox['total'] ? $sandbox['processed'] / $sandbox['total'] : 1; - -} - -/** - * Deletes {users}.picture field. - */ -function user_update_8013() { - db_drop_field('users', 'picture'); -} - -/** - * Create new {users_data} table. - */ -function user_update_8014() { - // Create the {users_data} table. - db_create_table('users_data', array( - 'description' => 'Stores module data as key/value pairs per user.', - 'fields' => array( - 'uid' => array( - 'description' => 'Primary key: {users}.uid for user.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - 'module' => array( - 'description' => 'The name of the module declaring the variable.', - 'type' => 'varchar', - 'length' => 204, - 'not null' => TRUE, - 'default' => '', - ), - 'name' => array( - 'description' => 'The identifier of the data.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - ), - 'value' => array( - 'description' => 'The value.', - 'type' => 'blob', - 'not null' => FALSE, - 'size' => 'big', - ), - 'serialized' => array( - 'description' => 'Whether value is serialized.', - 'type' => 'int', - 'size' => 'tiny', - 'unsigned' => TRUE, - 'default' => 0, - ), - ), - 'primary key' => array('uid', 'module', 'name'), - 'indexes' => array( - 'module' => array('module'), - 'name' => array('name'), - ), - 'foreign keys' => array( - 'uid' => array('users' => 'uid'), - ), - )); - - // Create backup table for data migration. - // Since the origin/owner of individual values in {users}.data is unknown, - // other modules need to migrate their existing values from {_d7_users_data}. - db_create_table('_d7_users_data', array( - 'description' => 'Backup of {users}.data for migration.', - 'fields' => array( - 'uid' => array( - 'description' => 'Primary Key: {users}.uid for user.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - 'name' => array( - 'description' => 'The name of the variable.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - ), - 'value' => array( - 'description' => 'The serialized value of the variable.', - 'type' => 'blob', - 'not null' => FALSE, - 'size' => 'big', - 'serialize' => TRUE, - ), - ), - 'primary key' => array('uid', 'name'), - 'foreign keys' => array( - 'uid' => array('users' => 'uid'), - ), - )); -} - -/** - * Move existing {users}.data into {_d7_users_data} migration table. - */ -function user_update_8015(&$sandbox) { - if (!isset($sandbox['progress'])) { - $sandbox['progress'] = 0; - // The anonymous user cannot have data, so start with uid 1. - $sandbox['last'] = 0; - $sandbox['max'] = db_query('SELECT COUNT(uid) FROM {users} WHERE uid > 0')->fetchField(); - } - - // Process 20 user records at a time. E.g., if there are 10 data keys per user - // record, that leads to an insert query with 200 values. - $result = db_query_range('SELECT uid, data FROM {users} WHERE uid > :uid ORDER BY uid ASC', 0, 20, array(':uid' => $sandbox['last']))->fetchAllKeyed(); - $query = db_insert('_d7_users_data')->fields(array('uid', 'name', 'value')); - $has_values = FALSE; - foreach ($result as $uid => $data) { - $sandbox['progress']++; - $sandbox['last'] = $uid; - if (empty($data)) { - continue; - } - $data = unserialize($data); - if (!empty($data) && is_array($data)) { - $has_values = TRUE; - foreach ($data as $name => $value) { - $query->values(array( - 'uid' => $uid, - 'name' => $name, - 'value' => serialize($value), - )); - } - } - } - if ($has_values) { - $query->execute(); - } - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); -} - -/** - * Drop {users}.data column. - */ -function user_update_8016() { - db_drop_field('users', 'data'); -} - -/** - * Grant "administer account settings" to roles with "administer users." - */ -function user_update_8017() { - $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer users'))->fetchCol(); - // None found. - if (empty($rids)) { - return; - } - $insert = db_insert('role_permission')->fields(array('rid', 'permission', 'module')); - foreach ($rids as $rid) { - $insert->values(array( - 'rid' => $rid, - 'permission' => 'administer account settings', - 'module' => 'user' - )); - } - $insert->execute(); -} - -/** - * Migrate user roles into configuration. - * - * @ingroup config_upgrade - */ -function user_update_8018() { - $uuid = \Drupal::service('uuid'); - - $roles = db_select('role', 'r') - ->fields('r') - ->execute() - ->fetchAll(); - - foreach ($roles as $role) { - \Drupal::config('user.role.' . $role->rid) - ->set('id', $role->rid) - ->set('uuid', $uuid->generate()) - ->set('label', $role->name) - ->set('weight', $role->weight) - ->set('langcode', Language::LANGCODE_NOT_SPECIFIED) - ->save(); - } -} - -/** - * Use the maximum allowed module name length in module name database fields. - */ -function user_update_8019() { - if (db_field_exists('role_permission', 'module')) { - $spec = array( - 'type' => 'varchar', - 'length' => 50, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The module declaring the permission.', - ); - db_change_field('role_permission', 'module', 'module', $spec); - } - - if (db_field_exists('users_data', 'module')) { - $spec = array( - 'description' => 'The name of the module declaring the variable.', - 'type' => 'varchar', - 'length' => 50, - 'not null' => TRUE, - 'default' => '', - ); - db_change_field('users_data', 'module', 'module', $spec); - } - -} - -/** - * Maps a role id to the new string. - * - * @param int $rid - * A D7 numeric role ID. - * - * @return string - * A D8 string role ID. - */ -function _user_update_map_rid($rid) { - $rid_map = array( - 1 => DRUPAL_ANONYMOUS_RID, - 2 => DRUPAL_AUTHENTICATED_RID, - ); - return isset($rid_map[$rid]) ? $rid_map[$rid] : $rid; -} - -/** - * Migrate roles permissions into configuration. - * - * @ingroup config_upgrade - */ -function user_update_8020() { - $db_permissions = db_select('role_permission', 'p') - ->fields('p') - ->execute() - ->fetchAll(); - $new_permissions = array(); - foreach ($db_permissions as $permission) { - $rid = _user_update_map_rid($permission->rid); - if (!isset($new_permissions[$rid]) || !in_array($permission->permission, $new_permissions[$rid])) { - $new_permissions[$rid][] = $permission->permission; - } - } - foreach ($new_permissions as $rid => $permissions) { - \Drupal::config("user.role.$rid") - ->set('permissions', $permissions) - ->save(); - } -} - -/** - * Create the 'register' form mode. - */ -function user_update_8021() { - $uuid = \Drupal::service('uuid'); - - \Drupal::config("entity.form_mode.user.register") - ->set('id', "user.register") - ->set('uuid', $uuid->generate()) - ->set('label', 'Register') - ->set('targetEntityType', 'user') - ->set('status', '1') - ->save(); -} - -/** - * @} End of "addtogroup updates-7.x-to-8.x". - */ diff --git a/core/update.php b/core/update.php index db6b9d2aabcb..6491afc0414c 100644 --- a/core/update.php +++ b/core/update.php @@ -14,6 +14,7 @@ * back to its original state! */ +use Drupal\Component\Utility\Settings; use Drupal\Core\DrupalKernel; use Drupal\Core\Update\Form\UpdateScriptSelectionForm; use Symfony\Component\HttpFoundation\Request; @@ -285,53 +286,6 @@ function update_task_list($active = NULL) { drupal_add_region_content('sidebar_first', drupal_render($task_list)); } -/** - * Returns and stores extra requirements that apply during the update process. - */ -function update_extra_requirements($requirements = NULL) { - static $extra_requirements = array(); - if (isset($requirements)) { - $extra_requirements += $requirements; - } - return $extra_requirements; -} - -/** - * Checks update requirements and reports errors and (optionally) warnings. - * - * @param $skip_warnings - * (optional) If set to TRUE, requirement warnings will be ignored, and a - * report will only be issued if there are requirement errors. Defaults to - * FALSE. - */ -function update_check_requirements($skip_warnings = FALSE) { - // Check requirements of all loaded modules. - $requirements = \Drupal::moduleHandler()->invokeAll('requirements', array('update')); - $requirements += update_extra_requirements(); - $severity = drupal_requirements_severity($requirements); - - // If there are errors, always display them. If there are only warnings, skip - // them if the caller has indicated they should be skipped. - if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && !$skip_warnings)) { - update_task_list('requirements'); - drupal_set_title('Requirements problem'); - $status = array( - '#theme' => 'status_report', - '#requirements' => $requirements, - ); - $status_report = drupal_render($status); - $status_report .= 'Check the messages and <a href="' . check_url(drupal_requirements_url($severity)) . '">try again</a>.'; - drupal_add_http_header('Content-Type', 'text/html; charset=utf-8'); - $maintenance_page = array( - '#theme' => 'maintenance_page', - '#content' => $status_report, - ); - print drupal_render($maintenance_page); - exit(); - } -} - - // Some unavoidable errors happen because the database is not yet up-to-date. // Our custom error handler is not yet installed, so we just suppress them. ini_set('display_errors', FALSE); @@ -343,12 +297,43 @@ function update_check_requirements($skip_warnings = FALSE) { require_once __DIR__ . '/includes/common.inc'; require_once __DIR__ . '/includes/file.inc'; require_once __DIR__ . '/includes/unicode.inc'; +require_once __DIR__ . '/includes/install.inc'; require_once __DIR__ . '/includes/schema.inc'; -update_prepare_d8_bootstrap(); +// Bootstrap to configuration. +drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); + +// Bootstrap the database. +require_once __DIR__ . '/includes/database.inc'; + +// Updating from a site schema version prior to 8000 should block the update +// process. Ensure that the site is not attempting to update a database +// created in a previous version of Drupal. +if (db_table_exists('system')) { + $system_schema = db_query('SELECT schema_version FROM {system} WHERE name = :system', array(':system' => 'system'))->fetchField(); + if ($system_schema < \Drupal::CORE_MINIMUM_SCHEMA_VERSION) { + print 'Your system schema version is ' . $system_schema . '. Updating directly from a schema version prior to 8000 is not supported. You must <a href="https://drupal.org/node/2179269">migrate your site to Drupal 8</a> first.'; + exit; + } +} + +// Enable UpdateServiceProvider service overrides. +// @see update_flush_all_caches() +$GLOBALS['conf']['container_service_providers']['UpdateServiceProvider'] = 'Drupal\Core\DependencyInjection\UpdateServiceProvider'; +$GLOBALS['conf']['update_service_provider_overrides'] = TRUE; + +// module.inc is not yet loaded but there are calls to module_config_sort() +// below. +require_once __DIR__ . '/includes/module.inc'; + +$settings = settings()->getAll(); +new Settings($settings); +$kernel = new DrupalKernel('update', drupal_classloader(), FALSE); +$kernel->boot(); +$request = Request::createFromGlobals(); +\Drupal::getContainer()->set('request', $request); // Determine if the current user has access to run update.php. drupal_bootstrap(DRUPAL_BOOTSTRAP_PAGE_CACHE); -$request = \Drupal::request(); require_once DRUPAL_ROOT . '/' . settings()->get('session_inc', 'core/includes/session.inc'); drupal_session_initialize(); @@ -382,16 +367,14 @@ function update_check_requirements($skip_warnings = FALSE) { // Check the update requirements for Drupal. Only report on errors at this // stage, since the real requirements check happens further down. + // The request will exit() if any requirement violations are reported in the + // following function invocation. update_check_requirements(TRUE); // Redirect to the update information page if all requirements were met. install_goto('core/update.php?op=info'); } -// Allow update_fix_d8_requirements() to run before code that can break on a -// Drupal 7 database. -drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE); -update_fix_d8_requirements(); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_maintenance_theme(); -- GitLab