X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Finst_upgrade.php;h=4e7e05b43309b0f6fb1c5ebd69d641712e843646;hb=a4b28f3fedae28ea92f597e345f75911c8118639;hp=eeee26a214b88152e2a01d84e9d607643f40eeb7;hpb=3e8166c811345854e18748deb67dba48beddfc41;p=fa-stable.git diff --git a/admin/inst_upgrade.php b/admin/inst_upgrade.php index eeee26a2..4e7e05b4 100644 --- a/admin/inst_upgrade.php +++ b/admin/inst_upgrade.php @@ -20,39 +20,6 @@ include_once($path_to_root . "/admin/db/company_db.inc"); include_once($path_to_root . "/admin/db/maintenance_db.inc"); include_once($path_to_root . "/includes/ui.inc"); -// -// Checks $field existence in $table with given field $properties -// $table - table name without prefix -// $field - optional field name -// $properties - optional properties of field defined by MySQL: -// 'Type', 'Null', 'Key', 'Default', 'Extra' -// -function check_table($pref, $table, $field=null, $properties=null) -{ - $tables = @db_query("SHOW TABLES LIKE '".$pref.$table."'"); - if (!db_num_rows($tables)) - return 1; // no such table or error - - $fields = @db_query("SHOW COLUMNS FROM ".$pref.$table); - if (!isset($field)) - return 0; // table exists - - while( $row = db_fetch_assoc($fields)) - { - if ($row['Field'] == $field) - { - if (!isset($properties)) - return 0; - foreach($properties as $property => $value) - { - if ($row[$property] != $value) - return 3; // failed type/length check - } - return 0; // property check ok. - } - } - return 2; // field not found -} // // Creates table of installer objects sorted by version. // @@ -85,7 +52,7 @@ function get_installers() // // Apply one differential data set. // -function upgrade_step($index, $conn) +function upgrade_step($index, $company, $conn) { global $path_to_root, $installers; @@ -108,7 +75,7 @@ function upgrade_step($index, $conn) if ($sql != '') $ret &= db_import($path_to_root.'/sql/'.$sql, $conn, $force); - $ret &= $inst->install($pref, $force); + $ret &= $inst->install($company, $force); error_log(_("Database upgrade finished.")); @@ -121,37 +88,27 @@ function upgrade_step($index, $conn) return $ret; } -function db_open($conn) -{ - $db = mysql_connect($conn["host"] ,$conn["dbuser"], $conn["dbpassword"]); - if (!$db) - return false; - if (!mysql_select_db($conn["dbname"], $db)) - return false; - return $db; -} - $installers = get_installers(); if (get_post('Upgrade')) { $ret = true; - foreach ($db_connections as $conn) + foreach ($db_connections as $comp => $conn) { // connect to database - if (!($db = db_open($conn))) + if (!(set_global_connection($comp))) { display_error(_("Cannot connect to database for company") ." '".$conn['name']."'"); continue; } // create security backup - db_backup($conn, 'no', 'Security backup before upgrade', $conn['tbpref']); + db_backup($conn, 'no', 'Security backup before upgrade'); // apply all upgrade data foreach ($installers as $i => $inst) { - $ret = upgrade_step($i, $conn); + $ret = upgrade_step($i, $comp, $conn); if (!$ret) display_error( sprintf(_("Database upgrade to version %s failed for company '%s'."), @@ -162,6 +119,7 @@ if (get_post('Upgrade')) // db_close($conn); ? if (!$ret) break; } + set_global_connection(); if($ret) { // re-read the prefs global $path_to_root; @@ -170,8 +128,7 @@ if (get_post('Upgrade')) $_SESSION["wa_current_user"]->prefs = new user_prefs($user); display_notification(_('All companies data has been successfully updated')); } - unset($_SESSION['SysPrefs']); // re-read system setup - $_SESSION['SysPrefs'] = new sys_prefs(); + refresh_sys_prefs(); // re-read system setup $Ajax->activate('_page_body'); }