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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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,'?>'))
  42. {
  43. //ignore the line
  44. $ignore = true;
  45. }
  46. if(!$ignore)
  47. {
  48. fwrite($fh,$line);
  49. }
  50. }
  51. if(!$found_version)
  52. {
  53. fwrite($fh,'$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
  54. }
  55. if(!$found_stable)
  56. {
  57. fwrite($fh,'$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
  58. }
  59. fwrite($fh,'?>');
  60. fclose($fh);
  61. $sys_course_path = $pathForm.'courses/';
  62. //$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  63. //linking
  64. $link = mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm);
  65. mysql_select_db($dbNameForm,$link);
  66. $db_name = $dbNameForm;
  67. $sql = "SELECT * FROM $db_name.course";
  68. error_log('Getting courses for files updates: '.$sql,0);
  69. $result=mysql_query($sql);
  70. $perm = api_get_setting('permissions_for_new_directories');
  71. $perm = octdec(!empty($perm)?$perm:'0770');
  72. $old_umask = umask(0);
  73. while($courses_directories=mysql_fetch_array($result))
  74. {
  75. $currentCourseRepositorySys = $sys_course_path.$courses_directories['directory'].'/';
  76. $db_name = $courses_directories['db_name'];
  77. $origCRS = $updatePath.'courses/'.$courses_directories['directory'];
  78. if(!is_dir($origCRS)){
  79. error_log('Directory '.$origCRS.' does not exist. Skipping.',0);
  80. continue;
  81. }
  82. //move everything to the new hierarchy (from old path to new path)
  83. error_log('Renaming '.$origCRS.' to '.$sys_course_path.$courses_directories['directory'],0);
  84. rename($origCRS,$sys_course_path.$courses_directories['directory']);
  85. error_log('Creating dirs in '.$currentCourseRepositorySys,0);
  86. //FOLDER UPLOAD
  87. //upload > forum > images
  88. if(!is_dir($currentCourseRepositorySys."upload/forum/images")){
  89. mkdir($currentCourseRepositorySys."upload/forum/images",$perm);
  90. }
  91. //upload > learning_path
  92. if(!is_dir($currentCourseRepositorySys."upload/learning_path")){
  93. mkdir($currentCourseRepositorySys."upload/learning_path",$perm);
  94. }
  95. //upload > learning_path > images
  96. if(!is_dir($currentCourseRepositorySys."upload/learning_path/images")){
  97. mkdir($currentCourseRepositorySys."upload/learning_path/images",$perm);
  98. }
  99. }
  100. }
  101. else
  102. {
  103. echo 'You are not allowed here !';
  104. }
  105. ?>