3 namespace Drupal\user\Plugin\migrate\source\d6;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Drupal 6 user source from database.
13 * source_module = "user"
16 class User extends DrupalSqlBase {
21 public function query() {
22 return $this->select('users', 'u')
23 ->fields('u', array_keys($this->baseFields()))
24 ->condition('u.uid', 0, '>');
30 public function fields() {
31 $fields = $this->baseFields();
34 $fields['roles'] = $this->t('Roles');
42 public function prepareRow(Row $row) {
44 $roles = $this->select('users_roles', 'ur')
45 ->fields('ur', ['rid'])
46 ->condition('ur.uid', $row->getSourceProperty('uid'))
49 $row->setSourceProperty('roles', $roles);
51 // We are adding here the Event contributed module column.
52 // @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
53 if ($row->hasSourceProperty('timezone_id') && $row->getSourceProperty('timezone_id')) {
54 if ($this->getDatabase()->schema()->tableExists('event_timezones')) {
55 $event_timezone = $this->select('event_timezones', 'e')
56 ->fields('e', ['name'])
57 ->condition('e.timezone', $row->getSourceProperty('timezone_id'))
60 if ($event_timezone) {
61 $row->setSourceProperty('event_timezone', $event_timezone);
67 $row->setSourceProperty('data', unserialize($row->getSourceProperty('data')));
69 return parent::prepareRow($row);
75 public function getIds() {
85 * Returns the user base fields to be migrated.
88 * Associative array having field name as key and description as value.
90 protected function baseFields() {
92 'uid' => $this->t('User ID'),
93 'name' => $this->t('Username'),
94 'pass' => $this->t('Password'),
95 'mail' => $this->t('Email address'),
96 'theme' => $this->t('Theme'),
97 'signature' => $this->t('Signature'),
98 'signature_format' => $this->t('Signature format'),
99 'created' => $this->t('Registered timestamp'),
100 'access' => $this->t('Last access timestamp'),
101 'login' => $this->t('Last login timestamp'),
102 'status' => $this->t('Status'),
103 'timezone' => $this->t('Timezone'),
104 'language' => $this->t('Language'),
105 'picture' => $this->t('Picture'),
106 'init' => $this->t('Init'),
107 'data' => $this->t('User data'),
110 // Possible field added by Date contributed module.
111 // @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
112 if ($this->getDatabase()->schema()->fieldExists('users', 'timezone_name')) {
113 $fields['timezone_name'] = $this->t('Timezone (Date)');
116 // Possible field added by Event contributed module.
117 // @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
118 if ($this->getDatabase()->schema()->fieldExists('users', 'timezone_id')) {
119 $fields['timezone_id'] = $this->t('Timezone (Event)');