Passed
Push — master ( f3d2cc...62adaa )
by Julito
13:44 queued 02:57
created

Version20170627122900   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 342
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 270
c 1
b 0
f 0
dl 0
loc 342
rs 10
wmc 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
D up() 0 329 10
A down() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
use Doctrine\DBAL\Schema\Schema;
11
12
class Version20170627122900 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'settings_current changes';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $this->addSql('ALTER TABLE settings_current CHANGE access_url access_url INT DEFAULT NULL');
22
        $this->addSql("UPDATE settings_current SET selected_value = 'true' WHERE variable = 'decode_utf8'");
23
24
        // Use .env APP_ENV setting to change server type
25
        //$this->addSql("DELETE FROM settings_current WHERE variable = 'server_type'");
26
27
        $table = $schema->getTable('settings_current');
28
        if (false === $table->hasForeignKey('FK_62F79C3B9436187B')) {
29
            $this->addSql(
30
                'ALTER TABLE settings_current ADD CONSTRAINT FK_62F79C3B9436187B FOREIGN KEY (access_url) REFERENCES access_url (id);'
31
            );
32
        }
33
        $this->addSql(
34
            'ALTER TABLE settings_current CHANGE variable variable VARCHAR(190) NOT NULL, CHANGE subkey subkey VARCHAR(190) DEFAULT NULL, CHANGE selected_value selected_value LONGTEXT DEFAULT NULL;'
35
        );
36
37
        $this->addSql('ALTER TABLE settings_options CHANGE value value VARCHAR(190) DEFAULT NULL');
38
39
        $connection = $this->getEntityManager()->getConnection();
40
41
        $result = $connection
42
            ->executeQuery(
43
                "SELECT COUNT(1) FROM settings_current WHERE variable = 'exercise_invisible_in_session' AND category = 'Session'"
44
            )
45
        ;
46
        $count = $result->fetchNumeric()[0];
47
        if (empty($count)) {
48
            $this->addSql(
49
                "INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_invisible_in_session',NULL,'radio','Session','false','ExerciseInvisibleInSessionTitle','ExerciseInvisibleInSessionComment','',NULL, 1)"
50
            );
51
            $this->addSql(
52
                "INSERT INTO settings_options (variable, value, display_text) VALUES ('exercise_invisible_in_session','true','Yes')"
53
            );
54
            $this->addSql(
55
                "INSERT INTO settings_options (variable, value, display_text) VALUES ('exercise_invisible_in_session','false','No')"
56
            );
57
        }
58
59
        $result = $connection->executeQuery(
60
            "SELECT COUNT(1) FROM settings_current WHERE variable = 'configure_exercise_visibility_in_course' AND category = 'Session'"
61
        );
62
        $count = $result->fetchNumeric()[0];
63
64
        if (empty($count)) {
65
            $this->addSql(
66
                "INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('configure_exercise_visibility_in_course',NULL,'radio','Session','false','ConfigureExerciseVisibilityInCourseTitle','ConfigureExerciseVisibilityInCourseComment','',NULL, 1)"
67
            );
68
            $this->addSql(
69
                "INSERT INTO settings_options (variable, value, display_text) VALUES ('configure_exercise_visibility_in_course','true','Yes')"
70
            );
71
            $this->addSql(
72
                "INSERT INTO settings_options (variable, value, display_text) VALUES ('configure_exercise_visibility_in_course','false','No')"
73
            );
74
        }
75
76
        // Fixes missing options show_glossary_in_extra_tools
77
        $this->addSql("DELETE FROM settings_options WHERE variable = 'show_glossary_in_extra_tools'");
78
        $this->addSql(
79
            "INSERT INTO settings_options (variable, value, display_text) VALUES ('show_glossary_in_extra_tools', 'none', 'None')"
80
        );
81
        $this->addSql(
82
            "INSERT INTO settings_options (variable, value, display_text) VALUES ('show_glossary_in_extra_tools', 'exercise', 'Exercise')"
83
        );
84
        $this->addSql(
85
            "INSERT INTO settings_options (variable, value, display_text) VALUES ('show_glossary_in_extra_tools', 'lp', 'LearningPath')"
86
        );
87
        $this->addSql(
88
            "INSERT INTO settings_options (variable, value, display_text) VALUES ('show_glossary_in_extra_tools', 'exercise_and_lp', 'ExerciseAndLearningPath')"
89
        );
90
91
        // Update settings variable name
92
        $settings = [
93
            'Institution' => 'institution',
94
            'SiteName' => 'site_name',
95
            'InstitutionUrl' => 'institution_url',
96
            'registration' => 'required_profile_fields',
97
            'profile' => 'changeable_options',
98
            'timezone_value' => 'timezone',
99
            'stylesheets' => 'theme',
100
            'platformLanguage' => 'platform_language',
101
            'languagePriority1' => 'language_priority_1',
102
            'languagePriority2' => 'language_priority_2',
103
            'languagePriority3' => 'language_priority_3',
104
            'languagePriority4' => 'language_priority_4',
105
            'gradebook_score_display_coloring' => 'my_display_coloring',
106
            'document_if_file_exists_option' => 'if_file_exists_option',
107
            'ProfilingFilterAddingUsers' => 'profiling_filter_adding_users',
108
            'course_create_active_tools' => 'active_tools_on_create',
109
            'EmailAdministrator' => 'administrator_email',
110
            'administratorSurname' => 'administrator_surname',
111
            'administratorName' => 'administrator_name',
112
            'administratorTelephone' => 'administrator_phone',
113
            'registration.soap.php.decode_utf8' => 'decode_utf8',
114
            'show_toolshortcuts' => 'show_tool_shortcuts',
115
        ];
116
117
        foreach ($settings as $oldSetting => $newSetting) {
118
            $sql = "UPDATE settings_current SET variable = '{$newSetting}'
119
                    WHERE variable = '{$oldSetting}'";
120
            $this->addSql($sql);
121
        }
122
123
        // Update settings category
124
        $settings = [
125
            'cookie_warning' => 'platform',
126
            'donotlistcampus' => 'platform',
127
            'administrator_email' => 'admin',
128
            'administrator_surname' => 'admin',
129
            'administrator_name' => 'admin',
130
            'administrator_phone' => 'admin',
131
            'exercise_max_ckeditors_in_page' => 'exercise',
132
            'allow_hr_skills_management' => 'skill',
133
            'accessibility_font_resize' => 'display',
134
            'account_valid_duration' => 'profile',
135
            'allow_global_chat' => 'chat',
136
            'allow_lostpassword' => 'registration',
137
            'allow_registration' => 'registration',
138
            'allow_registration_as_teacher' => 'registration',
139
            'allow_skills_tool' => 'skill',
140
            'allow_students_to_browse_courses' => 'display',
141
            'allow_terms_conditions' => 'registration',
142
            'allow_users_to_create_courses' => 'course',
143
            'auto_detect_language_custom_pages' => 'language',
144
            'course_validation' => 'course',
145
            'course_validation_terms_and_conditions_url' => 'course',
146
            'display_categories_on_homepage' => 'display',
147
            'display_coursecode_in_courselist' => 'course',
148
            'display_teacher_in_courselist' => 'course',
149
            'drh_autosubscribe' => 'registration',
150
            'drh_page_after_login' => 'registration',
151
            'enable_help_link' => 'display',
152
            'example_material_course_creation' => 'course',
153
            'login_is_email' => 'profile',
154
            'noreply_email_address' => 'mail',
155
            'page_after_login' => 'registration',
156
            'pdf_export_watermark_by_course' => 'document',
157
            'pdf_export_watermark_enable' => 'document',
158
            'pdf_export_watermark_text' => 'document',
159
            'platform_unsubscribe_allowed' => 'registration',
160
            'send_email_to_admin_when_create_course' => 'course',
161
            'show_admin_toolbar' => 'display',
162
            'show_administrator_data' => 'display',
163
            'show_back_link_on_top_of_tree' => 'display',
164
            'show_closed_courses' => 'display',
165
            'show_email_addresses' => 'display',
166
            'show_empty_course_categories' => 'display',
167
            'show_full_skill_name_on_skill_wheel' => 'skill',
168
            'show_hot_courses' => 'display',
169
            'show_link_bug_notification' => 'display',
170
            'show_number_of_courses' => 'display',
171
            'show_teacher_data' => 'display',
172
            'showonline' => 'display',
173
            'student_autosubscribe' => 'registration',
174
            'student_page_after_login' => 'registration',
175
            'student_view_enabled' => 'course',
176
            'teacher_autosubscribe' => 'registration',
177
            'teacher_page_after_login' => 'registration',
178
            'time_limit_whosonline' => 'display',
179
            'user_selected_theme' => 'profile',
180
            'hide_global_announcements_when_not_connected' => 'announcement',
181
            'hide_home_top_when_connected' => 'display',
182
            'hide_logout_button' => 'display',
183
            'institution_address' => 'platform',
184
            'redirect_admin_to_courses_list' => 'admin',
185
            'decode_utf8' => 'webservice',
186
            'use_custom_pages' => 'platform',
187
            'allow_group_categories' => 'group',
188
            'allow_user_headings' => 'display',
189
            'default_document_quotum' => 'document',
190
            'default_forum_view' => 'forum',
191
            'default_group_quotum' => 'document',
192
            'enable_quiz_scenario' => 'exercise',
193
            'exercise_max_score' => 'exercise',
194
            'exercise_min_score' => 'exercise',
195
            'pdf_logo_header' => 'platform',
196
            'show_glossary_in_documents' => 'document',
197
            'show_glossary_in_extra_tools' => 'glossary',
198
            //'show_toolshortcuts' => '',
199
            'survey_email_sender_noreply' => 'survey',
200
            'allow_coach_feedback_exercises' => 'exercise',
201
            'sessionadmin_autosubscribe' => 'registration',
202
            'sessionadmin_page_after_login' => 'registration',
203
            'show_tutor_data' => 'display',
204
            'chamilo_database_version' => 'platform',
205
            'add_gradebook_certificates_cron_task_enabled' => 'gradebook',
206
            'icons_mode_svg' => 'display',
207
            'server_type' => 'platform',
208
            'show_official_code_whoisonline' => 'profile',
209
            'show_terms_if_profile_completed' => 'ticket',
210
            'enable_record_audio' => 'course',
211
            'add_users_by_coach' => 'session',
212
            'allow_captcha' => 'security',
213
            'allow_coach_to_edit_course_session' => 'session',
214
            'allow_delete_attendance' => 'attendance',
215
            'allow_download_documents_by_api_key' => 'webservice',
216
            'allow_email_editor' => 'editor',
217
            'allow_message_tool' => 'message',
218
            'allow_send_message_to_all_platform_users' => 'message',
219
            'allow_personal_agenda' => 'agenda',
220
            'allow_show_linkedin_url' => 'profile',
221
            'allow_show_skype_account' => 'profile',
222
            'allow_social_tool' => 'social',
223
            'allow_students_to_create_groups_in_social' => 'social',
224
            'allow_use_sub_language' => 'language',
225
            'allow_user_course_subscription_by_course_admin' => 'course',
226
            'allow_users_to_change_email_with_no_password' => 'profile',
227
            'display_groups_forum_in_general_tool' => 'forum',
228
            'documents_default_visibility_defined_in_course' => 'document',
229
            'dropbox_allow_group' => 'dropbox',
230
            'dropbox_allow_just_upload' => 'dropbox',
231
            'dropbox_allow_mailing' => 'dropbox',
232
            'dropbox_allow_overwrite' => 'dropbox',
233
            'dropbox_allow_student_to_student' => 'dropbox',
234
            'dropbox_hide_course_coach' => 'dropbox',
235
            'dropbox_hide_general_coach' => 'dropbox',
236
            'dropbox_max_filesize' => 'dropbox',
237
            'email_alert_manager_on_new_quiz' => 'exercise',
238
            'enable_webcam_clip' => 'document',
239
            'enabled_support_pixlr' => 'editor',
240
            'enabled_support_svg' => 'editor',
241
            'enabled_text2audio' => 'document',
242
            'extend_rights_for_coach' => 'session',
243
            'extend_rights_for_coach_on_survey' => 'survey',
244
            'hide_course_group_if_no_tools_available' => 'group',
245
            'hide_dltt_markup' => 'language',
246
            'if_file_exists_option' => 'document',
247
            'language_priority_1' => 'language',
248
            'language_priority_2' => 'language',
249
            'language_priority_3' => 'language',
250
            'language_priority_4' => 'language',
251
            'lp_show_reduced_report' => 'course',
252
            'message_max_upload_filesize' => 'message',
253
            'messaging_allow_send_push_notification' => 'webservice',
254
            'messaging_gdc_api_key' => 'webservice',
255
            'messaging_gdc_project_number' => 'webservice',
256
            'permanently_remove_deleted_files' => 'document',
257
            'permissions_for_new_directories' => 'document',
258
            'permissions_for_new_files' => 'document',
259
            'platform_language' => 'language',
260
            'registered' => 'platform',
261
            'show_chat_folder' => 'chat',
262
            'show_default_folders' => 'document',
263
            'show_different_course_language' => 'language',
264
            'show_documents_preview' => 'document',
265
            'show_link_ticket_notification' => 'display',
266
            'show_official_code_exercise_result_list' => 'exercise',
267
            'show_users_folders' => 'document',
268
            'split_users_upload_directory' => 'profile',
269
            'students_download_folders' => 'document',
270
            'students_export2pdf' => 'document',
271
            'tool_visible_by_default_at_creation' => 'document',
272
            'upload_extensions_blacklist' => 'document',
273
            'upload_extensions_list_type' => 'document',
274
            'upload_extensions_replace_by' => 'document',
275
            'upload_extensions_skip' => 'document',
276
            'upload_extensions_whitelist' => 'document',
277
            'use_users_timezone' => 'profile',
278
            'users_copy_files' => 'document',
279
            'timezone' => 'platform',
280
            'enable_profile_user_address_geolocalization' => 'profile',
281
            'theme' => 'platform',
282
            'exercise_hide_label' => 'exercise',
283
        ];
284
285
        foreach ($settings as $variable => $category) {
286
            $sql = "UPDATE settings_current SET category = '{$category}'
287
                    WHERE variable = '{$variable}'";
288
            $this->addSql($sql);
289
        }
290
291
        // Update settings value
292
        $settings = [
293
            'upload_extensions_whitelist' => 'htm;html;jpg;jpeg;gif;png;swf;avi;mpg;mpeg;mov;flv;doc;docx;xls;xlsx;ppt;pptx;odt;odp;ods;pdf;webm;oga;ogg;ogv;h264',
294
        ];
295
296
        foreach ($settings as $variable => $value) {
297
            $sql = "UPDATE settings_current SET selected_value = '{$value}'
298
                    WHERE variable = '{$variable}'";
299
            $this->addSql($sql);
300
        }
301
302
        $this->addSql("UPDATE settings_current SET selected_value = ''
303
                           WHERE variable = 'platform_language' AND selected_value IS NULL");
304
305
        // Delete settings
306
        $settings = [
307
            'use_session_mode',
308
            'show_toolshortcuts',
309
            'show_tabs',
310
            'display_mini_month_calendar',
311
            'number_of_upcoming_events',
312
            'facebook_description',
313
            'ldap_description',
314
            'openid_authentication',
315
            'platform_charset',
316
            'shibboleth_description',
317
            'sso_authentication',
318
            'sso_authentication_domain',
319
            'sso_authentication_auth_uri',
320
            'sso_authentication_unauth_uri',
321
            'sso_authentication_protocol',
322
            'sso_force_redirect',
323
            'activate_email_template',
324
            'sso_authentication_subclass',
325
        ];
326
327
        foreach ($settings as $setting) {
328
            $sql = "DELETE FROM settings_current WHERE variable = '{$setting}'";
329
            $this->addSql($sql);
330
        }
331
332
        $this->addSql('UPDATE settings_current SET category = LOWER(category)');
333
334
        // ticket configuration
335
        $ticketProjectUserRoles = $this->getConfigurationValue('ticket_project_user_roles');
336
337
        if ($ticketProjectUserRoles && isset($ticketProjectUserRoles['permissions'])) {
338
            $selectedValue = array_map(
339
                fn ($projectId, $roles) => "$projectId:".implode(',', $roles),
340
                array_keys($ticketProjectUserRoles['permissions']),
341
                array_values($ticketProjectUserRoles['permissions'])
342
            );
343
344
            $selectedValue = implode(PHP_EOL, $selectedValue);
345
346
            $this->addSql(
347
                "INSERT INTO settings_current (access_url, variable, category, selected_value, title, access_url_changeable, access_url_locked) VALUES (1, 'ticket_project_user_roles', 'Ticket', '$selectedValue', 'ticket_project_user_roles', 1, 1)"
348
            );
349
        }
350
    }
351
352
    public function down(Schema $schema): void
353
    {
354
    }
355
}
356