diff --git a/core/core.services.yml b/core/core.services.yml index 18e37f9..89ea76d 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -75,8 +75,8 @@ services: class: Drupal\Core\Config\ConfigManager arguments: ['@entity.manager', '@config.factory', '@config.typed', '@string_translation', '@config.storage'] config.storage: - class: Drupal\Core\Config\CachedStorage - arguments: ['@config.cachedstorage.storage', '@cache.config'] + class: Drupal\Core\Config\DatabaseStorage + arguments: ['@database', 'config'] config.factory: class: Drupal\Core\Config\ConfigFactory tags: diff --git a/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php b/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php index e075261..1df8f07 100644 --- a/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php +++ b/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\Settings; +use Drupal\Core\Database\Database; /** * Defines a factory for retrieving the config storage used pre-kernel. @@ -26,7 +27,7 @@ public static function get() { return call_user_func($drupal_bootstrap_config_storage); } else { - return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY)); + return new DatabaseStorage(Database::getConnection(), 'config'); } } diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index fd8f2ee..aa0e022 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -176,7 +176,7 @@ public function decode($raw) { */ public function listAll($prefix = '') { return $this->connection->query('SELECT name FROM {' . $this->connection->escapeTable($this->table) . '} WHERE name LIKE :name', array( - ':name' => db_like($prefix) . '%', + ':name' => $this->connection->escapeLike($prefix) . '%', ), $this->options)->fetchCol(); } diff --git a/core/modules/config/lib/Drupal/config/Controller/ConfigController.php b/core/modules/config/lib/Drupal/config/Controller/ConfigController.php index 18f6287..c79b8cb 100644 --- a/core/modules/config/lib/Drupal/config/Controller/ConfigController.php +++ b/core/modules/config/lib/Drupal/config/Controller/ConfigController.php @@ -12,6 +12,7 @@ use Drupal\Core\Config\StorageInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\system\FileDownloadController; +use Symfony\Component\Yaml\Dumper; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -81,13 +82,15 @@ public function __construct(StorageInterface $target_storage, StorageInterface $ * Downloads a tarball of the site configuration. */ public function downloadExport() { + file_unmanaged_delete(file_directory_temp() . '/config.tar.gz'); + + $dumper = new Dumper(); + $dumper->setIndentation(2); + $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz'); - $config_dir = config_get_config_directory(); - $config_files = array(); - foreach (\Drupal::service('config.storage')->listAll() as $config_name) { - $config_files[] = $config_dir . '/' . $config_name . '.yml'; + foreach (\Drupal::service('config.storage')->listAll() as $name) { + $archiver->addString("$name.yml", $dumper->dump(\Drupal::config($name)->get(), PHP_INT_MAX, 0, TRUE)); } - $archiver->createModify($config_files, '', config_get_config_directory()); $request = new Request(array('file' => 'config.tar.gz')); return $this->fileDownloadController->download($request, 'temporary'); diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php b/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php index 101dacb..7d0c465 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormBase; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Yaml\Dumper; /** * Provides a form for exporting a single configuration file. @@ -33,6 +34,13 @@ class ConfigSingleExportForm extends FormBase { protected $configStorage; /** + * The config storage. + * + * @var \Symfony\Component\Yaml\Dumper + */ + protected $dumper; + + /** * Tracks the valid config entity type definitions. * * @var \Drupal\Core\Entity\EntityTypeInterface[] @@ -46,10 +54,14 @@ class ConfigSingleExportForm extends FormBase { * The entity manager. * @param \Drupal\Core\Config\StorageInterface $config_storage * The config storage. + * @param \Symfony\Component\Yaml\Dumper $dumper + * The yaml dumper. */ - public function __construct(EntityManagerInterface $entity_manager, StorageInterface $config_storage) { + public function __construct(EntityManagerInterface $entity_manager, StorageInterface $config_storage, Dumper $dumper) { $this->entityManager = $entity_manager; $this->configStorage = $config_storage; + $this->dumper = $dumper; + $this->dumper->setIndentation(2); } /** @@ -58,7 +70,8 @@ public function __construct(EntityManagerInterface $entity_manager, StorageInter public static function create(ContainerInterface $container) { return new static( $container->get('entity.manager'), - $container->get('config.storage') + $container->get('config.storage'), + new Dumper() ); } @@ -151,8 +164,7 @@ public function updateExport($form, &$form_state) { $name = $form_state['values']['config_name']; } // Read the raw data for this config name, encode it, and display it. - $data = $this->configStorage->read($name); - $form['export']['#value'] = $this->configStorage->encode($data); + $form['export']['#value'] = $this->dumper->dump($this->configStorage->read($name), PHP_INT_MAX, 0, TRUE); $form['export']['#description'] = $this->t('The filename is %name.', array('%name' => $name . '.yml')); return $form['export']; } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 7737cc8..65deaf6 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -103,10 +103,15 @@ protected function beforePrepareEnvironment() { * * @see config_get_config_directory() */ - protected function prepareConfigDirectories() { + protected function prepareConfigStorage() { $this->configDirectories = array(); include_once DRUPAL_ROOT . '/core/includes/install.inc'; - foreach (array(CONFIG_ACTIVE_DIRECTORY, CONFIG_STAGING_DIRECTORY) as $type) { + // Create the configuration table. + module_load_install('system'); + $schema = system_schema(); + Database::getConnection()->schema()->createTable('config', $schema['config']); + //$this->installSchema('system', 'config'); + foreach (array(CONFIG_STAGING_DIRECTORY) as $type) { // Assign the relative path to the global variable. $path = $this->siteDirectory . '/config_' . $type; $GLOBALS['config_directories'][$type] = $path; @@ -127,9 +132,6 @@ protected function setUp() { parent::setUp(); - // Create and set new configuration directories. - $this->prepareConfigDirectories(); - // Build a minimal, partially mocked environment for unit tests. $this->containerBuild(\Drupal::getContainer()); // Make sure it survives kernel rebuilds. @@ -137,7 +139,8 @@ protected function setUp() { \Drupal::state()->set('system.module.files', $this->moduleFiles); \Drupal::state()->set('system.theme.files', $this->themeFiles); - + // Create and set new configuration directories. + $this->prepareConfigStorage(); // Bootstrap the kernel. // No need to dump it; this test runs in-memory. $this->kernel = new DrupalKernel('unit_testing', drupal_classloader(), FALSE); @@ -225,8 +228,9 @@ public function containerBuild(ContainerBuilder $container) { $container->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory'); $container - ->register('config.storage', 'Drupal\Core\Config\FileStorage') - ->addArgument($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]); + ->register('config.storage', 'Drupal\Core\Config\DatabaseStorage') + ->addArgument(Database::getConnection()) + ->addArgument('config'); $this->settingsSet('keyvalue_default', 'keyvalue.memory'); $container->set('keyvalue.memory', $this->keyValueFactory); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index ca5d128..0bd1942 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -970,7 +970,25 @@ function system_schema() { 'source_langcode_pid' => array('source', 'langcode', 'pid'), ), ); - + $schema['config'] = array( + 'description' => 'The base table for configuration data.', + 'fields' => array( + 'name' => array( + 'description' => 'Primary Key: Unique config object name.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'data' => array( + 'description' => 'A serialized configuration object data.', + 'type' => 'blob', + 'not null' => FALSE, + 'size' => 'big', + ), + ), + 'primary key' => array('name'), + ); $schema['config_snapshot'] = array( 'description' => 'Stores a snapshot of the last imported configuration.', 'fields' => array(