diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 9cc33ec..a704ebf 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -326,12 +326,12 @@ function find_conf_path($http_host, $script_name, $require_settings = TRUE) { * * @param string $type * (optional) The type of config directory to return. Drupal core provides - * 'active' and 'staging'. Defaults to CONFIG_STAGING_DIRECTORY. + * 'active' and 'staging'. Defaults to CONFIG_ACTIVE_DIRECTORY. * * @return string * The configuration directory path. */ -function config_get_config_directory($type = CONFIG_STAGING_DIRECTORY) { +function config_get_config_directory($type = CONFIG_ACTIVE_DIRECTORY) { global $config_directories; if (!empty($config_directories[$type])) { diff --git a/core/includes/file.inc b/core/includes/file.inc index 18d7a68..f141cc8 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -575,6 +575,7 @@ function file_ensure_htaccess() { file_save_htaccess('private://', TRUE); } file_save_htaccess('temporary://', TRUE); + file_save_htaccess(config_get_config_directory(), TRUE); file_save_htaccess(config_get_config_directory(CONFIG_STAGING_DIRECTORY), TRUE); } diff --git a/core/includes/install.inc b/core/includes/install.inc index 28e1ba1..e7e5206 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -178,6 +178,10 @@ function drupal_get_database_types() { * and comment properties. * @code * $settings['config_directories'] = array( + * CONFIG_ACTIVE_DIRECTORY => (object) array( + * 'value' => 'config_hash/active' + * 'required' => TRUE, + * ), * CONFIG_STAGING_DIRECTORY => (object) array( * 'value' => 'config_hash/staging', * 'required' => TRUE, @@ -464,6 +468,10 @@ function drupal_install_config_directories() { if (empty($config_directories)) { $config_directories_hash = Crypt::randomBytesBase64(55); $settings['config_directories'] = array( + CONFIG_ACTIVE_DIRECTORY => (object) array( + 'value' => conf_path() . '/files/config_' . $config_directories_hash . '/active', + 'required' => TRUE, + ), CONFIG_STAGING_DIRECTORY => (object) array( 'value' => conf_path() . '/files/config_' . $config_directories_hash . '/staging', 'required' => TRUE, @@ -474,7 +482,7 @@ function drupal_install_config_directories() { } // Ensure the config directories exist or can be created, and are writable. - foreach (array(CONFIG_STAGING_DIRECTORY) as $config_type) { + foreach (array(CONFIG_ACTIVE_DIRECTORY, CONFIG_STAGING_DIRECTORY) as $config_type) { // This should never fail, since if the config directory was specified in // settings.php it will have already been created and verified earlier, and // if it wasn't specified in settings.php, it is created here inside the @@ -493,6 +501,9 @@ function drupal_install_config_directories() { // created, we have to write out the README rather than just adding it // to the drupal core repo. switch ($config_type) { + case CONFIG_ACTIVE_DIRECTORY: + $text = 'This directory contains the active configuration for your Drupal site. To move this configuration between environments, contents from this directory should be placed in the staging directory on the target server. To make this configuration active, see admin/config/development/configuration/sync on the target server.'; + break; case CONFIG_STAGING_DIRECTORY: $text = 'This directory contains configuration to be imported into your Drupal site. To make this configuration active, see admin/config/development/configuration/sync.'; break; diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php b/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php index 7d0c465..4b2b6f7 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php @@ -34,7 +34,7 @@ class ConfigSingleExportForm extends FormBase { protected $configStorage; /** - * The config storage. + * The YAML dumper. * * @var \Symfony\Component\Yaml\Dumper */ diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php b/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php index 1295862..7b3643c 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\ConfirmFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Yaml\Yaml; /** * Provides a form for importing a single configuration file. @@ -32,6 +33,12 @@ class ConfigSingleImportForm extends ConfirmFormBase { protected $configStorage; /** + * The YAML component. + * + * @var \Symfony\Component\Yaml\Yaml + */ + protected $yaml; + /** * If the config exists, this is that object. Otherwise, FALSE. * * @var \Drupal\Core\Config\Config|\Drupal\Core\Config\Entity\ConfigEntityInterface|bool @@ -52,10 +59,13 @@ class ConfigSingleImportForm extends ConfirmFormBase { * The entity manager. * @param \Drupal\Core\Config\StorageInterface $config_storage * The config storage. + * @param \Symfony\Component\Yaml\Parser $parser + * The yaml dumper. */ - public function __construct(EntityManagerInterface $entity_manager, StorageInterface $config_storage) { + public function __construct(EntityManagerInterface $entity_manager, StorageInterface $config_storage, Yaml $yaml) { $this->entityManager = $entity_manager; $this->configStorage = $config_storage; + $this->yaml = $yaml; } /** @@ -64,7 +74,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 Yaml() ); } @@ -184,7 +195,7 @@ public function validateForm(array &$form, array &$form_state) { } // Decode the submitted import. - $data = $this->configStorage->decode($form_state['values']['import']); + $data = $this->yaml->parse($form_state['values']['import']); // Validate for config entities. if ($form_state['values']['config_type'] !== 'system.simple') { diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php index 46a14d4..5f1a416 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php @@ -130,6 +130,7 @@ public function testImportSimpleConfiguration() { */ public function testExport() { $this->drupalLogin($this->drupalCreateUser(array('export configuration'))); + $yaml = new Yaml(); $this->drupalGet('admin/config/development/configuration/single/export/system.simple'); $this->assertFieldByXPath('//select[@name="config_type"]//option[@selected="selected"]', t('Simple configuration'), 'The simple configuration option is selected when specified in the URL.'); @@ -152,7 +153,7 @@ public function testExport() { $this->assertFieldByXPath('//select[@name="config_name"]//option[@selected="selected"]', t('Fallback date format'), 'The fallback date format config entity is selected when specified in the URL.'); $fallback_date = \Drupal::entityManager()->getStorage('date_format')->load('fallback'); - $data = \Drupal::service('config.storage')->encode($fallback_date->toArray()); + $data = $yaml->dump($fallback_date->toArray(), 2, 2); $this->assertFieldByXPath('//textarea[@name="export"]', $data, 'The fallback date format config entity export code is displayed.'); } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 65deaf6..1dc0523 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -109,9 +109,10 @@ protected function prepareConfigStorage() { // 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) { + // We use a different table name here and in the container to avoid + // exceptions when system module is installed. + Database::getConnection()->schema()->createTable('test_base_config', $schema['config']); + foreach (array(CONFIG_ACTIVE_DIRECTORY, CONFIG_STAGING_DIRECTORY) as $type) { // Assign the relative path to the global variable. $path = $this->siteDirectory . '/config_' . $type; $GLOBALS['config_directories'][$type] = $path; @@ -230,7 +231,7 @@ public function containerBuild(ContainerBuilder $container) { $container ->register('config.storage', 'Drupal\Core\Config\DatabaseStorage') ->addArgument(Database::getConnection()) - ->addArgument('config'); + ->addArgument('test_base_config'); $this->settingsSet('keyvalue_default', 'keyvalue.memory'); $container->set('keyvalue.memory', $this->keyValueFactory); diff --git a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php index aaf9612..3e5e9a4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php @@ -30,7 +30,7 @@ function setUp() { // invoke DrupalUnitTestBase::setUp(), since that would set up further // environment aspects, which would distort this test, because it tests // the DrupalKernel (re-)building itself. - $this->prepareConfigDirectories(); + $this->prepareConfigStorage(); $this->settingsSet('php_storage', array('service_container' => array( 'bin' => 'service_container', diff --git a/core/modules/system/system.install b/core/modules/system/system.install index fc74354..0bd1942 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -361,6 +361,7 @@ function system_requirements($phase) { // defined, the installer will create a valid config directory later, but // during runtime we must always display an error. if (!empty($GLOBALS['config_directories'])) { + $directories[] = config_get_config_directory(CONFIG_ACTIVE_DIRECTORY); $directories[] = config_get_config_directory(CONFIG_STAGING_DIRECTORY); } elseif ($phase != 'install') {