Skip to content
Snippets Groups Projects
Commit bf3c33c9 authored by João Ventura's avatar João Ventura
Browse files

Issue #3337634 by fgm, jrglasgow, jcnventura, joachim: Plans for Drupal 10 support?

parent 1a25e6f7
No related branches found
No related tags found
No related merge requests found
name: Schema
description: 'The Schema module provides functionality built on the Schema API.'
package: Database
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9.4 || ^10
type: module
......@@ -2,3 +2,10 @@ services:
plugin.manager.schema:
class: Drupal\schema\SchemaManager
parent: default_plugin_manager
schema.module_handler:
class: Drupal\schema\SchemaModuleHandler
parent: module_handler
arguments:
- '%app.root%'
- '%container.modules%'
- '@cache.bootstrap'
......@@ -20,7 +20,7 @@ class Config extends PluginBase implements SchemaProviderInterface {
public function get($rebuild = FALSE) {
$complete_schema = [];
foreach ([
'config.storage.staging',
'config.storage.sync',
'config.storage.snapshot',
'config.storage',
] as $service_id) {
......
......@@ -3,8 +3,11 @@
namespace Drupal\schema\Plugin\Schema;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\schema\SchemaProviderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides schema information defined by modules in implementations of
......@@ -17,10 +20,35 @@ use Drupal\schema\SchemaProviderInterface;
*
* @SchemaProvider(id = "system")
*/
class System extends PluginBase implements SchemaProviderInterface {
class System extends PluginBase implements SchemaProviderInterface, ContainerFactoryPluginInterface {
const CACHE_BIN = 'schema_provider_system';
/**
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected ModuleHandlerInterface $moduleHandler;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $moduleHandler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $moduleHandler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('schema.module_handler')
);
}
/**
* {@inheritdoc}
*/
......@@ -35,23 +63,8 @@ class System extends PluginBase implements SchemaProviderInterface {
// Otherwise, rebuild the schema cache.
else {
$schema = [];
// Load the .install files to get hook_schema.
\Drupal::moduleHandler()->loadAllIncludes('install');
require_once DRUPAL_ROOT . '/core/includes/common.inc';
// Invoke hook_schema for all modules.
foreach (\Drupal::moduleHandler()
->getImplementations('schema') as $module) {
// Cast the result of hook_schema() to an array, as a NULL return value
// would cause array_merge() to set the $schema variable to NULL as well.
// That would break modules which use $schema further down the line.
$current = (array) \Drupal::moduleHandler()
->invoke($module, 'schema');
// Set 'module' and 'name' keys for each table.
_drupal_schema_initialize($current, $module, FALSE);
$schema = array_merge($schema, $current);
}
\Drupal::moduleHandler()->alter('schema', $schema);
$schema = $this->moduleHandler->loadSchemaImplementations();
// If the schema is empty, avoid saving it: some database engines require
// the schema to perform queries, and this could lead to infinite loops.
......
......@@ -8,7 +8,7 @@ namespace Drupal\schema;
*/
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Driver\mysql\Schema as DatabaseSchema_mysql;
use Drupal\mysql\Driver\Database\mysql\Schema as DatabaseSchema_mysql;
class SchemaDatabaseSchema_mysql extends DatabaseSchema_mysql implements DatabaseSchemaInspectionInterface {
......
......@@ -7,7 +7,7 @@ namespace Drupal\schema;
* Schema module enhancements to DatabaseSchema_pgsql.
*/
use Drupal\Core\Database\Driver\pgsql\Schema as DatabaseSchema_pgsql;
use Drupal\pgsql\Driver\Database\pgsql\Schema as DatabaseSchema_pgsql;;
class SchemaDatabaseSchema_pgsql extends DatabaseSchema_pgsql implements DatabaseSchemaInspectionInterface {
......
......@@ -2,10 +2,10 @@
namespace Drupal\schema;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Factory\ContainerFactory;
/**
* Manager for SchemaProvider plugins.
......@@ -28,7 +28,7 @@ class SchemaManager extends DefaultPluginManager {
$this->alterInfo('schema_provider');
$this->setCacheBackend($cache_backend, 'schema_provider_plugins');
$this->factory = new DefaultFactory($this, 'Drupal\schema\SchemaProviderInterface');
$this->factory = new ContainerFactory($this, 'Drupal\schema\SchemaProviderInterface');
}
/**
......
<?php
namespace Drupal\schema;
use Drupal\Core\Extension\ModuleHandler;
/**
* Since Drupal 10 and ModuleHandler::getImplementations() is removed and
* ModuleHandler::getImplementationInfo() is protected
* \Drupal\schema\Plugin\Schema\System cannot call it, we have a child class
* that will call that method for us.
*/
class SchemaModuleHandler extends ModuleHandler {
/**
* @return array
*/
public function loadSchemaImplementations(): array {
require_once DRUPAL_ROOT . '/core/includes/common.inc';
// Load the .install files to get hook_schema.
$this->loadAllIncludes('install');
// The previous list of implementation was loaded before the .install files
// were loaded, reset them so we can get all the schema hooks.
$this->resetImplementations();
$schema = [];
// Invoke hook_schema for all modules.
if ($this->hasImplementations('schema')) {
$implementation_info = $this->getImplementationInfo('schema');
foreach ($implementation_info as $module => $module_file_name) {
// Cast the result of hook_schema() to an array, as a NULL return value
// would cause array_merge() to set the $schema variable to NULL as well.
// That would break modules which use $schema further down the line.
$current = (array) $this->invoke($module, 'schema');
// Fills in required default values for table definitions from
// hook_schema(): set 'module' and 'name' keys for each table.
foreach ($schema as $name => &$table) {
if (empty($table['module'])) {
$table['module'] = $module;
}
if (!isset($table['name'])) {
$table['name'] = $name;
}
}
$schema = array_merge($schema, $current);
}
}
$this->alter('schema', $schema);
return $schema;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment