1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Component\Utils; |
8
|
|
|
|
9
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
10
|
|
|
|
11
|
|
|
class ScriptHandler |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Dump files to the web/css folder. |
15
|
|
|
*/ |
16
|
|
|
public static function dumpCssFiles(): void |
17
|
|
|
{ |
18
|
|
|
/*$appCss = __DIR__.'/../../../assets/libs'; |
19
|
|
|
$newPath = __DIR__.'/../../../public/libs/'; |
20
|
|
|
if (!is_dir($newPath)) { |
21
|
|
|
mkdir($newPath); |
22
|
|
|
} |
23
|
|
|
$fs = new Filesystem(); |
24
|
|
|
$fs->mirror($appCss, $newPath, null, ['override' => true]);*/ |
25
|
|
|
|
26
|
|
|
if (\function_exists('opcache_reset')) { |
27
|
|
|
opcache_reset(); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Delete old Symfony folder before update (generates conflicts with composer) |
33
|
|
|
* This method also applies to 1.10 folders removed for 1.11. |
34
|
|
|
*/ |
35
|
|
|
public static function deleteOldFilesFrom19x(): void |
36
|
|
|
{ |
37
|
|
|
$paths = self::getFoldersToDelete(); |
38
|
|
|
|
39
|
|
|
foreach ($paths as $path) { |
40
|
|
|
$path = __DIR__.'/../../../..'.$path; |
41
|
|
|
if (is_dir($path) && is_writable($path)) { |
42
|
|
|
self::rmdirr($path); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$files = self::getFilesToDelete(); |
47
|
|
|
|
48
|
|
|
foreach ($files as $file) { |
49
|
|
|
$file = __DIR__.'/../../../..'.$file; |
50
|
|
|
if (is_file($file) && is_writable($file)) { |
51
|
|
|
unlink($file); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public static function getFoldersToDelete(): array |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
'/app/Resources/public/assets/bootstrap/docs', |
60
|
|
|
'/app/Resources/public/assets/bootstrap/nuget', |
61
|
|
|
'/app/Resources/public/assets/bootstrap/grunt', |
62
|
|
|
'/app/Resources/public/assets/bootstrap/test-infra', |
63
|
|
|
'/archive/', |
64
|
|
|
'/main/announcements/resources', |
65
|
|
|
'/main/conference/', |
66
|
|
|
'/main/course_notice/', |
67
|
|
|
'/main/metadata/', |
68
|
|
|
'/main/exercice/export/qti', |
69
|
|
|
'/main/glossary/resources', |
70
|
|
|
'/main/link/resources', |
71
|
|
|
'/main/notebook/resources', |
72
|
|
|
'/main/reservation/', |
73
|
|
|
'/main/inc/lib/symfony/', |
74
|
|
|
'/main/inc/entity/', |
75
|
|
|
'/main/inc/lib/phpdocx/', |
76
|
|
|
'/main/inc/lib/phpqrcode/', |
77
|
|
|
'/main/inc/lib/ezpdf', |
78
|
|
|
'/main/inc/lib/javascript/bootstrap', |
79
|
|
|
'/main/inc/lib/javascript/bxslider', |
80
|
|
|
'/main/inc/lib/javascript/fullcalendar', |
81
|
|
|
'/main/inc/lib/javascript/jquery-ui', |
82
|
|
|
'/main/inc/lib/fckeditor', |
83
|
|
|
'/main/inc/lib/mpdf/', |
84
|
|
|
'/main/inc/lib/nanogong/', |
85
|
|
|
'/main/inc/lib/phpseclib/', |
86
|
|
|
'/main/inc/lib/phpmailer/', |
87
|
|
|
'/main/inc/lib/symfony/', |
88
|
|
|
'/main/inc/lib/system/media/renderer', |
89
|
|
|
'/main/inc/lib/system/io', |
90
|
|
|
'/main/inc/lib/system/net', |
91
|
|
|
'/main/inc/lib/system/text/', |
92
|
|
|
'/main/inc/lib/system/portfolio/', |
93
|
|
|
'/main/inc/lib/icalcreator/', |
94
|
|
|
'/main/inc/lib/getid3/', |
95
|
|
|
'/main/inc/lib/tools/', |
96
|
|
|
'/main/inc/lib/pchart/', |
97
|
|
|
'/main/inc/lib/pclzip/', |
98
|
|
|
'/main/inc/lib/htmlpurifier', |
99
|
|
|
'/main/pear/excelreader/', |
100
|
|
|
'/main/resourcelinker', |
101
|
|
|
'/main/newscorm', |
102
|
|
|
'/main/exercice', |
103
|
|
|
'/plugin/ticket', |
104
|
|
|
'/plugin/skype', |
105
|
|
|
'/vendor/pclzip', |
106
|
|
|
'/web/assets/bootstrap/grunt', |
107
|
|
|
'/web/assets/bootstrap/nuget', |
108
|
|
|
'/web/assets/bootstrap/docs', |
109
|
|
|
'/web/assets/bootstrap/test-infra', |
110
|
|
|
]; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public static function getFilesToDelete(): array |
114
|
|
|
{ |
115
|
|
|
return [ |
116
|
|
|
'/main/admin/statistics/statistics.lib.php', |
117
|
|
|
'/main/admin/add_users_to_group.php', |
118
|
|
|
'/main/admin/group_add.php', |
119
|
|
|
'/main/admin/group_edit.php', |
120
|
|
|
'/main/admin/group_list.php', |
121
|
|
|
'/main/admin/admin_page.class.php', |
122
|
|
|
'/main/admin/system_management.php', |
123
|
|
|
'/main/announcements/resources/announcements.inc.php', |
124
|
|
|
'/main/announcements/resources/announcements_email.class.php', |
125
|
|
|
'/main/auth/external_login/facebook-php-sdk/src/base_facebook.php', |
126
|
|
|
'/main/auth/external_login/facebook-php-sdk/src/facebook.php', |
127
|
|
|
'/main/auth/external_login/facebook-php-sdk/src/base_facebook.php', |
128
|
|
|
'/main/course_description/ajax_controller.class.php', |
129
|
|
|
'/main/course_description/controller.class.php', |
130
|
|
|
'/main/course_description/course_description.class.php', |
131
|
|
|
'/main/course_description/course_description_form.class.php', |
132
|
|
|
'/main/course_description/course_description_repository.class.php', |
133
|
|
|
'/main/course_description/course_description_type.class.php', |
134
|
|
|
'/main/course_description/course_description_type_repository.class.php', |
135
|
|
|
'/main/course_description/course_import.class.php', |
136
|
|
|
'/main/course_description/csv_reader.class.php', |
137
|
|
|
'/main/course_description/csv_writer.class.php', |
138
|
|
|
'/main/course_description/request.class.php', |
139
|
|
|
'/main/course_description/upload_file_form.class.php', |
140
|
|
|
'/main/calendar/agenda.inc.php', |
141
|
|
|
'/main/calendar/agenda.lib.php', |
142
|
|
|
'/main/exercice/addlimits.php', |
143
|
|
|
'/main/exercice/testcategory.class.php', |
144
|
|
|
'/main/exercice/export/scorm/scorm_export.php', |
145
|
|
|
'/main/exercice/testheaderpage.php', |
146
|
|
|
'/main/exercise/hotspot_lang_conversion.php', |
147
|
|
|
'/main/exercise/export/qti2/qti2_classes.php', |
148
|
|
|
'/main/inc/lib/main_api.lib.php', |
149
|
|
|
'/main/inc/lib/nusoap/class.soapclient.php', |
150
|
|
|
'/main/inc/lib/nusoap/nusoap.php', |
151
|
|
|
'/main/inc/lib/autoload.class.php', |
152
|
|
|
'/main/inc/autoload.inc.php', |
153
|
|
|
'/main/inc/lib/uri.class.php', |
154
|
|
|
'/main/inc/lib/db.class.php', |
155
|
|
|
'/main/inc/lib/phpmailer/test/phpmailerTest.php', |
156
|
|
|
'/main/inc/lib/xht.lib.php', |
157
|
|
|
'/main/inc/lib/xmd.lib.php', |
158
|
|
|
'/main/inc/lib/surveymanager.lib.php', |
159
|
|
|
'/main/inc/lib/entity.class.php', |
160
|
|
|
'/main/inc/lib/entity_repository.class.php', |
161
|
|
|
'/main/inc/lib/javascript.class.php', |
162
|
|
|
'/main/inc/lib/course.class.php', |
163
|
|
|
'/main/inc/lib/document.class.php', |
164
|
|
|
'/main/inc/lib/item_property.class.php', |
165
|
|
|
'/main/inc/lib/chamilo.class.php', |
166
|
|
|
'/main/inc/lib/events.lib.inc.php', |
167
|
|
|
'/main/inc/lib/current_user.class.php', |
168
|
|
|
'/main/inc/lib/current_course.class.php', |
169
|
|
|
'/main/inc/lib/response.class.php', |
170
|
|
|
'/main/inc/lib/result_set.class.php', |
171
|
|
|
'/main/inc/lib/session_handler.class.php', |
172
|
|
|
'/main/inc/lib/WCAG/WCAG_rendering.php', |
173
|
|
|
'/main/inc/lib/zip.class.php', |
174
|
|
|
'/main/inc/lib/student_publication.class.php', |
175
|
|
|
'/main/inc/lib/ajax_controller.class.php', |
176
|
|
|
'/main/inc/lib/system/closure_compiler.class.php', |
177
|
|
|
'/main/inc/lib/system/code_utilities.class.php', |
178
|
|
|
'/main/inc/lib/controller.class.php', |
179
|
|
|
'/main/inc/lib/system/text/converter.class.php', |
180
|
|
|
'/main/inc/lib/course_entity_repository.class.php', |
181
|
|
|
'/main/inc/lib/course_entity.class.php', |
182
|
|
|
'/main/inc/lib/cache.class.php', |
183
|
|
|
'/main/inc/lib/system/web/request_server.class.php', |
184
|
|
|
'/main/inc/lib/page.class.php', |
185
|
|
|
'/main/inc/lib/sortabletable.class.php', |
186
|
|
|
'/main/inc/lib/mail.lib.inc.php', |
187
|
|
|
'/main/install/i_database.class.php', |
188
|
|
|
'/main/install/install.class.php', |
189
|
|
|
'/main/inc/latex.php', |
190
|
|
|
'/main/inc/lib/formvalidator/Element/calendar_popup.php', |
191
|
|
|
'/main/inc/lib/formvalidator/Element/datepickerdate.php', |
192
|
|
|
'/main/inc/lib/formvalidator/Element/html_editor.php', |
193
|
|
|
'/main/inc/lib/formvalidator/Element/select_language.php', |
194
|
|
|
'/main/inc/lib/formvalidator/Element/select_theme.php', |
195
|
|
|
'/main/inc/lib/formvalidator/Element/style_button.php', |
196
|
|
|
'/main/inc/lib/formvalidator/Element/style_reset_button.php', |
197
|
|
|
'/main/inc/lib/formvalidator/Element/style_submit_button.php', |
198
|
|
|
'/main/inc/lib/formvalidator/Element/tbl_change.js.php', |
199
|
|
|
'/main/lp/resourcelinker.php', |
200
|
|
|
'/main/lp/resourcelinker.inc.php', |
201
|
|
|
'/main/lp/learnpath_functions.inc.php', |
202
|
|
|
'/main/lp/lp_list_search.css', |
203
|
|
|
'/main/ticket/course_user_list.php', |
204
|
|
|
'/main/ticket/report.php', |
205
|
|
|
'/main/ticket/tutor.php', |
206
|
|
|
'/main/ticket/update_report.php', |
207
|
|
|
'/main/tracking/toolaccess_details.php', |
208
|
|
|
'/main/tracking/course_access_details.php', |
209
|
|
|
'/src/DataFixtures/AppFixtures.php', |
210
|
|
|
'/src/Chamilo/CoreBundle/Entity/GroupRelGroup.php', |
211
|
|
|
'/src/Chamilo/CoreBundle/Entity/GroupRelTag.php', |
212
|
|
|
'/src/Chamilo/CoreBundle/Entity/GroupRelUser.php', |
213
|
|
|
'/src/Chamilo/CoreBundle/Entity/Groups.php', |
214
|
|
|
'/src/Chamilo/UserBundle/Entity/Repository/UserRepository.php', |
215
|
|
|
'/app/Resources/public/assets/bootstrap/Gemfile', |
216
|
|
|
'/app/Resources/public/assets/bootstrap/Gemfile.lock', |
217
|
|
|
'/app/Resources/public/assets/bootstrap/Gruntfile.js', |
218
|
|
|
'/app/Resources/public/assets/bootstrap/package.js', |
219
|
|
|
'/app/Resources/public/assets/bootstrap/package.json', |
220
|
|
|
'/web/assets/bootstrap/Gemfile', |
221
|
|
|
'/web/assets/bootstrap/Gemfile.lock', |
222
|
|
|
'/web/assets/bootstrap/Gruntfile.js', |
223
|
|
|
'/web/assets/bootstrap/package.js', |
224
|
|
|
'/web/assets/bootstrap/package.json', |
225
|
|
|
'/src/CourseBundle/Entity/CQuizQuestionRelCategory.php', |
226
|
|
|
'/main/inc/lib/tablesort.lib.php', |
227
|
|
|
]; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Update the basis css files. |
232
|
|
|
* Avoid use the ScriptHandler::dumpCssFiles. |
233
|
|
|
*/ |
234
|
|
|
public static function updateCss(): void |
235
|
|
|
{ |
236
|
|
|
$appCss = __DIR__.'/../../../../app/Resources/public/css/'; |
237
|
|
|
$newPath = __DIR__.'/../../../../web/css/'; |
238
|
|
|
$cssFiles = [ |
239
|
|
|
'base.css', |
240
|
|
|
'chat.css', |
241
|
|
|
'document.css', |
242
|
|
|
'editor_content.css', |
243
|
|
|
'markdown.css', |
244
|
|
|
'print.css', |
245
|
|
|
'responsive.css', |
246
|
|
|
'scorm.css', |
247
|
|
|
]; |
248
|
|
|
|
249
|
|
|
$fs = new Filesystem(); |
250
|
|
|
|
251
|
|
|
foreach ($cssFiles as $file) { |
252
|
|
|
$fs->copy($appCss.$file, $newPath.$file, true); |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Copied from chamilo rmdirr function. |
258
|
|
|
* |
259
|
|
|
* @return bool |
260
|
|
|
*/ |
261
|
|
|
private static function rmdirr(string $dirname, bool $delete_only_content_in_folder = false, bool $strict = false) |
262
|
|
|
{ |
263
|
|
|
$res = true; |
264
|
|
|
|
265
|
|
|
// A sanity check. |
266
|
|
|
if (!file_exists($dirname)) { |
267
|
|
|
return false; |
268
|
|
|
} |
269
|
|
|
// Simple delete for a file. |
270
|
|
|
if (is_file($dirname) || is_link($dirname)) { |
271
|
|
|
return unlink($dirname); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
// Loop through the folder. |
275
|
|
|
$dir = dir($dirname); |
276
|
|
|
// A sanity check. |
277
|
|
|
$is_object_dir = \is_object($dir); |
278
|
|
|
if ($is_object_dir) { |
279
|
|
|
while (false !== $entry = $dir->read()) { |
280
|
|
|
// Skip pointers. |
281
|
|
|
if ('.' === $entry || '..' === $entry) { |
282
|
|
|
continue; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
// Recurse. |
286
|
|
|
if ($strict) { |
287
|
|
|
$result = self::rmdirr(sprintf('%s/%s', $dirname, $entry)); |
288
|
|
|
if (!$result) { |
289
|
|
|
$res = false; |
290
|
|
|
|
291
|
|
|
break; |
292
|
|
|
} |
293
|
|
|
} else { |
294
|
|
|
self::rmdirr(sprintf('%s/%s', $dirname, $entry)); |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
// Clean up. |
300
|
|
|
if ($is_object_dir) { |
301
|
|
|
$dir->close(); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
if (!$delete_only_content_in_folder) { |
305
|
|
|
$res = rmdir($dirname); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
return $res; |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|