Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / user / src / Plugin / migrate / source / d6 / Role.php
1 <?php
2
3 namespace Drupal\user\Plugin\migrate\source\d6;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Drupal 6 role source from database.
10  *
11  * @MigrateSource(
12  *   id = "d6_user_role",
13  *   source_module = "user"
14  * )
15  */
16 class Role extends DrupalSqlBase {
17
18   /**
19    * List of filter IDs per role IDs.
20    *
21    * @var array
22    */
23   protected $filterPermissions = [];
24
25   /**
26    * {@inheritdoc}
27    */
28   public function query() {
29     $query = $this->select('role', 'r')
30       ->fields('r', ['rid', 'name'])
31       ->orderBy('r.rid');
32     return $query;
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public function fields() {
39     return [
40       'rid' => $this->t('Role ID.'),
41       'name' => $this->t('The name of the user role.'),
42     ];
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   protected function initializeIterator() {
49     $filter_roles = $this->select('filter_formats', 'f')
50       ->fields('f', ['format', 'roles'])
51       ->execute()
52       ->fetchAllKeyed();
53     foreach ($filter_roles as $format => $roles) {
54       // Drupal 6 code: $roles = ','. implode(',', $roles) .',';
55       // Remove the beginning and ending comma.
56       foreach (explode(',', trim($roles, ',')) as $rid) {
57         $this->filterPermissions[$rid][] = $format;
58       }
59     }
60     return parent::initializeIterator();
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function prepareRow(Row $row) {
67     $rid = $row->getSourceProperty('rid');
68     $permissions = $this->select('permission', 'p')
69       ->fields('p', ['perm'])
70       ->condition('rid', $rid)
71       ->execute()
72       ->fetchField();
73
74     // If a role has no permissions then set to an empty array. The role will
75     // be migrated and given the default D8 permissions.
76     if ($permissions) {
77       $row->setSourceProperty('permissions', explode(', ', $permissions));
78     }
79     else {
80       $row->setSourceProperty('permissions', []);
81     }
82     if (isset($this->filterPermissions[$rid])) {
83       $row->setSourceProperty("filter_permissions:$rid", $this->filterPermissions[$rid]);
84     }
85     return parent::prepareRow($row);
86   }
87
88   /**
89    * {@inheritdoc}
90    */
91   public function getIds() {
92     $ids['rid']['type'] = 'integer';
93     return $ids;
94   }
95
96 }