Index: branches/unlabeled/unlabeled-1.6.2/core/install.php =================================================================== diff -u -r7526 -r7528 --- branches/unlabeled/unlabeled-1.6.2/core/install.php (.../install.php) (revision 7526) +++ branches/unlabeled/unlabeled-1.6.2/core/install.php (.../install.php) (revision 7528) @@ -13,6 +13,12 @@ */ define('UPGRADES_FILE', FULL_PATH.'/%sinstall/upgrades.sql'); + /** + * Format of version identificator in upgrade files + * + */ + define('VERSION_MARK', '# ===== v ([\d]+\.[\d]+\.[\d]+) ====='); + // print_pre($_POST); $install_engine = new kInstallator(); @@ -362,6 +368,9 @@ // import base data into database $this->RunSQL('/core/install/install_schema.sql'); $this->RunSQL('/core/install/install_data.sql'); + + // set module "Core" version after install (based on upgrade scripts) + $this->SetModuleVersion('Core'); break; case 'root_password': @@ -391,6 +400,9 @@ $install_file = MODULES_PATH.'/'.$module.'/install.php'; if (file_exists($install_file)) { include_once($install_file); + + // set module version after install (based on upgrade scripts) + $this->SetModuleVersion($module); } } } @@ -420,17 +432,14 @@ $upgrades_file = sprintf(UPGRADES_FILE, $module_info['Path']); $sqls = file_get_contents($upgrades_file); - $version_mark = '# ===== v '.$module_info['FromVersion'].' ====='; + $version_mark = preg_replace('/(\(.*?\))/', $module_info['FromVersion'], VERSION_MARK); $start_pos = strpos($sqls, $version_mark); $sqls = substr($sqls, $start_pos); $this->RunSQLText($sqls); // after upgrade sqls are executed update version - $sql = 'UPDATE '.TABLE_PREFIX.'Modules - SET Version = "'.$module_info['ToVersion'].'" - WHERE Name = "'.$module_name.'"'; - $this->Conn->Query($sql); + $this->SetModuleVersion($module_name, $module_info['ToVersion']); } } else { @@ -472,6 +481,27 @@ } /** + * Sets module version to passed + * + * @param string $module_name + * @param string $version + */ + function SetModuleVersion($module_name, $version = false) + { + if ($version === false) { + $version = $this->GetMaxModuleVersion($module_name); + } + + $table_prefix = $this->systemConfig['Database']['TablePrefix']; + + $sql = 'UPDATE '.$table_prefix.'Modules + SET Version = "'.$version.'" + WHERE Name = "'.$module_name.'"'; + $this->Conn->Query($sql); + } + + + /** * Sets new configuration variable value * * @param string $name @@ -524,19 +554,19 @@ exit; } - function GetModuleVersion($module_name) + function GetMaxModuleVersion($module_name) { - $upgrades_file = sprintf(UPGRADES_FILE, 'core/'); + $upgrades_file = sprintf(UPGRADES_FILE, strtolower($module_name).'/'); if (!file_exists($upgrades_file)) { // no upgrade file - return '4.0.0'; + return '4.0.1'; } $sqls = file_get_contents($upgrades_file); - $versions_found = preg_match_all('/# ===== v ([\d]+\.[\d]+\.[\d]+) =====/s', $sqls, $regs); + $versions_found = preg_match_all('/'.VERSION_MARK.'/s', $sqls, $regs); if (!$versions_found) { // upgrades file doesn't contain version definitions - return '4.0.0'; + return '4.0.1'; } return end($regs[1]); @@ -786,7 +816,7 @@ } $sqls = file_get_contents($upgrades_file); - $versions_found = preg_match_all('/# ===== v ([\d]+\.[\d]+\.[\d]+) =====/s', $sqls, $regs); + $versions_found = preg_match_all('/'.VERSION_MARK.'/s', $sqls, $regs); if (!$versions_found) { // upgrades file doesn't contain version definitions continue;