update-configuration.inc.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. *
  5. * Chamilo LMS
  6. *
  7. * Only updates the main/inc/conf/configuration.php
  8. * @package chamilo.install
  9. */
  10. if (defined('SYSTEM_INSTALLATION')) {
  11. error_log("Starting ".basename(__FILE__));
  12. $perm = api_get_permissions_for_new_files();
  13. $newConfFile = api_get_path(CONFIGURATION_PATH).'configuration.php';
  14. // Check $fromVersionShort, defined in install.lib.php, in the switch
  15. // on full version numbers, to know from which version we are upgrading
  16. if ($fromVersionShort == '1.9') {
  17. $oldConfFile = api_get_path(SYS_CODE_PATH).'inc/conf/configuration.php';
  18. if (file_exists($oldConfFile)) {
  19. copy($oldConfFile, $newConfFile);
  20. @chmod($newConfFile, $perm);
  21. @rmdir($oldConfFile);
  22. }
  23. }
  24. // Edit the configuration file.
  25. $file = file($newConfFile);
  26. $fh = fopen($newConfFile, 'w');
  27. $found_version_old = false;
  28. $found_stable_old = false;
  29. $found_version = false;
  30. $found_stable = false;
  31. $found_software_name = false;
  32. $found_software_url = false;
  33. foreach ($file as $line) {
  34. $ignore = false;
  35. if (stripos($line, '$_configuration[\'system_version\']') !== false) {
  36. $found_version = true;
  37. $line = '$_configuration[\'system_version\'] = \''.$GLOBALS['new_version'].'\';'."\r\n";
  38. } elseif (stripos($line, '$_configuration[\'system_stable\']') !== false) {
  39. $found_stable = true;
  40. $line = '$_configuration[\'system_stable\'] = '.($GLOBALS['new_version_stable'] ? 'true' : 'false').';'."\r\n";
  41. } elseif (stripos($line, '$_configuration[\'software_name\']') !== false) {
  42. $found_software_name = true;
  43. $line = '$_configuration[\'software_name\'] = \''.$GLOBALS['software_name'].'\';'."\r\n";
  44. } elseif (stripos($line, '$_configuration[\'software_url\']') !== false) {
  45. $found_software_url = true;
  46. $line = '$_configuration[\'software_url\'] = \''.$GLOBALS['software_url'].'\';'."\r\n";
  47. } elseif (stripos($line, '$userPasswordCrypted') !== false) {
  48. $line = '$_configuration[\'password_encryption\'] = \''.$userPasswordCrypted.'\';'."\r\n";
  49. } elseif (stripos($line, '?>') !== false) {
  50. $ignore = true;
  51. }
  52. if (!$ignore) {
  53. fwrite($fh, $line);
  54. }
  55. }
  56. if (!$found_version) {
  57. fwrite($fh, '$_configuration[\'system_version\'] = \''.$new_version.'\';'."\r\n");
  58. }
  59. if (!$found_stable) {
  60. fwrite($fh, '$_configuration[\'system_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n");
  61. }
  62. if (!$found_software_name) {
  63. fwrite($fh, '$_configuration[\'software_name\'] = \''.$software_name.'\';'."\r\n");
  64. }
  65. if (!$found_software_url) {
  66. fwrite($fh, '$_configuration[\'software_url\'] = \''.$software_url.'\';'."\r\n");
  67. }
  68. fclose($fh);
  69. error_log("configuration.php file updated.");
  70. } else {
  71. echo 'You are not allowed here !'.__FILE__;
  72. }