1 | <?php |
||||
2 | /* For licensing terms, see /license.txt */ |
||||
3 | |||||
4 | use Symfony\Component\Filesystem\Exception\IOException; |
||||
5 | use Symfony\Component\Filesystem\Filesystem; |
||||
6 | use Symfony\Component\Finder\Finder; |
||||
7 | |||||
8 | /** |
||||
9 | * Chamilo LMS. |
||||
10 | * |
||||
11 | * Updates the Chamilo files from version 1.9.0 to version 1.10.0 |
||||
12 | * This script operates only in the case of an update, and only to change the |
||||
13 | * active version number (and other things that might need a change) in the |
||||
14 | * current configuration file. |
||||
15 | * |
||||
16 | * @package chamilo.install |
||||
17 | */ |
||||
18 | error_log("Starting ".basename(__FILE__)); |
||||
19 | |||||
20 | global $debug; |
||||
21 | |||||
22 | if (defined('SYSTEM_INSTALLATION')) { |
||||
23 | // Changes for 1.10.x |
||||
24 | // Delete directories and files that are not necessary anymore |
||||
25 | // pChart (1) lib, etc |
||||
26 | |||||
27 | // Delete the "chat" file in all language directories, as variables have been moved to the trad4all file |
||||
28 | $langPath = api_get_path(SYS_CODE_PATH).'lang/'; |
||||
29 | // Only erase files from Chamilo languages (not sublanguages defined by the users) |
||||
30 | $officialLanguages = [ |
||||
31 | 'arabic', |
||||
32 | 'asturian', |
||||
33 | 'basque', |
||||
34 | 'bengali', |
||||
35 | 'bosnian', |
||||
36 | 'brazilian', |
||||
37 | 'bulgarian', |
||||
38 | 'catalan', |
||||
39 | 'croatian', |
||||
40 | 'czech', |
||||
41 | 'danish', |
||||
42 | 'dari', |
||||
43 | 'dutch', |
||||
44 | 'english', |
||||
45 | 'esperanto', |
||||
46 | 'faroese', |
||||
47 | 'finnish', |
||||
48 | 'french', |
||||
49 | 'friulian', |
||||
50 | 'galician', |
||||
51 | 'georgian', |
||||
52 | 'german', |
||||
53 | 'greek', |
||||
54 | 'hebrew', |
||||
55 | 'hindi', |
||||
56 | 'hungarian', |
||||
57 | 'indonesian', |
||||
58 | 'italian', |
||||
59 | 'japanese', |
||||
60 | 'korean', |
||||
61 | 'latvian', |
||||
62 | 'lithuanian', |
||||
63 | 'macedonian', |
||||
64 | 'malay', |
||||
65 | 'norwegian', |
||||
66 | 'occitan', |
||||
67 | 'pashto', |
||||
68 | 'persian', |
||||
69 | 'polish', |
||||
70 | 'portuguese', |
||||
71 | 'quechua_cusco', |
||||
72 | 'romanian', |
||||
73 | 'russian', |
||||
74 | 'serbian', |
||||
75 | 'simpl_chinese', |
||||
76 | 'slovak', |
||||
77 | 'slovenian', |
||||
78 | 'somali', |
||||
79 | 'spanish', |
||||
80 | 'spanish_latin', |
||||
81 | 'swahili', |
||||
82 | 'swedish', |
||||
83 | 'tagalog', |
||||
84 | 'thai', |
||||
85 | 'tibetan', |
||||
86 | 'trad_chinese', |
||||
87 | 'turkish', |
||||
88 | 'ukrainian', |
||||
89 | 'vietnamese', |
||||
90 | 'xhosa', |
||||
91 | 'yoruba', |
||||
92 | ]; |
||||
93 | |||||
94 | $filesToDelete = [ |
||||
95 | 'accessibility', |
||||
96 | 'admin', |
||||
97 | 'agenda', |
||||
98 | 'announcements', |
||||
99 | 'blog', |
||||
100 | 'chat', |
||||
101 | 'coursebackup', |
||||
102 | 'course_description', |
||||
103 | 'course_home', |
||||
104 | 'course_info', |
||||
105 | 'courses', |
||||
106 | 'create_course', |
||||
107 | 'document', |
||||
108 | 'dropbox', |
||||
109 | 'exercice', |
||||
110 | 'external_module', |
||||
111 | 'forum', |
||||
112 | 'glossary', |
||||
113 | 'gradebook', |
||||
114 | 'group', |
||||
115 | 'help', |
||||
116 | 'import', |
||||
117 | 'index', |
||||
118 | 'install', |
||||
119 | 'learnpath', |
||||
120 | 'link', |
||||
121 | 'md_document', |
||||
122 | 'md_link', |
||||
123 | 'md_mix', |
||||
124 | 'md_scorm', |
||||
125 | 'messages', |
||||
126 | 'myagenda', |
||||
127 | 'notebook', |
||||
128 | 'notification', |
||||
129 | 'registration', |
||||
130 | 'reservation', |
||||
131 | 'pedaSuggest', |
||||
132 | 'resourcelinker', |
||||
133 | 'scorm', |
||||
134 | 'scormbuilder', |
||||
135 | 'scormdocument', |
||||
136 | 'slideshow', |
||||
137 | 'survey', |
||||
138 | 'tracking', |
||||
139 | 'userInfo', |
||||
140 | 'videoconf', |
||||
141 | 'wiki', |
||||
142 | 'work', |
||||
143 | ]; |
||||
144 | |||||
145 | $list = scandir($langPath); |
||||
146 | foreach ($list as $entry) { |
||||
147 | if (is_dir($langPath.$entry) && |
||||
148 | in_array($entry, $officialLanguages) |
||||
149 | ) { |
||||
150 | foreach ($filesToDelete as $file) { |
||||
151 | if (is_file($langPath.$entry.'/'.$file.'.inc.php')) { |
||||
152 | unlink($langPath.$entry.'/'.$file.'.inc.php'); |
||||
153 | } |
||||
154 | } |
||||
155 | } |
||||
156 | } |
||||
157 | |||||
158 | if ($debug) { |
||||
159 | error_log('Cleaning folders'); |
||||
160 | } |
||||
161 | |||||
162 | // Remove the "main/conference/" directory that wasn't used since years long |
||||
163 | // past - see rrmdir function declared below |
||||
164 | @rrmdir(api_get_path(SYS_CODE_PATH).'conference'); |
||||
0 ignored issues
–
show
Are you sure the usage of
rrmdir(api_get_path(SYS_...E_PATH) . 'conference') is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
165 | // Other files that we renamed |
||||
166 | // events.lib.inc.php has been renamed to events.lib.php |
||||
167 | if (is_file(api_get_path(LIBRARY_PATH).'events.lib.inc.php')) { |
||||
168 | @unlink(api_get_path(LIBRARY_PATH).'events.lib.inc.php'); |
||||
0 ignored issues
–
show
It seems like you do not handle an error condition for
unlink() . This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||||
169 | } |
||||
170 | |||||
171 | if (is_file(api_get_path(SYS_PATH).'courses/.htaccess')) { |
||||
172 | unlink(api_get_path(SYS_PATH).'courses/.htaccess'); |
||||
173 | } |
||||
174 | |||||
175 | // Move dirs into new structures. |
||||
176 | $movePathList = [ |
||||
177 | api_get_path(SYS_CODE_PATH).'upload/users/groups' => api_get_path(SYS_UPLOAD_PATH).'groups', |
||||
178 | api_get_path(SYS_CODE_PATH).'upload/users' => api_get_path(SYS_UPLOAD_PATH).'users', |
||||
179 | api_get_path(SYS_CODE_PATH).'upload/badges' => api_get_path(SYS_UPLOAD_PATH).'badges', |
||||
180 | api_get_path(SYS_PATH).'courses' => api_get_path(SYS_APP_PATH).'courses', |
||||
181 | api_get_path(SYS_PATH).'searchdb' => api_get_path(SYS_UPLOAD_PATH).'plugins/xapian/', |
||||
182 | api_get_path(SYS_PATH).'home' => api_get_path(SYS_APP_PATH).'home', |
||||
183 | ]; |
||||
184 | |||||
185 | if ($debug) { |
||||
186 | error_log('Moving folders'); |
||||
187 | } |
||||
188 | |||||
189 | $fs = new Filesystem(); |
||||
190 | |||||
191 | foreach ($movePathList as $origin => $destination) { |
||||
192 | if (is_dir($origin)) { |
||||
193 | $fs->mirror($origin, $destination); |
||||
194 | |||||
195 | if ($debug) { |
||||
196 | error_log("Renaming: '$origin' to '$destination'"); |
||||
197 | } |
||||
198 | |||||
199 | try { |
||||
200 | $fs->remove($origin); |
||||
201 | } catch (IOException $e) { |
||||
202 | // If removing the directory doesn't work, just log an error and continue |
||||
203 | error_log('Could not move '.$origin.' to '.$destination.'('.$e->getMessage().'). Please move it manually.'); |
||||
204 | } |
||||
205 | } |
||||
206 | } |
||||
207 | |||||
208 | // Delete all "courses/ABC/index.php" files. |
||||
209 | if ($debug) { |
||||
210 | error_log('Deleting old courses/ABC/index.php files'); |
||||
211 | } |
||||
212 | $finder = new Finder(); |
||||
213 | |||||
214 | $courseDir = api_get_path(SYS_APP_PATH).'courses'; |
||||
215 | if (is_dir($courseDir)) { |
||||
216 | $dirs = $finder->directories()->in($courseDir); |
||||
217 | /** @var Symfony\Component\Finder\SplFileInfo $dir */ |
||||
218 | foreach ($dirs as $dir) { |
||||
219 | $indexFile = $dir->getPath().'/index.php'; |
||||
220 | if ($debug) { |
||||
221 | error_log('Deleting: '.$indexFile); |
||||
222 | } |
||||
223 | if ($fs->exists($indexFile)) { |
||||
224 | $fs->remove($indexFile); |
||||
225 | } |
||||
226 | } |
||||
227 | } |
||||
228 | |||||
229 | // Remove old "courses" folder if empty |
||||
230 | $originalCourseDir = api_get_path(SYS_PATH).'courses'; |
||||
231 | |||||
232 | if (is_dir($originalCourseDir)) { |
||||
233 | $dirs = $finder->directories()->in($originalCourseDir); |
||||
234 | $files = $finder->directories()->in($originalCourseDir); |
||||
235 | $dirCount = $dirs->count(); |
||||
236 | $fileCount = $dirs->count(); |
||||
237 | if ($fileCount == 0 && $dirCount == 0) { |
||||
238 | @rrmdir(api_get_path(SYS_PATH).'courses'); |
||||
0 ignored issues
–
show
Are you sure the usage of
rrmdir(api_get_path(SYS_PATH) . 'courses') is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
239 | } |
||||
240 | } |
||||
241 | |||||
242 | if ($debug) { |
||||
243 | error_log('Remove archive folder'); |
||||
244 | } |
||||
245 | |||||
246 | // Remove archive |
||||
247 | @rrmdir(api_get_path(SYS_PATH).'archive'); |
||||
0 ignored issues
–
show
Are you sure the usage of
rrmdir(api_get_path(SYS_PATH) . 'archive') is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
248 | } else { |
||||
249 | echo 'You are not allowed here !'.__FILE__; |
||||
250 | } |
||||
251 |
If you suppress an error, we recommend checking for the error condition explicitly: