Role.php 1.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<?php

namespace Drupal\user\Plugin\migrate\source\d7;

use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

/**
 * Drupal 7 role source from database.
 *
 * @MigrateSource(
 *   id = "d7_user_role"
 * )
 */
class Role extends DrupalSqlBase {

  /**
   * {@inheritdoc}
   */
  public function query() {
    return $this->select('role', 'r')->fields('r');
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    return array(
      'rid' => $this->t('Role ID.'),
      'name' => $this->t('The name of the user role.'),
      'weight' => $this->t('The weight of the role.'),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    $permissions = $this->select('role_permission', 'rp')
      ->fields('rp', ['permission'])
      ->condition('rid', $row->getSourceProperty('rid'))
      ->execute()
      ->fetchCol();
    $row->setSourceProperty('permissions', $permissions);

    return parent::prepareRow($row);
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids['rid']['type'] = 'integer';
    return $ids;
  }

}