7950991a8fb7453a65b56543fa4d31c61c04f80f
[yaffs-website] / web / core / modules / user / src / Plugin / migrate / source / d7 / Role.php
1 <?php
2
3 namespace Drupal\user\Plugin\migrate\source\d7;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Drupal 7 role source from database.
10  *
11  * @MigrateSource(
12  *   id = "d7_user_role",
13  *   source_module = "user"
14  * )
15  */
16 class Role extends DrupalSqlBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     return $this->select('role', 'r')->fields('r');
23   }
24
25   /**
26    * {@inheritdoc}
27    */
28   public function fields() {
29     return [
30       'rid' => $this->t('Role ID.'),
31       'name' => $this->t('The name of the user role.'),
32       'weight' => $this->t('The weight of the role.'),
33     ];
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function prepareRow(Row $row) {
40     $permissions = $this->select('role_permission', 'rp')
41       ->fields('rp', ['permission'])
42       ->condition('rid', $row->getSourceProperty('rid'))
43       ->execute()
44       ->fetchCol();
45     $row->setSourceProperty('permissions', $permissions);
46
47     return parent::prepareRow($row);
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public function getIds() {
54     $ids['rid']['type'] = 'integer';
55     return $ids;
56   }
57
58 }