diff --git a/core/includes/schema.inc b/core/includes/schema.inc index 87cbfa4085..8863a24b48 100644 --- a/core/includes/schema.inc +++ b/core/includes/schema.inc @@ -5,7 +5,7 @@ * Schema API handling functions. */ -use Drupal\Core\Utility\SchemaTypecaster; +use Drupal\Component\Utility\SchemaTypecaster; use Drupal\Core\Schema\SchemaDataInterface; /** @@ -16,7 +16,7 @@ /** * Indicates that a module has not been installed yet. * - * @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. * Use \Drupal\Core\Schema\SchemaDataInterface::UNINSTALLED instead. * * @see https://www.drupal.org/node/2444417 @@ -33,13 +33,13 @@ * If the module has updates, an array of available updates sorted by * version. Otherwise, FALSE. * - * @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. * Use \Drupal\Core\Schema\SchemaDataInterface::getVersions() instead. * * @see https://www.drupal.org/node/2444417 */ function drupal_get_schema_versions($module) { - @trigger_error('drupal_get_schema_versions() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Schema\SchemaDataInterface::getVersions() instead. See https://www.drupal.org/node/2444417.', E_USER_DEPRECATED); + @trigger_error('drupal_get_schema_versions() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Schema\SchemaDataInterface::getVersions() instead. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED); $versions = \Drupal::service('schema.data')->getVersions($module); // Service returns an empty array instead of FALSE as before. return $versions ?: FALSE; @@ -57,8 +57,9 @@ function drupal_get_schema_versions($module) { * system. * * @return string|int - * The currently installed schema version, or SCHEMA_UNINSTALLED if the - * module is not installed. + * The currently installed schema version, or + * \Drupal\Core\Schema\SchemaDataInterface::UNINSTALLED if the module is not + * installed. */ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = FALSE) { $versions = &drupal_static(__FUNCTION__, []); @@ -77,7 +78,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F return $versions; } else { - return isset($versions[$module]) ? $versions[$module] : SCHEMA_UNINSTALLED; + return isset($versions[$module]) ? $versions[$module] : SchemaDataInterface::UNINSTALLED; } } @@ -203,13 +204,13 @@ function _drupal_schema_initialize(&$schema, $module, $remove_descriptions = TRU * @return mixed * The converted value. * - * @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. - * Drupal\Core\Utility\SchemaTypecaster::castValue() instead. + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. + * Use \Drupal\Component\Utility\SchemaTypecaster::castValue() instead. * * @eee https://www.drupal.org/node/2444417 */ function drupal_schema_get_field_value(array $info, $value) { - @trigger_error('drupal_schema_get_field_value() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Schema\SchemaData::getFieldValue($info, $value) instead. See https://www.drupal.org/node/2444417.', E_USER_DEPRECATED); + @trigger_error('drupal_schema_get_field_value() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Component\Utility\SchemaTypecaster::castValue($info, $value) instead. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED); return SchemaTypecaster::castValue($info, $value); } diff --git a/core/includes/update.inc b/core/includes/update.inc index 85ca44385d..e7258b57a9 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -9,6 +9,7 @@ */ use Drupal\Component\Graph\Graph; +use Drupal\Core\Schema\SchemaDataInterface; use Drupal\Core\Update\UpdateKernel; use Drupal\Core\Utility\Error; @@ -307,9 +308,10 @@ function update_get_update_list() { $ret = ['system' => []]; $modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE); + $schema_data = \Drupal::service('schema.data'); foreach ($modules as $module => $schema_version) { // Skip uninstalled and incompatible modules. - if ($schema_version == SCHEMA_UNINSTALLED || update_check_incompatibility($module)) { + if ($schema_version == SchemaDataInterface::UNINSTALLED || update_check_incompatibility($module)) { continue; } // Display a requirements error if the user somehow has a schema version @@ -319,7 +321,7 @@ function update_get_update_list() { continue; } // Otherwise, get the list of updates defined by this module. - $updates = \Drupal::service('schema.data')->getVersions($module); + $updates = $schema_data->getVersions($module); if ($updates) { // \Drupal::moduleHandler()->invoke() returns NULL for non-existing hooks, // so if no updates are removed, it will == 0. @@ -454,9 +456,10 @@ function update_get_update_function_list($starting_updates) { // Go through each module and find all updates that we need (including the // first update that was requested and any updates that run after it). $update_functions = []; + $schema_data = \Drupal::service('schema.data'); foreach ($starting_updates as $module => $version) { $update_functions[$module] = []; - $updates = \Drupal::service('schema.data')->getVersions($module); + $updates = $schema_data->getVersions($module); if ($updates) { $max_version = max($updates); if ($version <= $max_version) { @@ -609,7 +612,7 @@ function update_retrieve_dependencies() { // Get a list of installed modules, arranged so that we invoke their hooks in // the same order that \Drupal::moduleHandler()->invokeAll() does. foreach (\Drupal::keyValue('system.schema')->getAll() as $module => $schema) { - if ($schema == SCHEMA_UNINSTALLED) { + if ($schema == SchemaDataInterface::UNINSTALLED) { // Nothing to upgrade. continue; } diff --git a/core/lib/Drupal/Component/Utility/SchemaTypecaster.php b/core/lib/Drupal/Component/Utility/SchemaTypecaster.php index d0518a2ee2..c570ab99a8 100644 --- a/core/lib/Drupal/Component/Utility/SchemaTypecaster.php +++ b/core/lib/Drupal/Component/Utility/SchemaTypecaster.php @@ -24,7 +24,7 @@ class SchemaTypecaster { * @return mixed * The converted value. * - * @see Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema + * @see \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema */ public static function castValue(array $info, $value) { // Preserve legal NULL values. diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index c8f492bd4f..798d752952 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -4,6 +4,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Schema\SchemaDataInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -173,7 +174,7 @@ protected function doList() { foreach ($extensions as $name => $module) { $module->weight = isset($installed_modules[$name]) ? $installed_modules[$name] : 0; $module->status = (int) isset($installed_modules[$name]); - $module->schema_version = SCHEMA_UNINSTALLED; + $module->schema_version = SchemaDataInterface::UNINSTALLED; } $extensions = $this->moduleHandler->buildModuleDependencies($extensions); diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 86dd86eeda..3545aa9163 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -77,13 +77,11 @@ public function __construct($root, ModuleHandlerInterface $module_handler, Drupa $this->root = $root; $this->moduleHandler = $module_handler; $this->kernel = $kernel; - if ($schema) { - $this->schema = $schema; - } - else { + if (!$schema) { @trigger_error('\Drupal\Core\Schema\SchemaDataInterface became an optional dependency of this class in Drupal 8.7.0 and will be required before Drupal 9.0.0. See https://www.drupal.org/project/drupal/issues/2124069.', E_USER_DEPRECATED); - $this->schema = \Drupal::service('schema.data'); + $schema = \Drupal::service('schema.data'); } + $this->schema = $schema; } /** diff --git a/core/modules/system/src/Form/ModulesUninstallForm.php b/core/modules/system/src/Form/ModulesUninstallForm.php index 841a741e44..2e924fc415 100644 --- a/core/modules/system/src/Form/ModulesUninstallForm.php +++ b/core/modules/system/src/Form/ModulesUninstallForm.php @@ -7,6 +7,7 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; +use Drupal\Core\Schema\SchemaDataInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -142,7 +143,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { // All modules which depend on this one must be uninstalled first, before // we can allow this module to be uninstalled. foreach (array_keys($module->required_by) as $dependent) { - if (drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) { + if (drupal_get_installed_schema_version($dependent) != SchemaDataInterface::UNINSTALLED) { $name = isset($modules[$dependent]->info['name']) ? $modules[$dependent]->info['name'] : $dependent; $form['modules'][$module->getName()]['#required_by'][] = $name; $form['uninstall'][$module->getName()]['#disabled'] = TRUE; diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 7d04188cf9..4e116e3f43 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -723,8 +723,9 @@ function system_requirements($phase) { // Check installed modules. $has_pending_updates = FALSE; + $schema_data = \Drupal::service('schema.data'); foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) { - $updates = \Drupal::service('schema.data')->getVersions($module); + $updates = $schema_data->getVersions($module); if ($updates) { $default = drupal_get_installed_schema_version($module); if (max($updates) > $default) { @@ -745,7 +746,7 @@ function system_requirements($phase) { if ($has_pending_updates) { $requirements['update']['severity'] = REQUIREMENT_ERROR; $requirements['update']['value'] = t('Out of date'); - $requirements['update']['description'] = t('Some modules have database schema updates to install. You should run the database update script immediately.', [':update' => \Drupal::url('system.db_update')]); + $requirements['update']['description'] = t('Some modules have database schema_data updates to install. You should run the database update script immediately.', [':update' => \Drupal::url('system.db_update')]); } $requirements['entity_update'] = [ diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php index 976032e050..eecd60ad0d 100644 --- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php +++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php @@ -4,6 +4,7 @@ use Drupal\Core\Extension\MissingDependencyException; use Drupal\Core\Extension\ModuleUninstallValidatorException; +use Drupal\Core\Schema\SchemaDataInterface; use Drupal\entity_test\Entity\EntityTest; use Drupal\KernelTests\KernelTestBase; @@ -126,7 +127,7 @@ public function testDependencyResolution() { $this->assertTrue($result, 'ModuleInstaller::uninstall() returned TRUE.'); foreach (['color', 'config', 'help'] as $module) { - $this->assertEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, "$module module was uninstalled."); + $this->assertEqual(drupal_get_installed_schema_version($module), SchemaDataInterface::UNINSTALLED, "$module module was uninstalled."); } $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: []; $this->assertEqual($uninstalled_modules, ['color', 'config', 'help'], 'Modules were uninstalled in the correct order.'); @@ -182,7 +183,7 @@ public function testUninstallProfileDependencyBC() { $result = $this->moduleInstaller()->uninstall([$dependency]); $this->assertTrue($result, 'ModuleInstaller::uninstall() returns TRUE.'); $this->assertFalse($this->moduleHandler()->moduleExists($dependency)); - $this->assertEqual(drupal_get_installed_schema_version($dependency), SCHEMA_UNINSTALLED, "$dependency module was uninstalled."); + $this->assertEqual(drupal_get_installed_schema_version($dependency), SchemaDataInterface::UNINSTALLED, "$dependency module was uninstalled."); // Verify that the installation profile itself was not uninstalled. $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: []; @@ -217,7 +218,7 @@ public function testUninstallProfileDependency() { $result = $this->moduleInstaller()->uninstall([$non_dependency]); $this->assertTrue($result, 'ModuleInstaller::uninstall() returns TRUE.'); $this->assertFalse($this->moduleHandler()->moduleExists($non_dependency)); - $this->assertEquals(drupal_get_installed_schema_version($non_dependency), SCHEMA_UNINSTALLED, "$non_dependency module was uninstalled."); + $this->assertEquals(drupal_get_installed_schema_version($non_dependency), SchemaDataInterface::UNINSTALLED, "$non_dependency module was uninstalled."); // Verify that the installation profile itself was not uninstalled. $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: []; @@ -311,7 +312,7 @@ public function testUninstallContentDependency() { $result = $this->moduleInstaller()->uninstall(['help']); $this->assertTrue($result, 'ModuleInstaller::uninstall() returns TRUE.'); - $this->assertEqual(drupal_get_installed_schema_version('entity_test'), SCHEMA_UNINSTALLED, "entity_test module was uninstalled."); + $this->assertEqual(drupal_get_installed_schema_version('entity_test'), SchemaDataInterface::UNINSTALLED, "entity_test module was uninstalled."); } /**