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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /* See license terms in /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * Updates the Dokeos files from version 1.8.5 to version 1.8.6
  6. * This script operates only in the case of an update, and only to change the
  7. * active version number (and other things that might need a change) in the
  8. * current configuration file.
  9. * As of 1.8.6, the Dokeos version has been added to configuration.php to
  10. * allow for edition (inc/conf is one of the directories that needs write
  11. * permissions on upgrade).
  12. * Being in configuration.php, it benefits from the configuration.dist.php
  13. * advantages that a new version doesn't overwrite it, thus letting the old
  14. * version be available until the end of the installation.
  15. * @package dokeos.install
  16. ==============================================================================
  17. */
  18. require_once("../inc/lib/main_api.lib.php");
  19. require_once("../inc/lib/fileUpload.lib.php");
  20. require_once('../inc/lib/database.lib.php');
  21. if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
  22. {
  23. // Edit the Dokeos config file
  24. $file = file('../inc/conf/configuration.php');
  25. $fh = fopen('../inc/conf/configuration.php','w');
  26. $found_version = false;
  27. $found_stable = false;
  28. foreach($file as $line)
  29. {
  30. $ignore = false;
  31. if(stristr($line,'$_configuration[\'dokeos_version\']'))
  32. {
  33. $found_version = true;
  34. $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
  35. }
  36. elseif(stristr($line,'$_configuration[\'dokeos_stable\']'))
  37. {
  38. $found_stable = true;
  39. $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n";
  40. }
  41. elseif(stristr($line,'$userPasswordCrypted'))
  42. {
  43. $line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n";
  44. }
  45. elseif(stristr($line,'?>'))
  46. {
  47. //ignore the line
  48. $ignore = true;
  49. }
  50. if(!$ignore)
  51. {
  52. fwrite($fh,$line);
  53. }
  54. }
  55. if(!$found_version)
  56. {
  57. fwrite($fh,'$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
  58. }
  59. if(!$found_stable)
  60. {
  61. fwrite($fh,'$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
  62. }
  63. fwrite($fh,'?>');
  64. fclose($fh);
  65. $sys_course_path = $pathForm.'courses/';
  66. //$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  67. //linking
  68. $link = mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm);
  69. mysql_select_db($dbNameForm,$link);
  70. $db_name = $dbNameForm;
  71. $sql = "SELECT * FROM $db_name.course";
  72. error_log('Getting courses for files updates: '.$sql,0);
  73. $result=mysql_query($sql);
  74. $perm = api_get_setting('permissions_for_new_directories');
  75. $perm = octdec(!empty($perm)?$perm:'0770');
  76. $old_umask = umask(0);
  77. while($courses_directories=mysql_fetch_array($result))
  78. {
  79. $currentCourseRepositorySys = $sys_course_path.$courses_directories['directory'].'/';
  80. $db_name = $courses_directories['db_name'];
  81. $origCRS = $updatePath.'courses/'.$courses_directories['directory'];
  82. if(!is_dir($origCRS)){
  83. error_log('Directory '.$origCRS.' does not exist. Skipping.',0);
  84. continue;
  85. }
  86. //move everything to the new hierarchy (from old path to new path)
  87. error_log('Renaming '.$origCRS.' to '.$sys_course_path.$courses_directories['directory'],0);
  88. rename($origCRS,$sys_course_path.$courses_directories['directory']);
  89. error_log('Creating dirs in '.$currentCourseRepositorySys,0);
  90. //DOCUMENT FOLDER
  91. //document > shared_folder
  92. if(!is_dir($currentCourseRepositorySys."document/shared_folder")){
  93. mkdir($currentCourseRepositorySys."document/shared_folder",$perm);
  94. }
  95. //UPLOAD FOLDER
  96. //upload > forum > images
  97. if(!is_dir($currentCourseRepositorySys."upload/forum/images")){
  98. mkdir($currentCourseRepositorySys."upload/forum/images",$perm);
  99. }
  100. //upload > learning_path
  101. if(!is_dir($currentCourseRepositorySys."upload/learning_path")){
  102. mkdir($currentCourseRepositorySys."upload/learning_path",$perm);
  103. }
  104. //upload > learning_path > images
  105. if(!is_dir($currentCourseRepositorySys."upload/learning_path/images")){
  106. mkdir($currentCourseRepositorySys."upload/learning_path/images",$perm);
  107. }
  108. //upload > calendar
  109. if(!is_dir($currentCourseRepositorySys."upload/calendar")){
  110. mkdir($currentCourseRepositorySys."upload/calendar",$perm);
  111. }
  112. //upload > calendar > images
  113. if(!is_dir($currentCourseRepositorySys."upload/calendar/images")){
  114. mkdir($currentCourseRepositorySys."upload/calendar/images",$perm);
  115. }
  116. }
  117. }
  118. else
  119. {
  120. echo 'You are not allowed here !';
  121. }
  122. ?>