update-files-1.9.0-1.10.0.inc.php 6.7 KB

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