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

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