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

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