protected function setUp()
 {
     $this->info = array('type' => 'profile', 'core' => \Drupal::CORE_COMPATIBILITY, 'name' => 'Override standard', 'hidden' => TRUE);
     // File API functions are not available yet.
     $path = $this->siteDirectory . '/profiles/standard';
     mkdir($path, 0777, TRUE);
     file_put_contents("{$path}/standard.info.yml", Yaml::encode($this->info));
     parent::setUp();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->info = array('type' => 'profile', 'core' => \Drupal::CORE_COMPATIBILITY, 'name' => 'Distribution profile', 'distribution' => array('name' => 'My Distribution', 'langcode' => $this->langcode, 'install' => array('theme' => 'bartik')));
     // File API functions are not available yet.
     $path = $this->siteDirectory . '/profiles/mydistro';
     mkdir($path, 0777, TRUE);
     file_put_contents("{$path}/mydistro.info.yml", Yaml::encode($this->info));
     parent::setUp();
 }
Пример #3
0
 /**
  * Test that the overridden serializer is called.
  *
  * @covers ::getSerializer
  * @runInSeparateProcess
  */
 public function testGetSeralization()
 {
     new Settings(['yaml_parser_class' => YamlParserProxy::class]);
     $this->assertEquals(YamlParserProxy::class, Settings::get('yaml_parser_class'));
     $mock = $this->getMockBuilder('\\stdClass')->setMethods(['encode', 'decode', 'getFileExtension'])->getMock();
     $mock->expects($this->once())->method('decode');
     YamlParserProxy::setMock($mock);
     Yaml::decode('---');
     new Settings([]);
 }
Пример #4
0
 /**
  * Tests export of configuration.
  */
 function testExport()
 {
     // Verify the export page with export submit button is available.
     $this->drupalGet('admin/config/development/configuration/full/export');
     $this->assertFieldById('edit-submit', t('Export'));
     // Submit the export form and verify response.
     $this->drupalPostForm('admin/config/development/configuration/full/export', array(), t('Export'));
     $this->assertResponse(200, 'User can access the download callback.');
     // Test if header contains file name with hostname and timestamp.
     $request = \Drupal::request();
     $hostname = str_replace('.', '-', $request->getHttpHost());
     $header_content_disposition = $this->drupalGetHeader('content-disposition');
     $header_match = (bool) preg_match('/attachment; filename="config-' . preg_quote($hostname) . '-\\d{4}-\\d{2}-\\d{2}-\\d{2}-\\d{2}\\.tar\\.gz"/', $header_content_disposition);
     $this->assertTrue($header_match, "Header with filename matches the expected format.");
     // Get the archived binary file provided to user for download.
     $archive_data = $this->getRawContent();
     // Temporarily save the archive file.
     $uri = file_unmanaged_save_data($archive_data, 'temporary://config.tar.gz');
     // Extract the archive and verify it's not empty.
     $file_path = file_directory_temp() . '/' . file_uri_target($uri);
     $archiver = new Tar($file_path);
     $archive_contents = $archiver->listContents();
     $this->assert(!empty($archive_contents), 'Downloaded archive file is not empty.');
     // Prepare the list of config files from active storage, see
     // \Drupal\config\Controller\ConfigController::downloadExport().
     $storage_active = $this->container->get('config.storage');
     $config_files = array();
     foreach ($storage_active->listAll() as $config_name) {
         $config_files[] = $config_name . '.yml';
     }
     // Assert that the downloaded archive file contents are the same as the test
     // site active store.
     $this->assertIdentical($archive_contents, $config_files);
     // Ensure the test configuration override is in effect but was not exported.
     $this->assertIdentical(\Drupal::config('system.maintenance')->get('message'), 'Foo');
     $archiver->extract(file_directory_temp(), array('system.maintenance.yml'));
     $file_contents = file_get_contents(file_directory_temp() . '/' . 'system.maintenance.yml');
     $exported = Yaml::decode($file_contents);
     $this->assertNotIdentical($exported['message'], 'Foo');
     // Check the single export form doesn't have "form-required" elements.
     $this->drupalGet('admin/config/development/configuration/single/export');
     $this->assertNoRaw('js-form-required form-required', 'No form required fields are found.');
     // Ensure the temporary file is not available to users without the
     // permission.
     $this->drupalLogout();
     $this->drupalGet('system/temporary', ['query' => ['file' => 'config.tar.gz']]);
     $this->assertResponse(403);
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function parse($filename)
 {
     if (!file_exists($filename)) {
         $parsed_info = array();
     } else {
         try {
             $parsed_info = Yaml::decode(file_get_contents($filename));
         } catch (InvalidDataTypeException $e) {
             throw new InfoParserException("Unable to parse {$filename} " . $e->getMessage());
         }
         $missing_keys = array_diff($this->getRequiredKeys(), array_keys($parsed_info));
         if (!empty($missing_keys)) {
             throw new InfoParserException('Missing required keys (' . implode(', ', $missing_keys) . ') in ' . $filename);
         }
         if (isset($parsed_info['version']) && $parsed_info['version'] === 'VERSION') {
             $parsed_info['version'] = \Drupal::VERSION;
         }
     }
     return $parsed_info;
 }
 /**
  * Tests post-update responsive_image_post_update_dependency().
  *
  * @see responsive_image_post_update_dependency()
  */
 public function testPostUpdateDependency()
 {
     // Installing the 'wide' responsive image style.
     $wide_image_style = Yaml::decode(file_get_contents(__DIR__ . '/../../../../../profiles/standard/config/optional/responsive_image.styles.wide.yml'));
     $this->config('responsive_image.styles.wide')->setData($wide_image_style)->save(TRUE);
     // Change 'field_image' formatter to a responsive image formatter.
     $options = ['type' => 'responsive_image', 'label' => 'hidden', 'settings' => ['responsive_image_style' => 'wide', 'image_link' => ''], 'third_party_settings' => []];
     $display = $this->config('core.entity_view_display.node.article.default');
     $display->set('content.field_image', $options)->save(TRUE);
     // Check that there's no dependency to 'responsive_image.styles.wide'.
     $dependencies = $display->get('dependencies.config') ?: [];
     $this->assertFalse(in_array('responsive_image.styles.wide', $dependencies));
     // Run updates.
     $this->runUpdates();
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
     $view_display = EntityViewDisplay::load('node.article.default');
     $dependencies = $view_display->getDependencies() + ['config' => []];
     // Check that post-update added a 'responsive_image.styles.wide' dependency.
     $this->assertTrue(in_array('responsive_image.styles.wide', $dependencies['config']));
 }
 protected function setUp()
 {
     // Copy the testing_config_overrides install profile so we can change the
     // configuration to include a dependency that can not be met. File API
     // functions are not available yet.
     $dest = $this->siteDirectory . '/profiles/testing_config_overrides';
     mkdir($dest, 0777, TRUE);
     $source = DRUPAL_ROOT . '/core/profiles/testing_config_overrides';
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $item) {
         if ($item->isDir()) {
             mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
         } else {
             copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
         }
     }
     // Add a dependency that can not be met because User is installed before
     // Action.
     $config_file = $dest . DIRECTORY_SEPARATOR . InstallStorage::CONFIG_INSTALL_DIRECTORY . DIRECTORY_SEPARATOR . 'system.action.user_block_user_action.yml';
     $action = Yaml::decode(file_get_contents($config_file));
     $action['dependencies']['module'][] = 'action';
     file_put_contents($config_file, Yaml::encode($action));
     parent::setUp();
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // The confirmation step needs no additional validation.
     if ($this->data) {
         return;
     }
     try {
         // Decode the submitted import.
         $data = Yaml::decode($form_state->getValue('import'));
     } catch (InvalidDataTypeException $e) {
         $form_state->setErrorByName('import', $this->t('The import failed with the following message: %message', ['%message' => $e->getMessage()]));
     }
     // Validate for config entities.
     if ($form_state->getValue('config_type') !== 'system.simple') {
         $definition = $this->entityManager->getDefinition($form_state->getValue('config_type'));
         $id_key = $definition->getKey('id');
         // If a custom entity ID is specified, override the value in the
         // configuration data being imported.
         if (!$form_state->isValueEmpty('custom_entity_id')) {
             $data[$id_key] = $form_state->getValue('custom_entity_id');
         }
         $entity_storage = $this->entityManager->getStorage($form_state->getValue('config_type'));
         // If an entity ID was not specified, set an error.
         if (!isset($data[$id_key])) {
             $form_state->setErrorByName('import', $this->t('Missing ID key "@id_key" for this @entity_type import.', array('@id_key' => $id_key, '@entity_type' => $definition->getLabel())));
             return;
         }
         $config_name = $definition->getConfigPrefix() . '.' . $data[$id_key];
         // If there is an existing entity, ensure matching ID and UUID.
         if ($entity = $entity_storage->load($data[$id_key])) {
             $this->configExists = $entity;
             if (!isset($data['uuid'])) {
                 $form_state->setErrorByName('import', $this->t('An entity with this machine name already exists but the import did not specify a UUID.'));
                 return;
             }
             if ($data['uuid'] !== $entity->uuid()) {
                 $form_state->setErrorByName('import', $this->t('An entity with this machine name already exists but the UUID does not match.'));
                 return;
             }
         } elseif (isset($data['uuid']) && $entity_storage->loadByProperties(array('uuid' => $data['uuid']))) {
             $form_state->setErrorByName('import', $this->t('An entity with this UUID already exists but the machine name does not match.'));
         }
     } else {
         $config_name = $form_state->getValue('config_name');
         $config = $this->config($config_name);
         $this->configExists = !$config->isNew() ? $config : FALSE;
     }
     // Use ConfigImporter validation.
     if (!$form_state->getErrors()) {
         $source_storage = new StorageReplaceDataWrapper($this->configStorage);
         $source_storage->replaceData($config_name, $data);
         $storage_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager);
         if (!$storage_comparer->createChangelist()->hasChanges()) {
             $form_state->setErrorByName('import', $this->t('There are no changes to import.'));
         } else {
             $config_importer = new ConfigImporter($storage_comparer, $this->eventDispatcher, $this->configManager, $this->lock, $this->typedConfigManager, $this->moduleHandler, $this->moduleInstaller, $this->themeHandler, $this->getStringTranslation());
             try {
                 $config_importer->validate();
                 $form_state->set('config_importer', $config_importer);
             } catch (ConfigImporterException $e) {
                 // There are validation errors.
                 $item_list = ['#theme' => 'item_list', '#items' => $config_importer->getErrors(), '#title' => $this->t('The configuration cannot be imported because it failed validation for the following reasons:')];
                 $form_state->setErrorByName('import', $this->renderer->render($item_list));
             }
         }
     }
     // Store the decoded version of the submitted import.
     $form_state->setValueForElement($form['import'], $data);
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 protected function decode($file)
 {
     return Yaml::decode(file_get_contents($file)) ?: [];
 }
Пример #10
0
 /**
  * Helper method for removing all cache bins registered by a given module.
  *
  * @param string $module
  *   The name of the module for which to remove all registered cache bins.
  */
 protected function removeCacheBins($module)
 {
     // Remove any cache bins defined by a module.
     $service_yaml_file = drupal_get_path('module', $module) . "/{$module}.services.yml";
     if (file_exists($service_yaml_file)) {
         $definitions = Yaml::decode(file_get_contents($service_yaml_file));
         if (isset($definitions['services'])) {
             foreach ($definitions['services'] as $id => $definition) {
                 if (isset($definition['tags'])) {
                     foreach ($definition['tags'] as $tag) {
                         // This works for the default cache registration and even in some
                         // cases when a non-default "super" factory is used. That should
                         // be extremely rare.
                         if ($tag['name'] == 'cache.bin' && isset($definition['factory_service']) && isset($definition['factory_method']) && !empty($definition['arguments'])) {
                             try {
                                 $factory = \Drupal::service($definition['factory_service']);
                                 if (method_exists($factory, $definition['factory_method'])) {
                                     $backend = call_user_func_array(array($factory, $definition['factory_method']), $definition['arguments']);
                                     if ($backend instanceof CacheBackendInterface) {
                                         $backend->removeBin();
                                     }
                                 }
                             } catch (\Exception $e) {
                                 watchdog_exception('system', $e, 'Failed to remove cache bin defined by the service %id.', array('%id' => $id));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #11
0
 /**
  * Handles switching the export textarea.
  */
 public function updateExport($form, FormStateInterface $form_state)
 {
     // Determine the full config name for the selected config entity.
     if ($form_state->getValue('config_type') !== 'system.simple') {
         $definition = $this->entityManager->getDefinition($form_state->getValue('config_type'));
         $name = $definition->getConfigPrefix() . '.' . $form_state->getValue('config_name');
     } else {
         $name = $form_state->getValue('config_name');
     }
     // Read the raw data for this config name, encode it, and display it.
     $form['export']['#value'] = Yaml::encode($this->configStorage->read($name));
     $form['export']['#description'] = $this->t('Filename: %name', array('%name' => $name . '.yml'));
     return $form['export'];
 }
<?php

/**
 * @file
 * Test fixture for \Drupal\rest\Tests\Update\RestExportAuthUpdateTest.
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
$config = $connection;
// Set the schema version.
$connection->insert('key_value')->fields(['collection' => 'system.schema', 'name' => 'rest', 'value' => 'i:8000;'])->fields(['collection' => 'system.schema', 'name' => 'serialization', 'value' => 'i:8000;'])->fields(['collection' => 'system.schema', 'name' => 'basic_auth', 'value' => 'i:8000;'])->execute();
// Update core.extension.
$extensions = $connection->select('config')->fields('config', ['data'])->condition('collection', '')->condition('name', 'core.extension')->execute()->fetchField();
$extensions = unserialize($extensions);
$extensions['module']['rest'] = 0;
$extensions['module']['serialization'] = 0;
$extensions['module']['basic_auth'] = 0;
$connection->update('config')->fields(['data' => serialize($extensions)])->condition('collection', '')->condition('name', 'core.extension')->execute();
$config = ['link_domain' => '~'];
$data = $connection->insert('config')->fields(['name' => 'rest.settings', 'data' => serialize($config), 'collection' => ''])->execute();
$connection->insert('config')->fields(['name' => 'views.view.rest_export_with_authorization'])->execute();
$connection->merge('config')->condition('name', 'views.view.rest_export_with_authorization')->condition('collection', '')->fields(['data' => serialize(Yaml::decode(file_get_contents('core/modules/views/tests/modules/views_test_config/test_views/views.view.rest_export_with_authorization.yml')))])->execute();
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function decode($raw)
 {
     $data = Yaml::decode($raw);
     // A simple string is valid YAML for any reason.
     if (!is_array($data)) {
         return FALSE;
     }
     return $data;
 }
<?php

/**
 * @file
 * Contains database additions to drupal-8.bare.standard.php.gz for testing the
 * upgrade path of https://www.drupal.org/node/2455125.
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
// Structure of a view with timestamp fields.
$views_configs = [];
$views_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/drupal-8.views-entity-views-data-2455125.yml'));
foreach ($views_configs as $views_config) {
    $connection->insert('config')->fields(array('collection', 'name', 'data'))->values(array('collection' => '', 'name' => 'views.view.' . $views_config['id'], 'data' => serialize($views_config)))->execute();
}
Пример #15
0
 /**
  * Parses a given library file and allows modules and themes to alter it.
  *
  * This method sets the parsed information onto the library property.
  *
  * Library information is parsed from *.libraries.yml files; see
  * editor.library.yml for an example. Every library must have at least one js
  * or css entry. Each entry starts with a machine name and defines the
  * following elements:
  * - js: A list of JavaScript files to include. Each file is keyed by the file
  *   path. An item can have several attributes (like HTML
  *   attributes). For example:
  *   @code
  *   js:
  *     path/js/file.js: { attributes: { defer: true } }
  *   @endcode
  *   If the file has no special attributes, just use an empty object:
  *   @code
  *   js:
  *     path/js/file.js: {}
  *   @endcode
  *   The path of the file is relative to the module or theme directory, unless
  *   it starts with a /, in which case it is relative to the Drupal root. If
  *   the file path starts with //, it will be treated as a protocol-free,
  *   external resource (e.g., //cdn.com/library.js). Full URLs
  *   (e.g., http://cdn.com/library.js) as well as URLs that use a valid
  *   stream wrapper (e.g., public://path/to/file.js) are also supported.
  * - css: A list of categories for which the library provides CSS files. The
  *   available categories are:
  *   - base
  *   - layout
  *   - component
  *   - state
  *   - theme
  *   Each category is itself a key for a sub-list of CSS files to include:
  *   @code
  *   css:
  *     component:
  *       css/file.css: {}
  *   @endcode
  *   Just like with JavaScript files, each CSS file is the key of an object
  *   that can define specific attributes. The format of the file path is the
  *   same as for the JavaScript files.
  * - dependencies: A list of libraries this library depends on.
  * - version: The library version. The string "VERSION" can be used to mean
  *   the current Drupal core version.
  * - header: By default, JavaScript files are included in the footer. If the
  *   script must be included in the header (along with all its dependencies),
  *   set this to true. Defaults to false.
  * - minified: If the file is already minified, set this to true to avoid
  *   minifying it again. Defaults to false.
  * - remote: If the library is a third-party script, this provides the
  *   repository URL for reference.
  * - license: If the remote property is set, the license information is
  *   required. It has 3 properties:
  *   - name: The human-readable name of the license.
  *   - url: The URL of the license file/information for the version of the
  *     library used.
  *   - gpl-compatible: A Boolean for whether this library is GPL compatible.
  *
  * See https://www.drupal.org/node/2274843#define-library for more
  * information.
  *
  * @param string $extension
  *   The name of the extension that registered a library.
  * @param string $path
  *   The relative path to the extension.
  *
  * @return array
  *   An array of parsed library data.
  *
  * @throws \Drupal\Core\Asset\Exception\InvalidLibraryFileException
  *   Thrown when a parser exception got thrown.
  */
 protected function parseLibraryInfo($extension, $path)
 {
     $libraries = [];
     $library_file = $path . '/' . $extension . '.libraries.yml';
     if (file_exists($this->root . '/' . $library_file)) {
         try {
             $libraries = Yaml::decode(file_get_contents($this->root . '/' . $library_file));
         } catch (InvalidDataTypeException $e) {
             // Rethrow a more helpful exception to provide context.
             throw new InvalidLibraryFileException(sprintf('Invalid library definition in %s: %s', $library_file, $e->getMessage()), 0, $e);
         }
     }
     // Allow modules to add dynamic library definitions.
     $hook = 'library_info_build';
     if ($this->moduleHandler->implementsHook($extension, $hook)) {
         $libraries = NestedArray::mergeDeep($libraries, $this->moduleHandler->invoke($extension, $hook));
     }
     // Allow modules to alter the module's registered libraries.
     $this->moduleHandler->alter('library_info', $libraries, $extension);
     $this->themeManager->alter('library_info', $libraries, $extension);
     return $libraries;
 }
 /**
  * Tests exporting a single configuration file.
  */
 public function testExport()
 {
     $this->drupalLogin($this->drupalCreateUser(array('export configuration')));
     $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.');
     // Spot check several known simple configuration files.
     $element = $this->xpath('//select[@name="config_name"]');
     $options = $this->getAllOptions($element[0]);
     $expected_options = array('system.site', 'user.settings');
     foreach ($options as &$option) {
         $option = (string) $option;
     }
     $this->assertIdentical($expected_options, array_intersect($expected_options, $options), 'The expected configuration files are listed.');
     $this->drupalGet('admin/config/development/configuration/single/export/system.simple/system.image');
     $this->assertFieldByXPath('//textarea[@name="export"]', "toolkit: gd\n_core:\n  default_config_hash: durWHaKeBaq4d9Wpi4RqwADj1OufDepcnJuhVLmKN24\n", 'The expected system configuration is displayed.');
     $this->drupalGet('admin/config/development/configuration/single/export/date_format');
     $this->assertFieldByXPath('//select[@name="config_type"]//option[@selected="selected"]', t('Date format'), 'The date format entity type is selected when specified in the URL.');
     $this->drupalGet('admin/config/development/configuration/single/export/date_format/fallback');
     $this->assertFieldByXPath('//select[@name="config_name"]//option[@selected="selected"]', t('Fallback date format (fallback)'), 'The fallback date format config entity is selected when specified in the URL.');
     $fallback_date = \Drupal::entityManager()->getStorage('date_format')->load('fallback');
     $yaml_text = (string) $this->xpath('//textarea[@name="export"]')[0];
     $this->assertEqual(Yaml::decode($yaml_text), $fallback_date->toArray(), 'The fallback date format config entity export code is displayed.');
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 public function diff(StorageInterface $source_storage, StorageInterface $target_storage, $source_name, $target_name = NULL, $collection = StorageInterface::DEFAULT_COLLECTION)
 {
     if ($collection != StorageInterface::DEFAULT_COLLECTION) {
         $source_storage = $source_storage->createCollection($collection);
         $target_storage = $target_storage->createCollection($collection);
     }
     if (!isset($target_name)) {
         $target_name = $source_name;
     }
     // The output should show configuration object differences formatted as YAML.
     // But the configuration is not necessarily stored in files. Therefore, they
     // need to be read and parsed, and lastly, dumped into YAML strings.
     $source_data = explode("\n", Yaml::encode($source_storage->read($source_name)));
     $target_data = explode("\n", Yaml::encode($target_storage->read($target_name)));
     // Check for new or removed files.
     if ($source_data === array('false')) {
         // Added file.
         // Cast the result of t() to a string, as the diff engine doesn't know
         // about objects.
         $source_data = array((string) $this->t('File added'));
     }
     if ($target_data === array('false')) {
         // Deleted file.
         // Cast the result of t() to a string, as the diff engine doesn't know
         // about objects.
         $target_data = array((string) $this->t('File removed'));
     }
     return new Diff($source_data, $target_data);
 }
Пример #18
0
 /**
  * Loads a YAML file.
  *
  * @param string $file
  *
  * @return array The file content
  *
  * @throws InvalidArgumentException
  *   When the given file is not a local file or when it does not exist.
  */
 protected function loadFile($file)
 {
     if (!stream_is_local($file)) {
         throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
     }
     if (!file_exists($file)) {
         throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
     }
     return $this->validate(Yaml::decode(file_get_contents($file)), $file);
 }
Пример #19
0
 protected function read($name)
 {
     $data = file_get_contents($this->storage->getFilePath($name));
     return Yaml::decode($data);
 }
<?php

/**
 * @file
 * Contains database additions to drupal-8.bare.standard.php.gz for testing the
 * upgrade path of https://www.drupal.org/node/507488.
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
// Structure of a custom block with visibility settings.
$block_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/block.block.testfor2569529.yml'));
foreach ($block_configs as $block_config) {
    $connection->insert('config')->fields(['collection', 'name', 'data'])->values(['collection' => '', 'name' => 'block.block.' . $block_config['id'], 'data' => serialize($block_config)])->execute();
}
// Update the config entity query "index".
$existing_blocks = $connection->select('key_value')->fields('key_value', ['value'])->condition('collection', 'config.entity.key_store.block')->condition('name', 'theme:seven')->execute()->fetchField();
$existing_blocks = unserialize($existing_blocks);
$connection->update('key_value')->fields(['value' => serialize(array_merge($existing_blocks, ['block.block.seven_secondary_local_tasks']))])->condition('collection', 'config.entity.key_store.block')->condition('name', 'theme:seven')->execute();
/**
 * @file
 * Contains database additions to drupal-8.bare.standard.php.gz for testing the
 * upgrade path of https://www.drupal.org/node/2429191.
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
use Drupal\field\Entity\FieldStorageConfig;
$connection = Database::getConnection();
// Configuration for a View with an "entity_reference selection" display.
$config = Yaml::decode(file_get_contents(__DIR__ . '/views.view.entity_reference_plugins_2429191.yml'));
$connection->insert('config')->fields(['collection', 'name', 'data'])->values(['collection' => '', 'name' => 'views.view.' . $config['id'], 'data' => serialize($config)])->execute();
// Configuration for an entity_reference field storage using the View for
// selection.
$field_ref_views_select_2429191 = Yaml::decode(file_get_contents(__DIR__ . '/field.storage.node.field_ref_views_select_2429191.yml'));
// Configuration for an entity_reference field storage using the auto-create
// feature.
$field_ref_autocreate_2412569 = Yaml::decode(file_get_contents(__DIR__ . '/field.storage.node.field_ref_autocreate_2412569.yml'));
$connection->insert('config')->fields(['collection', 'name', 'data'])->values(['collection' => '', 'name' => 'field.storage.' . $field_ref_views_select_2429191['id'], 'data' => serialize($field_ref_views_select_2429191)])->values(['collection' => '', 'name' => 'field.storage.' . $field_ref_autocreate_2412569['id'], 'data' => serialize($field_ref_autocreate_2412569)])->execute();
// We need to Update the registry of "last installed" field definitions.
$installed = $connection->select('key_value')->fields('key_value', ['value'])->condition('collection', 'entity.definitions.installed')->condition('name', 'node.field_storage_definitions')->execute()->fetchField();
$installed = unserialize($installed);
$installed['field_ref_views_select_2429191'] = new FieldStorageConfig($field_ref_views_select_2429191);
$installed['field_ref_autocreate_2412569'] = new FieldStorageConfig($field_ref_autocreate_2412569);
$connection->update('key_value')->condition('collection', 'entity.definitions.installed')->condition('name', 'node.field_storage_definitions')->fields(['value' => serialize($installed)])->execute();
// Configuration for an entity_reference field using the View for selection.
$field_ref_views_select_2429191 = Yaml::decode(file_get_contents(__DIR__ . '/field.field.node.article.field_ref_views_select_2429191.yml'));
// Configuration for an entity_reference field using the auto-create feature.
$field_ref_autocreate_2412569 = Yaml::decode(file_get_contents(__DIR__ . '/field.field.node.article.field_ref_autocreate_2412569.yml'));
$connection->insert('config')->fields(['collection', 'name', 'data'])->values(['collection' => '', 'name' => 'field.field.' . $field_ref_views_select_2429191['id'], 'data' => serialize($field_ref_views_select_2429191)])->values(['collection' => '', 'name' => 'field.field.' . $field_ref_autocreate_2412569['id'], 'data' => serialize($field_ref_autocreate_2412569)])->execute();
Пример #22
0
<?php

/**
 * @file
 * Test fixture.
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
$connection->insert('config')->fields(array('collection' => '', 'name' => 'views.view.test_boolean_filter_values', 'data' => serialize(Yaml::decode(file_get_contents('core/modules/views/tests/fixtures/update/views.view.test_boolean_filter_values.yml')))))->execute();
Пример #23
0
<?php

/**
 * @file
 * Test fixture.
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
$connection->insert('config')->fields(array('collection' => '', 'name' => 'views.view.test_duplicate_field_handlers', 'data' => serialize(Yaml::decode(file_get_contents('core/modules/views/tests/modules/views_test_config/test_views/views.view.test_duplicate_field_handlers.yml')))))->execute();
<?php

/**
 * @file
 * Contains database additions to drupal-8.bare.standard.php.gz for testing the
 * upgrade path of rest_post_update_resource_granularity().
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
// Set the schema version.
$connection->insert('key_value')->fields(['collection' => 'system.schema', 'name' => 'rest', 'value' => 'i:8201;'])->fields(['collection' => 'system.schema', 'name' => 'serialization', 'value' => 'i:8201;'])->execute();
// Update core.extension.
$extensions = $connection->select('config')->fields('config', ['data'])->condition('collection', '')->condition('name', 'core.extension')->execute()->fetchField();
$extensions = unserialize($extensions);
$extensions['module']['rest'] = 8201;
$extensions['module']['serialization'] = 8201;
$connection->update('config')->fields(['data' => serialize($extensions)])->condition('collection', '')->condition('name', 'core.extension')->execute();
$connection->merge('key_value')->condition('collection', 'entity.definitions.installed')->condition('name', 'rest_resource_config.entity_type')->fields(['value' => 'O:42:"Drupal\\Core\\Config\\Entity\\ConfigEntityType":39:{s:16:"*config_prefix";s:8:"resource";s:15:"*static_cache";b:0;s:14:"*lookup_keys";a:1:{i:0;s:4:"uuid";}s:16:"*config_export";a:4:{i:0;s:2:"id";i:1;s:9:"plugin_id";i:2;s:11:"granularity";i:3;s:13:"configuration";}s:21:"*mergedConfigExport";a:0:{}s:15:"*render_cache";b:1;s:19:"*persistent_cache";b:1;s:14:"*entity_keys";a:6:{s:2:"id";s:2:"id";s:8:"revision";s:0:"";s:6:"bundle";s:0:"";s:8:"langcode";s:8:"langcode";s:16:"default_langcode";s:16:"default_langcode";s:4:"uuid";s:4:"uuid";}s:5:"*id";s:20:"rest_resource_config";s:11:"*provider";s:4:"rest";s:8:"*class";s:37:"Drupal\\rest\\Entity\\RestResourceConfig";s:16:"*originalClass";N;s:11:"*handlers";a:2:{s:6:"access";s:45:"Drupal\\Core\\Entity\\EntityAccessControlHandler";s:7:"storage";s:45:"Drupal\\Core\\Config\\Entity\\ConfigEntityStorage";}s:19:"*admin_permission";s:25:"administer rest resources";s:25:"*permission_granularity";s:11:"entity_type";s:8:"*links";a:0:{}s:17:"*label_callback";s:18:"getLabelFromPlugin";s:21:"*bundle_entity_type";N;s:12:"*bundle_of";N;s:15:"*bundle_label";N;s:13:"*base_table";N;s:22:"*revision_data_table";N;s:17:"*revision_table";N;s:13:"*data_table";N;s:15:"*translatable";b:0;s:8:"*label";O:48:"Drupal\\Core\\StringTranslation\\TranslatableMarkup":3:{s:9:"*string";s:20:"REST resource config";s:12:"*arguments";a:0:{}s:10:"*options";a:0:{}}s:17:"*label_singular";s:0:"";s:15:"*label_plural";s:0:"";s:14:"*label_count";a:0:{}s:15:"*uri_callback";N;s:8:"*group";s:13:"configuration";s:14:"*group_label";O:48:"Drupal\\Core\\StringTranslation\\TranslatableMarkup":3:{s:9:"*string";s:13:"Configuration";s:12:"*arguments";a:0:{}s:10:"*options";a:1:{s:7:"context";s:17:"Entity type group";}}s:22:"*field_ui_base_route";N;s:26:"*common_reference_target";b:0;s:22:"*list_cache_contexts";a:0:{}s:18:"*list_cache_tags";a:1:{i:0;s:32:"config:rest_resource_config_list";}s:14:"*constraints";a:0:{}s:13:"*additional";a:0:{}s:20:"*stringTranslation";N;}', 'name' => 'rest_resource_config.entity_type', 'collection' => 'entity.definitions.installed'])->execute();
$connection->merge('key_value')->condition('collection', 'post_update')->condition('name', 'existing_updates')->fields(['value' => 'a:13:{i:0;s:64:"system_post_update_recalculate_configuration_entity_dependencies";i:1;s:50:"field_post_update_entity_reference_handler_setting";i:2;s:46:"field_post_update_save_custom_storage_property";i:3;s:54:"block_post_update_disable_blocks_with_missing_contexts";i:4;s:46:"views_post_update_cleanup_duplicate_views_data";i:5;s:46:"views_post_update_update_cacheability_metadata";i:6;s:43:"field_post_update_email_widget_size_setting";i:7;s:42:"image_post_update_image_style_dependencies";i:8;s:42:"views_post_update_image_style_dependencies";i:9;s:46:"views_post_update_field_formatter_dependencies";i:10;s:41:"views_post_update_serializer_dependencies";i:11;s:36:"views_post_update_taxonomy_index_tid";i:12;s:53:"rest_post_update_create_rest_resource_config_entities";}', 'name' => 'existing_updates', 'collection' => 'post_update'])->execute();
$connection->insert('config')->fields(['collection', 'name', 'data'])->values(['collection' => '', 'name' => 'rest.resource.entity.node', 'data' => serialize(Yaml::decode(file_get_contents(__DIR__ . '/rest.resource.entity.node_2721595.yml')))])->values(['collection' => '', 'name' => 'rest.resource.entity.comment', 'data' => serialize(Yaml::decode(file_get_contents(__DIR__ . '/rest.resource.entity.comment_2721595.yml')))])->values(['collection' => '', 'name' => 'rest.resource.entity.user', 'data' => serialize(Yaml::decode(file_get_contents(__DIR__ . '/rest.resource.entity.user_2721595.yml')))])->execute();
<?php

/**
 * @file
 * Contains database additions to drupal-8.bare.standard.php.gz for testing the
 * upgrade path of https://www.drupal.org/node/2354889.
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
// A custom block with visibility settings.
$block_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/block.block.testfor2354889.yml'));
// A custom block without any visibility settings.
$block_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/block.block.secondtestfor2354889.yml'));
// A custom block with visibility settings that contain a non-existing context
// mapping.
$block_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/block.block.thirdtestfor2354889.yml'));
foreach ($block_configs as $block_config) {
    $connection->insert('config')->fields(array('collection', 'name', 'data'))->values(array('collection' => '', 'name' => 'block.block.' . $block_config['id'], 'data' => serialize($block_config)))->execute();
}
// Update the config entity query "index".
$existing_blocks = $connection->select('key_value')->fields('key_value', ['value'])->condition('collection', 'config.entity.key_store.block')->condition('name', 'theme:bartik')->execute()->fetchField();
$existing_blocks = unserialize($existing_blocks);
$connection->update('key_value')->fields(['value' => serialize(array_merge($existing_blocks, ['block.block.testfor2354889', 'block.block.secondtestfor2354889', 'block.block.thirdtestfor2354889']))])->condition('collection', 'config.entity.key_store.block')->condition('name', 'theme:bartik')->execute();
<?php

/**
 * @file
 * Contains database additions to drupal-8-rc1.bare.standard.php.gz for testing
 * the upgrade path of https://www.drupal.org/node/2649914.
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
$views_config = Yaml::decode(file_get_contents(__DIR__ . '/drupal8.views-image-style-dependency-2649914.yml'));
$connection->insert('config')->fields(['collection', 'name', 'data'])->values(['collection' => '', 'name' => 'views.view.' . $views_config['id'], 'data' => serialize($views_config)])->execute();
Пример #27
0
 /**
  * Changes parameters in the services.yml file.
  *
  * @param string $name
  *   The name of the parameter.
  * @param mixed $value
  *   The value of the parameter.
  */
 protected function setContainerParameter($name, $value)
 {
     $filename = $this->siteDirectory . '/services.yml';
     chmod($filename, 0666);
     $services = Yaml::decode(file_get_contents($filename));
     $services['parameters'][$name] = $value;
     file_put_contents($filename, Yaml::encode($services));
     // Ensure that the cache is deleted for the yaml file loader.
     $file_cache = FileCacheFactory::get('container_yaml_loader');
     $file_cache->delete($filename);
 }
Пример #28
0
 /**
  * Downloads a tarball of the site configuration.
  */
 public function downloadExport()
 {
     file_unmanaged_delete(file_directory_temp() . '/config.tar.gz');
     $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz');
     // Get raw configuration data without overrides.
     foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
         $archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData()));
     }
     // Get all override data from the remaining collections.
     foreach ($this->targetStorage->getAllCollectionNames() as $collection) {
         $collection_storage = $this->targetStorage->createCollection($collection);
         foreach ($collection_storage->listAll() as $name) {
             $archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name)));
         }
     }
     $request = new Request(array('file' => 'config.tar.gz'));
     return $this->fileDownloadController->download($request, 'temporary');
 }