update-configuration.inc.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. Log::notice("Starting " . basename(__FILE__));
  12. $perm = api_get_permissions_for_new_files();
  13. $oldConfFile = api_get_path(SYS_CODE_PATH) . 'inc/conf/configuration.php';
  14. $newConfFile = api_get_path(CONFIGURATION_PATH) . 'configuration.php';
  15. if (file_exists($oldConfFile)) {
  16. copy($oldConfFile, $newConfFile);
  17. @chmod($newConfFile, $perm);
  18. @rmdir($oldConfFile);
  19. }
  20. // Edit the configuration file.
  21. $file = file($newConfFile);
  22. $fh = fopen($newConfFile, 'w');
  23. $found_version_old = false;
  24. $found_stable_old = false;
  25. $found_version = false;
  26. $found_stable = false;
  27. $found_software_name = false;
  28. $found_software_url = false;
  29. foreach ($file as $line) {
  30. $ignore = false;
  31. if (stripos($line, '$_configuration[\'system_version\']') !== false) {
  32. $found_version = true;
  33. $line = '$_configuration[\'system_version\'] = \'' . $new_version . '\';' . "\r\n";
  34. } elseif (stripos($line, '$_configuration[\'system_stable\']') !== false) {
  35. $found_stable = true;
  36. $line = '$_configuration[\'system_stable\'] = ' . ($new_version_stable ? 'true' : 'false') . ';' . "\r\n";
  37. } elseif (stripos($line, '$_configuration[\'software_name\']') !== false) {
  38. $found_software_name = true;
  39. $line = '$_configuration[\'software_name\'] = \'' . $software_name . '\';' . "\r\n";
  40. } elseif (stripos($line, '$_configuration[\'software_url\']') !== false) {
  41. $found_software_url = true;
  42. $line = '$_configuration[\'software_url\'] = \'' . $software_url . '\';' . "\r\n";
  43. } elseif (stripos($line, '$userPasswordCrypted') !== false) {
  44. $line = '$_configuration[\'password_encryption\'] = \'' .$userPasswordCrypted.'\';' . "\r\n";
  45. } elseif (stripos($line, '?>') !== false) {
  46. $ignore = true;
  47. }
  48. if (!$ignore) {
  49. fwrite($fh, $line);
  50. }
  51. }
  52. if (!$found_version) {
  53. fwrite($fh, '$_configuration[\'system_version\'] = \'' . $new_version . '\';' . "\r\n");
  54. }
  55. if (!$found_stable) {
  56. fwrite($fh, '$_configuration[\'system_stable\'] = ' . ($new_version_stable ? 'true' : 'false') . ';' . "\r\n");
  57. }
  58. if (!$found_software_name) {
  59. fwrite($fh, '$_configuration[\'software_name\'] = \'' . $software_name . '\';' . "\r\n");
  60. }
  61. if (!$found_software_url) {
  62. fwrite($fh, '$_configuration[\'software_url\'] = \'' . $software_url . '\';' . "\r\n");
  63. }
  64. fwrite($fh, '?>');
  65. fclose($fh);
  66. } else {
  67. echo 'You are not allowed here !'. __FILE__;
  68. }