X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Finst_upgrade.php;h=9691b22e0eedeb4aa15bf0f1bf2958d09031b11f;hb=b55f02cae98917881b488c3ac02392d0419deed5;hp=4a5106b96a2c59a6f439102eaf6b2032130ccc48;hpb=cf67cec296e611c30be010686a5ea96d730418b0;p=fa-stable.git diff --git a/admin/inst_upgrade.php b/admin/inst_upgrade.php index 4a5106b9..9691b22e 100644 --- a/admin/inst_upgrade.php +++ b/admin/inst_upgrade.php @@ -9,49 +9,17 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -$page_security = 20; +$page_security = 'SA_SOFTWAREUPGRADE'; $path_to_root=".."; include_once($path_to_root . "/includes/session.inc"); -page(_("Software Upgrade")); +page(_($help_context = "Software Upgrade")); include_once($path_to_root . "/includes/date_functions.inc"); 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) -{ - $fields = db_query("SHOW COLUMNS FROM ".$pref.$table); - if (!$fields) - return 1; // no such table or error - - 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. // @@ -68,7 +36,7 @@ function get_installers() while(false !== ($fname = readdir($datadir))) { // check all php files but index.php if (!is_dir($patchdir . $fname) && ($fname != 'index.php') - && stristr($fname, '.php') != false) + && stristr($fname, '.php') != false && $fname[0] != '.') { unset($install); include_once($patchdir . $fname); @@ -89,58 +57,54 @@ function upgrade_step($index, $conn) global $path_to_root, $installers; $inst = $installers[$index]; - $sql = $inst->sql; $pref = $conn['tbpref']; $ret = true; $force = get_post('force_'.$index); if ($force || get_post('install_'.$index)) { - if (!$inst->installed($pref) || $force) + $state = $inst->installed($pref); + if (!$state || $force) { - if (!$inst->pre_check($pref)) return false; + if (!$inst->pre_check($pref, $force)) return false; + $sql = $inst->sql; + error_log(sprintf(_("Database upgrade for company '%s' (%s:%s*) started..."), + $conn['name'], $conn['dbname'], $conn['tbpref'])); + if ($sql != '') $ret &= db_import($path_to_root.'/sql/'.$sql, $conn, $force); $ret &= $inst->install($pref, $force); - } + + error_log(_("Database upgrade finished.")); + + } else + if ($state!==true) { + display_error(_("Upgrade cannot be done because database has been already partially upgraded. Please downgrade database to clean previous version or try forced upgrade.")); + $ret = false; + } } 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 - if ($conn['tbpref'] != "") - $filename = $conn['dbname'] . "_" . $conn['tbpref'] . date("Ymd_Hi") . ".sql"; - else - $filename = $conn['dbname'] . "_" . date("Ymd_Hi") . ".sql"; - - db_export($conn, $filename, 'no', 'Security backup before upgrade', $conn['tbpref']); + // create security backup + db_backup($conn, 'no', 'Security backup before upgrade', $conn['tbpref']); // apply all upgrade data foreach ($installers as $i => $inst) { @@ -155,24 +119,27 @@ if (get_post('Upgrade')) // db_close($conn); ? if (!$ret) break; } + set_global_connection(); if($ret) { // re-read the prefs global $path_to_root; include_once($path_to_root . "/admin/db/users_db.inc"); - $user = get_user($_SESSION["wa_current_user"]->username); + $user = get_user_by_login($_SESSION["wa_current_user"]->username); $_SESSION["wa_current_user"]->prefs = new user_prefs($user); display_notification(_('All companies data has been successfully updated')); } + refresh_sys_prefs(); // re-read system setup $Ajax->activate('_page_body'); } start_form(); -start_table($table_style); +start_table(TABLESTYLE); $th = array(_("Version"), _("Description"), _("Sql file"), _("Install"), _("Force upgrade")); table_header($th); $k = 0; //row colour counter +$partial = 0; foreach($installers as $i => $inst) { alt_table_row_color($k); @@ -183,14 +150,27 @@ foreach($installers as $i => $inst) // this is checked only for first (site admin) company, // but in fact we should always upgrade all data sets after // source upgrade. - if ($inst->installed(TB_PREF)) + $check = $inst->installed(TB_PREF); + if ($check === true) label_cell(_("Installed")); - else - check_cells(null,'install_'.$i, 0); + else + if (!$check) + check_cells(null,'install_'.$i, 0); + else { + label_cell("" + . sprintf(_("Partially installed (%s)"), $check) . ""); + $partial++; + } + check_cells(null,'force_'.$i, 0); end_row(); } end_table(1); +if ($partial!=0) { + display_note(_("Database upgrades marked as partially installed cannot be installed automatically. +You have to clean database manually to enable them, or try to perform forced upgrade.")); + br(); +} submit_center('Upgrade', _('Upgrade system'), true, _('Save database and perform upgrade'), 'process'); end_form();