Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / user / src / Plugin / migrate / source / d6 / User.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 user source from database.
10  *
11  * @MigrateSource(
12  *   id = "d6_user",
13  *   source_module = "user"
14  * )
15  */
16 class User extends DrupalSqlBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     return $this->select('users', 'u')
23       ->fields('u', array_keys($this->baseFields()))
24       ->condition('u.uid', 0, '>');
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function fields() {
31     $fields = $this->baseFields();
32
33     // Add roles field.
34     $fields['roles'] = $this->t('Roles');
35
36     // Profile fields.
37     if ($this->moduleExists('profile')) {
38       $fields += $this->select('profile_fields', 'pf')
39         ->fields('pf', ['name', 'title'])
40         ->execute()
41         ->fetchAllKeyed();
42     }
43
44     return $fields;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function prepareRow(Row $row) {
51     // User roles.
52     $roles = $this->select('users_roles', 'ur')
53       ->fields('ur', ['rid'])
54       ->condition('ur.uid', $row->getSourceProperty('uid'))
55       ->execute()
56       ->fetchCol();
57     $row->setSourceProperty('roles', $roles);
58
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'))
66           ->execute()
67           ->fetchField();
68         if ($event_timezone) {
69           $row->setSourceProperty('event_timezone', $event_timezone);
70         }
71       }
72     }
73
74     // Unserialize Data.
75     $row->setSourceProperty('data', unserialize($row->getSourceProperty('data')));
76
77     return parent::prepareRow($row);
78   }
79
80   /**
81    * {@inheritdoc}
82    */
83   public function getIds() {
84     return [
85       'uid' => [
86         'type' => 'integer',
87         'alias' => 'u',
88       ],
89     ];
90   }
91
92   /**
93    * Returns the user base fields to be migrated.
94    *
95    * @return array
96    *   Associative array having field name as key and description as value.
97    */
98   protected function baseFields() {
99     $fields = [
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'),
116     ];
117
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)');
122     }
123
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)');
128     }
129
130     return $fields;
131   }
132
133 }