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