From 5f05dd3290bdcb3a60554b1c1452e593f75226db Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Sat, 27 Mar 2010 10:18:39 +0200 Subject: [PATCH] Task #836 Instalaltion scripts: System paths are used on treating files inside the system. --- main/install/install.lib.php | 83 ++++++++++--------- main/install/install_files.inc.php | 12 +-- .../update-db-scorm-1.6.x-1.8.0.inc.php | 6 +- main/install/update-files-1.6.x-1.8.0.inc.php | 4 +- main/install/update-files-1.8.3-1.8.4.inc.php | 10 +-- main/install/update-files-1.8.4-1.8.5.inc.php | 10 +-- main/install/update-files-1.8.5-1.8.6.inc.php | 12 +-- .../update-files-1.8.6-1.8.6.1.inc.php | 12 +-- .../update-files-1.8.6.1-1.8.6.2.inc.php | 12 +-- .../update-files-1.8.6.2-1.8.7.inc.php | 4 +- 10 files changed, 86 insertions(+), 79 deletions(-) diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 1f1d27a997..39fd1d1d0c 100644 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -33,12 +33,12 @@ function is_already_installed_system() { return true; // Must be initialized. } - $current_config_file = str_replace('\\', '/', realpath('../inc/conf/configuration.php')); + $current_config_file = api_get_path(CONFIGURATION_PATH).'configuration.php'; if (!file_exists($current_config_file)) { return false; // Configuration file does not exist, install the system. } require $current_config_file; - + $current_version = trim($_configuration['dokeos_version']); if (empty($current_version)) { $current_version = trim($_configuration['system_version']); @@ -213,7 +213,7 @@ function detect_browser_language() { * This function checks if the given folder is writable */ function check_writable($folder, $suggestion = false) { - if (is_writable('../'.$folder)) { + if (is_writable(api_get_path(SYS_CODE_PATH).$folder)) { return ''.get_lang('Writable').''; } else { if ($suggestion) { @@ -251,10 +251,9 @@ function set_file_folder_permissions() { * @param string $url_append The path from your webroot to your chamilo root */ function write_courses_htaccess_file($url_append) { - $file_path = dirname(__FILE__).'/'.COURSES_HTACCESS_FILENAME; - $content = file_get_contents($file_path); + $content = file_get_contents(dirname(__FILE__).'/'.COURSES_HTACCESS_FILENAME); $content = str_replace('{CHAMILO_URL_APPEND_PATH}', $url_append, $content); - $fp = @ fopen('../../courses/.htaccess', 'w'); + $fp = @ fopen(api_get_path(SYS_PATH).'courses/.htaccess', 'w'); if ($fp) { fwrite($fp, $content); return fclose($fp); @@ -1173,11 +1172,11 @@ function display_requirements($installType, $badUpdatePath, $updatePath = '', $u chamilo/main/css/ - '.check_writable('css/',true).' ('.get_lang('SuggestionOnlyToEnableCSSUploadFeature').') + '.check_writable('css/', true).' ('.get_lang('SuggestionOnlyToEnableCSSUploadFeature').') chamilo/main/lang/ - '.check_writable('lang/',true).' ('.get_lang('SuggestionOnlyToEnableSubLanguageFeature').') + '.check_writable('lang/', true).' ('.get_lang('SuggestionOnlyToEnableSubLanguageFeature').') '. //' // chamilo/searchdb/ @@ -1231,43 +1230,51 @@ function display_requirements($installType, $badUpdatePath, $updatePath = '', $u $notwritable = array(); $curdir = getcwd(); - if (!is_writable('../inc/conf')) { - $notwritable[] = realpath($curdir.'/../inc/conf'); - @chmod('../inc/conf',$perm); + $checked_writable = api_get_path(CONFIGURATION_PATH); + if (!is_writable($checked_writable)) { + $notwritable[] = $checked_writable; + @chmod($checked_writable, $perm); } - if (!is_writable('../upload/users')) { - $notwritable[] = realpath($curdir.'/../upload/users'); - @chmod('../upload/users', $perm); + $checked_writable = api_get_path(SYS_CODE_PATH).'upload/users/'; + if (!is_writable($checked_writable)) { + $notwritable[] = $checked_writable; + @chmod($checked_writable, $perm); } - if (!is_writable('../default_course_document/images/')) { - $notwritable[] = realpath($curdir.'/../default_course_document/images/'); - @chmod('../default_course_document/images/', $perm); + $checked_writable = api_get_path(SYS_CODE_PATH).'default_course_document/images/'; + if (!is_writable($checked_writable)) { + $notwritable[] = $checked_writable; + @chmod($checked_writable, $perm); } - if (!is_writable('../../archive')) { - $notwritable[] = realpath($curdir.'/../../archive'); - @chmod('../../archive',$perm); + $checked_writable = api_get_path(SYS_ARCHIVE_PATH); + if (!is_writable($checked_writable)) { + $notwritable[] = $checked_writable; + @chmod($checked_writable, $perm); } - if (!is_writable('../../courses')) { - $notwritable[] = realpath($curdir.'/../../courses'); - @chmod('../../courses',$perm); + $checked_writable = api_get_path(SYS_COURSE_PATH); + if (!is_writable($checked_writable)) { + $notwritable[] = $checked_writable; + @chmod($checked_writable, $perm); } - if (!is_writable('../../home')) { - $notwritable[] = realpath($curdir.'/../../home'); - @chmod('../../home',$perm); + $checked_writable = api_get_path(SYS_PATH).'home/'; + if (!is_writable($checked_writable)) { + $notwritable[] = realpath($checked_writable); + @chmod($checked_writable, $perm); } - if (file_exists('../inc/conf/configuration.php') && !is_writable('../inc/conf/configuration.php')) { - $notwritable[]= realpath($curdir.'/../inc/conf/configuration.php'); - @chmod('../inc/conf/configuration.php',$perm_file); + $checked_writable = api_get_path(CONFIGURATION_PATH).'configuration.php'; + if (file_exists($checked_writable) && !is_writable($checked_writable)) { + $notwritable[] = $checked_writable; + @chmod($checked_writable, $perm_file); } - //Second, if this fails, report an error - //--> the user will have to adjust the permissions manually + // Second, if this fails, report an error + + //--> The user would have to adjust the permissions manually if (count($notwritable) > 0) { $error = true; echo '
'; @@ -1281,24 +1288,24 @@ function display_requirements($installType, $badUpdatePath, $updatePath = '', $u echo '
'; } - // check wether a Chamilo configuration file already exists. - elseif (file_exists('../inc/conf/configuration.php')) { + // Check wether a Chamilo configuration file already exists. + elseif (file_exists(api_get_path(CONFIGURATION_PATH).'configuration.php')) { echo '
'; echo get_lang('WarningExistingDokeosInstallationDetected'); echo '
'; } - //and now display the choice buttons (go back or install) + // And now display the choice buttons (go back or install) ?>

-

+

-

+

diff --git a/main/install/install_files.inc.php b/main/install/install_files.inc.php index 4a41eee104..3841cd03bd 100755 --- a/main/install/install_files.inc.php +++ b/main/install/install_files.inc.php @@ -17,19 +17,19 @@ if (defined('SYSTEM_INSTALLATION')) { // Write the system config file - write_system_config_file('../inc/conf/configuration.php'); + write_system_config_file(api_get_path(CONFIGURATION_PATH).'configuration.php'); // Write a distribution file with the config as a backup for the admin - write_system_config_file('../inc/conf/configuration.dist.php'); + write_system_config_file(api_get_path(CONFIGURATION_PATH).'configuration.dist.php'); // Write a .htaccess file in the course repository write_courses_htaccess_file($urlAppendPath); // Copy distribution files with renaming for being the actual system configuration files. - copy('../inc/conf/add_course.conf.dist.php', '../inc/conf/add_course.conf.php'); - copy('../inc/conf/course_info.conf.dist.php', '../inc/conf/course_info.conf.php'); - copy('../inc/conf/mail.conf.dist.php', '../inc/conf/mail.conf.php'); - copy('../inc/conf/profile.conf.dist.php', '../inc/conf/profile.conf.php'); + copy(api_get_path(CONFIGURATION_PATH).'add_course.conf.dist.php', api_get_path(CONFIGURATION_PATH).'add_course.conf.php'); + copy(api_get_path(CONFIGURATION_PATH).'course_info.conf.dist.php', api_get_path(CONFIGURATION_PATH).'course_info.conf.php'); + copy(api_get_path(CONFIGURATION_PATH).'mail.conf.dist.php', api_get_path(CONFIGURATION_PATH).'mail.conf.php'); + copy(api_get_path(CONFIGURATION_PATH).'profile.conf.dist.php', api_get_path(CONFIGURATION_PATH).'profile.conf.php'); } else { diff --git a/main/install/update-db-scorm-1.6.x-1.8.0.inc.php b/main/install/update-db-scorm-1.6.x-1.8.0.inc.php index a08d44f9db..b44b613d00 100644 --- a/main/install/update-db-scorm-1.6.x-1.8.0.inc.php +++ b/main/install/update-db-scorm-1.6.x-1.8.0.inc.php @@ -37,9 +37,9 @@ function my_get_time($time) { } // Open log file -$fh = fopen('../../archive/newscorm_'.time().'.log', 'w'); -$fh_revert = fopen('../../archive/newscorm_'.time().'_revert.log', 'w'); -$fh_res = fopen('../../archive/newscorm_'.time().'_res.log', 'w'); +$fh = fopen(api_get_path(SYS_ARCHIVE_PATH).'newscorm_'.time().'.log', 'w'); +$fh_revert = fopen(api_get_path(SYS_ARCHIVE_PATH).'newscorm_'.time().'_revert.log', 'w'); +$fh_res = fopen(api_get_path(SYS_ARCHIVE_PATH)'newscorm_'.time().'_res.log', 'w'); fwrite($fh, "-- Recording course homepages links changes to enable reverting\n"); fwrite($fh_revert, "-- Recording reverted course homepages links changes to enable reverting\n"); fwrite($fh_res, "-- Recording resulting course homepages links changes\n"); diff --git a/main/install/update-files-1.6.x-1.8.0.inc.php b/main/install/update-files-1.6.x-1.8.0.inc.php index f1ea972636..a8db12ac5d 100644 --- a/main/install/update-files-1.6.x-1.8.0.inc.php +++ b/main/install/update-files-1.6.x-1.8.0.inc.php @@ -125,9 +125,9 @@ if (defined('SYSTEM_INSTALLATION')) { } // Write the config file - write_system_config_file('../inc/conf/configuration.php'); + write_system_config_file(api_get_path(CONFIGURATION_PATH).'configuration.php'); // Write a distribution file with the config as a backup for the admin - write_system_config_file('../inc/conf/configuration.dist.php'); + write_system_config_file(api_get_path(CONFIGURATION_PATH).'configuration.dist.php'); // Write a .htaccess file in the course repository write_courses_htaccess_file($urlAppendPath); copy($updatePath.'claroline/inc/conf/add_course.conf.php', $pathForm.'main/inc/conf/add_course.conf.php'); diff --git a/main/install/update-files-1.8.3-1.8.4.inc.php b/main/install/update-files-1.8.3-1.8.4.inc.php index c94f898c6d..6bd61cf2fa 100644 --- a/main/install/update-files-1.8.3-1.8.4.inc.php +++ b/main/install/update-files-1.8.3-1.8.4.inc.php @@ -20,19 +20,19 @@ if (defined('SYSTEM_INSTALLATION')) { // Edit the configuration file - $file = file('../inc/conf/configuration.php'); - $fh = fopen('../inc/conf/configuration.php', 'w'); + $file = file(api_get_path(CONFIGURATION_PATH).'configuration.php'); + $fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w'); $found_version = false; $found_stable = false; foreach ($file as $line) { $ignore = false; - if (stristr($line, '$_configuration[\'dokeos_version\']')) { + if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) { $found_version = true; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; - } elseif (stristr($line, '$_configuration[\'dokeos_stable\']')) { + } elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) { $found_stable = true; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n"; - } elseif (stristr($line, '?>')) { + } elseif (stripos($line, '?>') !== false) { // Ignore the line $ignore = true; } diff --git a/main/install/update-files-1.8.4-1.8.5.inc.php b/main/install/update-files-1.8.4-1.8.5.inc.php index 1fbef936b4..ae1b84543c 100644 --- a/main/install/update-files-1.8.4-1.8.5.inc.php +++ b/main/install/update-files-1.8.4-1.8.5.inc.php @@ -20,19 +20,19 @@ if (defined('SYSTEM_INSTALLATION')) { // Edit the configuration file - $file = file('../inc/conf/configuration.php'); - $fh = fopen('../inc/conf/configuration.php', 'w'); + $file = file(api_get_path(CONFIGURATION_PATH).'configuration.php'); + $fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w'); $found_version = false; $found_stable = false; foreach ($file as $line) { $ignore = false; - if (stristr($line, '$_configuration[\'dokeos_version\']')) { + if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) { $found_version = true; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; - } elseif (stristr($line, '$_configuration[\'dokeos_stable\']')) { + } elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) { $found_stable = true; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n"; - } elseif (stristr($line, '?>')) { + } elseif (stripos($line, '?>') !== false) { // Ignore the line $ignore = true; } diff --git a/main/install/update-files-1.8.5-1.8.6.inc.php b/main/install/update-files-1.8.5-1.8.6.inc.php index 23e7a30d9c..172814f7fc 100644 --- a/main/install/update-files-1.8.5-1.8.6.inc.php +++ b/main/install/update-files-1.8.5-1.8.6.inc.php @@ -20,21 +20,21 @@ if (defined('SYSTEM_INSTALLATION')) { // Edit the configuration file - $file = file('../inc/conf/configuration.php'); - $fh = fopen('../inc/conf/configuration.php', 'w'); + $file = file(api_get_path(CONFIGURATION_PATH).'configuration.php'); + $fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w'); $found_version = false; $found_stable = false; foreach ($file as $line) { $ignore = false; - if (stristr($line, '$_configuration[\'dokeos_version\']')) { + if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) { $found_version = true; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; - } elseif (stristr($line, '$_configuration[\'dokeos_stable\']')) { + } elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) { $found_stable = true; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n"; - } elseif (stristr($line,'$userPasswordCrypted')) { + } elseif (stripos($line,'$userPasswordCrypted') !== false) { $line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n"; - } elseif (stristr($line, '?>')) { + } elseif (stripos($line, '?>') !== false) { // Ignore the line $ignore = true; } diff --git a/main/install/update-files-1.8.6-1.8.6.1.inc.php b/main/install/update-files-1.8.6-1.8.6.1.inc.php index 245f8bc03f..59a9bebfc3 100644 --- a/main/install/update-files-1.8.6-1.8.6.1.inc.php +++ b/main/install/update-files-1.8.6-1.8.6.1.inc.php @@ -20,21 +20,21 @@ if (defined('SYSTEM_INSTALLATION')) { // Edit the configuration file - $file = file('../inc/conf/configuration.php'); - $fh = fopen('../inc/conf/configuration.php', 'w'); + $file = file(api_get_path(CONFIGURATION_PATH).'configuration.php'); + $fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w'); $found_version = false; $found_stable = false; foreach ($file as $line) { $ignore = false; - if (stristr($line, '$_configuration[\'dokeos_version\']')) { + if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) { $found_version = true; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; - } elseif (stristr($line, '$_configuration[\'dokeos_stable\']')) { + } elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) { $found_stable = true; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n"; - } elseif (stristr($line, '$userPasswordCrypted')) { + } elseif (stripos($line, '$userPasswordCrypted') !== false) { $line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n"; - } elseif (stristr($line, '?>')) { + } elseif (stripos($line, '?>') !== false) { //ignore the line $ignore = true; } diff --git a/main/install/update-files-1.8.6.1-1.8.6.2.inc.php b/main/install/update-files-1.8.6.1-1.8.6.2.inc.php index cf2f5c4287..53846b84a0 100644 --- a/main/install/update-files-1.8.6.1-1.8.6.2.inc.php +++ b/main/install/update-files-1.8.6.1-1.8.6.2.inc.php @@ -14,21 +14,21 @@ if (defined('SYSTEM_INSTALLATION')) { // Edit the configuration file - $file = file('../inc/conf/configuration.php'); - $fh = fopen('../inc/conf/configuration.php', 'w'); + $file = file(api_get_path(CONFIGURATION_PATH).'configuration.php'); + $fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w'); $found_version = false; $found_stable = false; foreach ($file as $line) { $ignore = false; - if (stristr($line, '$_configuration[\'dokeos_version\']')) { + if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) { $found_version = true; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; - } elseif(stristr($line, '$_configuration[\'dokeos_stable\']')) { + } elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) { $found_stable = true; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n"; - } elseif(stristr($line,'$userPasswordCrypted')) { + } elseif (stripos($line,'$userPasswordCrypted') !== false) { $line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n"; - } elseif(stristr($line, '?>')) { + } elseif (stripos($line, '?>') !== false) { //ignore the line $ignore = true; } diff --git a/main/install/update-files-1.8.6.2-1.8.7.inc.php b/main/install/update-files-1.8.6.2-1.8.7.inc.php index 511e0ded03..c008f6997d 100755 --- a/main/install/update-files-1.8.6.2-1.8.7.inc.php +++ b/main/install/update-files-1.8.6.2-1.8.7.inc.php @@ -14,8 +14,8 @@ if (defined('SYSTEM_INSTALLATION')) { // Edit the configuration file - $file = file('../inc/conf/configuration.php'); - $fh = fopen('../inc/conf/configuration.php', 'w'); + $file = file(api_get_path(CONFIGURATION_PATH).'configuration.php'); + $fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w'); $found_version_old = false; $found_stable_old = false; $found_version = false;