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');
37 if ($this->moduleExists('profile')) {
38 $fields += $this->select('profile_fields', 'pf')
39 ->fields('pf', ['name', 'title'])
50 public function prepareRow(Row $row) {
52 $roles = $this->select('users_roles', 'ur')
53 ->fields('ur', ['rid'])
54 ->condition('ur.uid', $row->getSourceProperty('uid'))
57 $row->setSourceProperty('roles', $roles);
59 // We are adding here the Event contributed module column.
60 // @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
61 if ($row->hasSourceProperty('timezone_id') && $row->getSourceProperty('timezone_id')) {
62 if ($this->getDatabase()->schema()->tableExists('event_timezones')) {
63 $event_timezone = $this->select('event_timezones', 'e')
64 ->fields('e', ['name'])
65 ->condition('e.timezone', $row->getSourceProperty('timezone_id'))
68 if ($event_timezone) {
69 $row->setSourceProperty('event_timezone', $event_timezone);
75 $row->setSourceProperty('data', unserialize($row->getSourceProperty('data')));
77 return parent::prepareRow($row);
83 public function getIds() {
93 * Returns the user base fields to be migrated.
96 * Associative array having field name as key and description as value.
98 protected function baseFields() {
100 'uid' => $this->t('User ID'),
101 'name' => $this->t('Username'),
102 'pass' => $this->t('Password'),
103 'mail' => $this->t('Email address'),
104 'theme' => $this->t('Theme'),
105 'signature' => $this->t('Signature'),
106 'signature_format' => $this->t('Signature format'),
107 'created' => $this->t('Registered timestamp'),
108 'access' => $this->t('Last access timestamp'),
109 'login' => $this->t('Last login timestamp'),
110 'status' => $this->t('Status'),
111 'timezone' => $this->t('Timezone'),
112 'language' => $this->t('Language'),
113 'picture' => $this->t('Picture'),
114 'init' => $this->t('Init'),
115 'data' => $this->t('User data'),
118 // Possible field added by Date contributed module.
119 // @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
120 if ($this->getDatabase()->schema()->fieldExists('users', 'timezone_name')) {
121 $fields['timezone_name'] = $this->t('Timezone (Date)');
124 // Possible field added by Event contributed module.
125 // @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
126 if ($this->getDatabase()->schema()->fieldExists('users', 'timezone_id')) {
127 $fields['timezone_id'] = $this->t('Timezone (Event)');