update-files-1.8.5-1.8.6.inc.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Chamilo LMS
  5. *
  6. * Updates the Dokeos files from version 1.8.5 to version 1.8.6
  7. * This script operates only in the case of an update, and only to change the
  8. * active version number (and other things that might need a change) in the
  9. * current configuration file.
  10. * As of 1.8.6, the Dokeos version has been added to configuration.php to
  11. * allow for edition (inc/conf is one of the directories that needs write
  12. * permissions on upgrade).
  13. * Being in configuration.php, it benefits from the configuration.dist.php
  14. * advantages that a new version doesn't overwrite it, thus letting the old
  15. * version be available until the end of the installation.
  16. * @package chamilo.install
  17. */
  18. if (defined('SYSTEM_INSTALLATION')) {
  19. // Edit the configuration file
  20. $file = file(api_get_path(CONFIGURATION_PATH).'configuration.php');
  21. $fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w');
  22. $found_version = false;
  23. $found_stable = false;
  24. foreach ($file as $line) {
  25. $ignore = false;
  26. if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) {
  27. $found_version = true;
  28. $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
  29. } elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) {
  30. $found_stable = true;
  31. $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n";
  32. } elseif (stripos($line,'$userPasswordCrypted') !== false) {
  33. $line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n";
  34. } elseif (stripos($line, '?>') !== false) {
  35. // Ignore the line
  36. $ignore = true;
  37. }
  38. if (!$ignore) {
  39. fwrite($fh, $line);
  40. }
  41. }
  42. if (!$found_version) {
  43. fwrite($fh, '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
  44. }
  45. if (!$found_stable) {
  46. fwrite($fh, '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n");
  47. }
  48. fwrite($fh, '?>');
  49. fclose($fh);
  50. $sys_course_path = $pathForm.'courses/';
  51. //$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  52. //// Linking (The following line is disabled, connection has been already done)
  53. //$res = @Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm));
  54. //Database::select_db($dbNameForm, $link);
  55. Database::select_db($dbNameForm);
  56. $db_name = $dbNameForm;
  57. $sql = "SELECT * FROM $db_name.course";
  58. error_log('Getting courses for files updates: '.$sql, 0);
  59. $result = Database::query($sql);
  60. while ($courses_directories = Database::fetch_array($result)) {
  61. $currentCourseRepositorySys = $sys_course_path.$courses_directories['directory'].'/';
  62. $db_name = $courses_directories['db_name'];
  63. $origCRS = $updatePath.'courses/'.$courses_directories['directory'];
  64. if (!is_dir($origCRS)) {
  65. error_log('Directory '.$origCRS.' does not exist. Skipping.', 0);
  66. continue;
  67. }
  68. // Move everything to the new hierarchy (from old path to new path)
  69. error_log('Renaming '.$origCRS.' to '.$sys_course_path.$courses_directories['directory'], 0);
  70. rename($origCRS,$sys_course_path.$courses_directories['directory']);
  71. error_log('Creating dirs in '.$currentCourseRepositorySys, 0);
  72. // DOCUMENT FOLDER
  73. // document > shared_folder
  74. if (!is_dir($currentCourseRepositorySys."document/shared_folder")) {
  75. mkdir($currentCourseRepositorySys."document/shared_folder", $perm);
  76. }
  77. // UPLOAD FOLDER
  78. // upload > forum > images
  79. if (!is_dir($currentCourseRepositorySys."upload/forum/images")) {
  80. mkdir($currentCourseRepositorySys."upload/forum/images", $perm);
  81. }
  82. // upload > learning_path
  83. if (!is_dir($currentCourseRepositorySys."upload/learning_path")) {
  84. mkdir($currentCourseRepositorySys."upload/learning_path", $perm);
  85. }
  86. // upload > learning_path > images
  87. if (!is_dir($currentCourseRepositorySys."upload/learning_path/images")) {
  88. mkdir($currentCourseRepositorySys."upload/learning_path/images", $perm);
  89. }
  90. // upload > calendar
  91. if (!is_dir($currentCourseRepositorySys."upload/calendar")) {
  92. mkdir($currentCourseRepositorySys."upload/calendar", $perm);
  93. }
  94. // upload > calendar > images
  95. if (!is_dir($currentCourseRepositorySys."upload/calendar/images")) {
  96. mkdir($currentCourseRepositorySys."upload/calendar/images", $perm);
  97. }
  98. }
  99. } else {
  100. echo 'You are not allowed here !';
  101. }