Passed
Push — dependabot/npm_and_yarn/highli... ( cb1e44...34f0f6 )
by
unknown
13:27 queued 06:04
created

Version20170627122900   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 313
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 258
c 0
b 0
f 0
dl 0
loc 313
rs 10
wmc 9

2 Methods

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