ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\User\Setup\UserProfileMigrations Class Reference
+ Inheritance diagram for ILIAS\User\Setup\UserProfileMigrations:
+ Collaboration diagram for ILIAS\User\Setup\UserProfileMigrations:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 
 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 

Private Member Functions

 migrateCustomFieldAccess ()
 
 migrateStandardFieldConfig ()
 
 updateCountryField (array $property_attributes)
 
 fetchConfigValuesFromSettings (string $field_id, array $attributes)
 
 retrievePropertyAttributeValue (string $field_id, string $attribute)
 
 insertConfig (string $field_id, int $visible_in_registration, int $visible_to_user, int $visible_in_lua, int $visible_in_crss, int $visible_in_grps, int $visible_in_prgs, int $changeable_by_user, int $changeable_in_lua, int $required, int $export, int $searchable, int $available_in_certs)
 

Private Attributes

const string MIGRATION_COMPLETED = 'usr_profile_migration_completed'
 
ilDBInterface $db
 
ilSetting $settings
 
AdminInteraction $admin_interaction
 

Additional Inherited Members

- Data Fields inherited from ILIAS\Setup\Migration
const INFINITE = -1
 

Detailed Description

Definition at line 28 of file UserProfileMigrations.php.

Member Function Documentation

◆ fetchConfigValuesFromSettings()

ILIAS\User\Setup\UserProfileMigrations::fetchConfigValuesFromSettings ( string  $field_id,
array  $attributes 
)
private

Definition at line 272 of file UserProfileMigrations.php.

275 : array {
276 return array_map(
277 function (string $v) use ($field_id): bool {
278 if ($field_id === 'username' && $v === 'usr_settings_disable') {
279 return $this->settings->get('allow_change_loginname', '0') === '1';
280 }
281 $value = $this->retrievePropertyAttributeValue($field_id, $v);
282 if (in_array($v, ['usr_settings_hide', 'usr_settings_disable'])) {
283 return !$value;
284 }
285 return $value;
286 },
287 $attributes
288 );
289 }
retrievePropertyAttributeValue(string $field_id, string $attribute)

References ILIAS\Repository\settings().

Referenced by ILIAS\User\Setup\UserProfileMigrations\migrateStandardFieldConfig(), and ILIAS\User\Setup\UserProfileMigrations\updateCountryField().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ILIAS\User\Setup\UserProfileMigrations::getDefaultAmountOfStepsPerRun ( )

Tell the default amount of steps to be executed for one run of the migration.

Return Migration::INFINITE if all units should be migrated at once.

Implements ILIAS\Setup\Migration.

Definition at line 40 of file UserProfileMigrations.php.

40 : int
41 {
42 return 1;
43 }

◆ getLabel()

ILIAS\User\Setup\UserProfileMigrations::getLabel ( )
Returns
string - a meaningful and concise description for your migration.

Implements ILIAS\Setup\Migration.

Definition at line 35 of file UserProfileMigrations.php.

35 : string
36 {
37 return 'Clean-Up and Consolidate User Profile Fields';
38 }

◆ getPreconditions()

ILIAS\User\Setup\UserProfileMigrations::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 45 of file UserProfileMigrations.php.

45 : array
46 {
47 return [
48 new \ilDatabaseInitializedObjective(),
49 new \ilSettingsFactoryExistsObjective(),
50 new \ilDatabaseUpdatedObjective()
51 ];
52 }

◆ getRemainingAmountOfSteps()

ILIAS\User\Setup\UserProfileMigrations::getRemainingAmountOfSteps ( )

Count up how many "things" need to be migrated.

This helps the admin to decide how big he can create the steps and also how long a migration takes

Implements ILIAS\Setup\Migration.

Definition at line 68 of file UserProfileMigrations.php.

68 : int
69 {
70 return $this->settings->get(self::MIGRATION_COMPLETED) === '1' ? 0 : 1;
71 }

References ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ insertConfig()

ILIAS\User\Setup\UserProfileMigrations::insertConfig ( string  $field_id,
int  $visible_in_registration,
int  $visible_to_user,
int  $visible_in_lua,
int  $visible_in_crss,
int  $visible_in_grps,
int  $visible_in_prgs,
int  $changeable_by_user,
int  $changeable_in_lua,
int  $required,
int  $export,
int  $searchable,
int  $available_in_certs 
)
private

Definition at line 296 of file UserProfileMigrations.php.

310 : void {
311 if ($this->db->fetchAll(
312 $this->db->query(
313 "SELECT count(field_id) as cnt FROM usr_field_config WHERE field_id='{$field_id}'"
314 ),
316 )[0]->cnt !== 0) {
317 return;
318 }
319 $this->db->insert(
320 'usr_field_config',
321 [
322 'field_id' => [
324 $field_id
325 ],
326 'visible_in_registration' => [
328 $visible_in_registration
329 ],
330 'visible_to_user' => [
332 $visible_to_user
333 ],
334 'visible_in_lua' => [
336 $visible_in_lua
337 ],
338 'visible_in_crss' => [
340 $visible_in_crss
341 ],
342 'visible_in_grps' => [
344 $visible_in_grps
345 ],
346 'visible_in_prgs' => [
348 $visible_in_prgs
349 ],
350 'changeable_by_user' => [
352 $changeable_by_user
353 ],
354 'changeable_in_lua' => [
356 $changeable_in_lua
357 ],
358 'required' => [
360 $required
361 ],
362 'export' => [
364 $export
365 ],
366 'searchable' => [
368 $searchable
369 ],
370 'available_in_certs' => [
372 $available_in_certs
373 ]
374 ]
375 );
376 }

Referenced by ILIAS\User\Setup\UserProfileMigrations\migrateCustomFieldAccess(), ILIAS\User\Setup\UserProfileMigrations\migrateStandardFieldConfig(), and ILIAS\User\Setup\UserProfileMigrations\updateCountryField().

+ Here is the caller graph for this function:

◆ migrateCustomFieldAccess()

ILIAS\User\Setup\UserProfileMigrations::migrateCustomFieldAccess ( )
private

Definition at line 73 of file UserProfileMigrations.php.

73 : void
74 {
75 if (!$this->db->tableColumnExists('udf_definition', 'prg_export')) {
76 return;
77 }
78
79 $custom_fields_query = $this->db->query('SELECT * FROM udf_definition');
80
81 while (($row = $this->db->fetchObject($custom_fields_query))) {
82 $this->insertConfig(
83 $row->field_id,
84 $row->registration_visible,
85 $row->visible,
86 $row->visible_lua,
87 $row->course_export,
88 $row->group_export,
89 $row->prg_export,
90 $row->changeable,
91 $row->changeable_lua,
92 $row->required,
93 $row->export,
94 $row->searchable,
95 $row->certificate
96 );
97 }
98 $this->db->dropTableColumn(
99 'udf_definition',
100 'visible'
101 );
102 $this->db->dropTableColumn(
103 'udf_definition',
104 'changeable'
105 );
106 $this->db->dropTableColumn(
107 'udf_definition',
108 'required'
109 );
110 $this->db->dropTableColumn(
111 'udf_definition',
112 'searchable'
113 );
114 $this->db->dropTableColumn(
115 'udf_definition',
116 'export'
117 );
118 $this->db->dropTableColumn(
119 'udf_definition',
120 'course_export'
121 );
122 $this->db->dropTableColumn(
123 'udf_definition',
124 'registration_visible'
125 );
126 $this->db->dropTableColumn(
127 'udf_definition',
128 'visible_lua'
129 );
130 $this->db->dropTableColumn(
131 'udf_definition',
132 'changeable_lua'
133 );
134 $this->db->dropTableColumn(
135 'udf_definition',
136 'group_export'
137 );
138 $this->db->dropTableColumn(
139 'udf_definition',
140 'certificate'
141 );
142 $this->db->dropTableColumn(
143 'udf_definition',
144 'prg_export'
145 );
146 }
insertConfig(string $field_id, int $visible_in_registration, int $visible_to_user, int $visible_in_lua, int $visible_in_crss, int $visible_in_grps, int $visible_in_prgs, int $changeable_by_user, int $changeable_in_lua, int $required, int $export, int $searchable, int $available_in_certs)

References ILIAS\User\Setup\UserProfileMigrations\insertConfig().

Referenced by ILIAS\User\Setup\UserProfileMigrations\step().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ migrateStandardFieldConfig()

ILIAS\User\Setup\UserProfileMigrations::migrateStandardFieldConfig ( )
private

Definition at line 148 of file UserProfileMigrations.php.

148 : void
149 {
150 $field_ids = [
151 'username',
152 'firstname',
153 'lastname',
154 'title',
155 'birthday',
156 'gender',
157 'avatar',
158 'roles',
159 'org_units',
160 'interests_general' ,
161 'interests_help_offered',
162 'interests_help_looking',
163 'institution',
164 'department',
165 'street',
166 'zipcode',
167 'city',
168 'country',
169 'phone_office',
170 'phone_home',
171 'phone_mobile',
172 'fax',
173 'email',
174 'second_email',
175 'hobby',
176 'referral_comment',
177 'matriculation',
178 'awrn_user_show',
179 'allow_contact_request',
180 'incoming_mail',
181 'language',
182 'skin_style',
183 'session_reminder'
184 ];
185
186 $property_attributes = [
187 'usr_settings_visib_reg',
188 'usr_settings_hide',
189 'usr_settings_visib_lua',
190 'usr_settings_course_export',
191 'usr_settings_group_export',
192 'usr_settings_prg_export',
193 'usr_settings_disable',
194 'usr_settings_changeable_lua',
195 'require',
196 'usr_settings_export',
197 'search_enabled',
198 'certificate',
199 ];
200
201 $this->updateCountryField($property_attributes);
202 foreach ($field_ids as $field_id) {
203 $this->insertConfig(
204 $field_id,
205 ...$this->fetchConfigValuesFromSettings($field_id, $property_attributes)
206 );
207
208 foreach ($property_attributes as $attribute) {
209 $this->settings->delete("{$attribute}_{$field_id}");
210 }
211 }
212 }
updateCountryField(array $property_attributes)
fetchConfigValuesFromSettings(string $field_id, array $attributes)

References ILIAS\User\Setup\UserProfileMigrations\fetchConfigValuesFromSettings(), ILIAS\User\Setup\UserProfileMigrations\insertConfig(), ILIAS\Repository\settings(), and ILIAS\User\Setup\UserProfileMigrations\updateCountryField().

Referenced by ILIAS\User\Setup\UserProfileMigrations\step().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepare()

ILIAS\User\Setup\UserProfileMigrations::prepare ( Environment  $environment)

Prepare the migration by means of some environment.

This is not supposed to modify the environment, but will be run to prime the migration object to run step and getRemainingAmountOfSteps afterwards.

Implements ILIAS\Setup\Migration.

Definition at line 54 of file UserProfileMigrations.php.

54 : void
55 {
56 $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
57 $this->settings = $environment->getResource(Environment::RESOURCE_SETTINGS_FACTORY)->settingsFor();
58 $this->admin_interaction = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
59 }

References ILIAS\Setup\Environment\getResource(), ILIAS\Setup\Environment\RESOURCE_ADMIN_INTERACTION, ILIAS\Setup\Environment\RESOURCE_DATABASE, ILIAS\Setup\Environment\RESOURCE_SETTINGS_FACTORY, and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ retrievePropertyAttributeValue()

ILIAS\User\Setup\UserProfileMigrations::retrievePropertyAttributeValue ( string  $field_id,
string  $attribute 
)
private

Definition at line 291 of file UserProfileMigrations.php.

291 : bool
292 {
293 return $this->settings->get("{$attribute}_{$field_id}", '0') === '1';
294 }

References ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ step()

ILIAS\User\Setup\UserProfileMigrations::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 61 of file UserProfileMigrations.php.

61 : void
62 {
65 $this->settings->set(self::MIGRATION_COMPLETED, '1');
66 }

References ILIAS\User\Setup\UserProfileMigrations\migrateCustomFieldAccess(), ILIAS\User\Setup\UserProfileMigrations\migrateStandardFieldConfig(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ updateCountryField()

ILIAS\User\Setup\UserProfileMigrations::updateCountryField ( array  $property_attributes)
private

Definition at line 214 of file UserProfileMigrations.php.

214 : void
215 {
216 $message = 'ILIAS up to now knows two types of country information: One selectable by a dropdown '
217 . 'the other one as a text field. The latter one will be removed. Would you like us to move '
218 . 'the current information in the text field to a custom field with the name "Country"? If you '
219 . 'choose to not move the information it will simply be deleted.';
220
221 if ($this->admin_interaction->confirmOrDeny($message)) {
222 $uuid = (new UUIDFactory())->uuid4AsString();
223 $this->db->insert(
224 'udf_definition',
225 [
226 'field_id' => [
228 $uuid
229 ],
230 'field_name' => [
232 'Country'
233 ],
234 'field_type' => [
236 Text::class
237 ],
238 'section' => [
240 AvailableSections::ContactData->value
241 ]
242 ]
243 );
244 $this->insertConfig(
245 $uuid,
246 ...$this->fetchConfigValuesFromSettings('old_country', $property_attributes)
247 );
248 $query = $this->db->query(
249 'SELECT usr_id, old_country FROM usr_data WHERE old_country IS NOT NULL AND NOT old_country = ""'
250 );
251
252 $insert = [];
253 while (($row = $this->db->fetchObject($query))) {
254 $insert[] = "('{$row->usr_id}', '{$uuid}', {$this->db->quote($row->old_country, \ilDBConstants::T_TEXT)})";
255 }
256
257 if ($insert === []) {
258 return;
259 }
260
261 $this->db->manipulate(
262 'INSERT INTO usr_profile_data (usr_id, field_id, value) VALUES ' . implode(',', $insert)
263 );
264 }
265
266 foreach ($property_attributes as $attribute) {
267 $this->settings->delete("{$attribute}_old_country");
268 }
269 $this->db->dropTableColumn('usr_data', 'old_country');
270 }
$message
Definition: xapiexit.php:31

References $message, ILIAS\User\Setup\UserProfileMigrations\fetchConfigValuesFromSettings(), ILIAS\User\Setup\UserProfileMigrations\insertConfig(), ILIAS\Repository\settings(), and ilDBConstants\T_TEXT.

Referenced by ILIAS\User\Setup\UserProfileMigrations\migrateStandardFieldConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $admin_interaction

AdminInteraction ILIAS\User\Setup\UserProfileMigrations::$admin_interaction
private

Definition at line 33 of file UserProfileMigrations.php.

◆ $db

ilDBInterface ILIAS\User\Setup\UserProfileMigrations::$db
private

Definition at line 31 of file UserProfileMigrations.php.

◆ $settings

ilSetting ILIAS\User\Setup\UserProfileMigrations::$settings
private

Definition at line 32 of file UserProfileMigrations.php.

◆ MIGRATION_COMPLETED

const string ILIAS\User\Setup\UserProfileMigrations::MIGRATION_COMPLETED = 'usr_profile_migration_completed'
private

Definition at line 30 of file UserProfileMigrations.php.


The documentation for this class was generated from the following file: