86a36ee3625d73f21b954dc776143fabe9750cd7
[yaffs-website] / web / modules / contrib / eu_cookie_compliance / tests / fixtures / update / drupal-8.user-role-manager-2774143.php
1 <?php
2
3 /**
4  * @file
5  * Contains database additions to drupal-8.eu-cookie-compliance-beta5.minimal.php.gz
6  * for testing the upgrade path of https://www.drupal.org/node/2774143.
7  */
8
9 use Drupal\Component\Serialization\Yaml;
10 use Drupal\Core\Database\Database;
11
12 $connection = Database::getConnection();
13
14 // A custom role with 'administer EU Cookie Compliance popup' permissions.
15 $role_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/user.role.testfor2774143.yml'));
16
17 // A custom role with 'display EU Cookie Compliance popup' permissions.
18 $role_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/user.role.secondtestfor2774143.yml'));
19
20 foreach ($role_configs as $role_config) {
21   $connection->insert('config')
22     ->fields(array(
23       'collection',
24       'name',
25       'data',
26     ))
27     ->values(array(
28       'collection' => '',
29       'name' => 'user.role.' . $role_config['id'],
30       'data' => serialize($role_config),
31     ))
32     ->execute();
33 }
34
35 // Update the config entity query "index".
36 $existing_roles = $connection->select('key_value')
37   ->fields('key_value', ['value'])
38   ->condition('collection', 'config.entity.key_store.user_role')
39   ->execute()
40   ->fetchField();
41 $existing_roles = unserialize($existing_roles);
42
43 $connection->update('key_value')
44   ->fields([
45     'value' => serialize(array_merge($existing_roles, ['user.role.testfor2774143', 'user.role.secondtestfor2774143']))
46   ])
47   ->condition('collection', 'config.entity.key_store.user_role')
48   ->condition('name', 'theme:bartik')
49   ->execute();