$path_to_root="..";
include_once($path_to_root . "/includes/session.inc");
-page(_("Software Upgrade"));
+if ($SysPrefs->use_popup_windows) {
+ $js = get_js_open_window(900, 500);
+}
+page(_($help_context = "Software Upgrade"), false, false, "", $js);
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");
+include_once($path_to_root . "/admin/includes/fa_patch.class.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
+$site_status = get_site_status($db_connections);
+$installers = get_installers();
- if (!isset($field))
- return 0; // table exists
+if (get_post('Upgrade'))
+{
+ $comp = get_post('select_comp');
- while( $row = db_fetch_assoc($fields))
- {
- if ($row['Field'] == $field)
+ if ($comp === '')
+ display_error(_('Select company to be upgraded.'));
+ else {
+ $patch = @$installers[$site_status[$comp]['version']];
+ if ($patch)
{
- 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.
+ if (!$patch->upgrade_company($comp, check_value('force')))
+ display_error(implode('<hr>', $patch->errors));
+ else
+ display_notification(_("Company upgraded successfully."));
+
+ $site_status = get_site_status($db_connections); // update info
+ $Ajax->activate('_page_body');
}
}
- return 2; // field not found
}
-//
-// Creates table of installer objects sorted by version.
-//
-function get_installers()
+$i = find_submit('Clear');
+if ($i != -1)
{
- global $path_to_root;
-
- $patchdir = $path_to_root."/sql/";
- $upgrades = array();
- $datadir = @opendir($patchdir);
-
- if ($datadir)
- {
- while(false !== ($fname = readdir($datadir)))
- { // check all php files but index.php
- if (!is_dir($patchdir . $fname) && ($fname != 'index.php')
- && stristr($fname, '.php') != false)
- {
- unset($install);
- include_once($patchdir . $fname);
- if (isset($install)) // add installer if found
- $upgrades[$install->version] = $install;
- }
- }
- ksort($upgrades); // sort by file name
- $upgrades = array_values($upgrades);
- }
- return $upgrades;
+ unlink(VARLOG_PATH.'/upgrade.'.$i.'.log');
+ $Ajax->activate('_page_body');
}
-//
-// Apply one differential data set.
-//
-function upgrade_step($index, $conn)
+if (get_post('_select_comp_update'))
{
- global $path_to_root, $installers;
+ $Ajax->activate('_page_body');
+}
- $inst = $installers[$index];
- $pref = $conn['tbpref'];
- $ret = true;
+start_form();
- $force = get_post('force_'.$index);
- if ($force || get_post('install_'.$index))
- {
- $state = $inst->installed($pref);
- if (!$state || $force)
- {
- if (!$inst->pre_check($pref, $force)) return false;
- $sql = $inst->sql;
-
- if ($sql != '')
- $ret &= db_import($path_to_root.'/sql/'.$sql, $conn, $force);
-
- $ret &= $inst->install($pref, $force);
- } 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;
-}
+$th = array(_("Company"), _("Table set"), _("Current version"), _("Last log"), _('Upgrade'));
+start_table(TABLESTYLE);
+table_header($th);
+$k = 0; //row colour counter
-function db_open($conn)
+$uptodate = true;
+foreach($site_status as $i => $comp)
{
- $db = mysql_connect($conn["host"] ,$conn["dbuser"], $conn["dbpassword"]);
- if (!$db)
- return false;
- if (!mysql_select_db($conn["dbname"], $db))
- return false;
- return $db;
-}
+ $status = $comp['version']==$db_version;
-$installers = get_installers();
+ alt_table_row_color($k);
-if (get_post('Upgrade'))
-{
+ label_cell($comp['name']);
+ label_cell($comp['table_set']);
+
+ label_cell($comp['version'], 'align=center' .($status ? '':' class=redfg')/*, 'class='.( $status ? 'ok' : 'error')*/);
- $ret = true;
- foreach ($db_connections as $conn)
+ $log = VARLOG_PATH.'/upgrade.'.$i.'.log';
+ if (file_exists($log))
{
- // connect to database
- if (!($db = db_open($conn)))
- {
- display_error(_("Cannot connect to database for company")
- ." '".$conn['name']."'");
- continue;
- }
- // create security backup
- db_backup($conn, 'no', 'Security backup before upgrade', $conn['tbpref']);
- // apply all upgrade data
- foreach ($installers as $i => $inst)
- {
- $ret = upgrade_step($i, $conn);
- if (!$ret)
- display_error(
- sprintf(_("Database upgrade to version %s failed for company '%s'."),
- $inst->version, $conn['name'])
- .'<br>'
- ._('You should restore company database from latest backup file'));
- }
-// db_close($conn); ?
- if (!$ret) break;
- }
- if($ret)
- { // re-read the prefs
- global $path_to_root;
- include_once($path_to_root . "/admin/db/users_db.inc");
- $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'));
- }
- $Ajax->activate('_page_body');
+ label_cell(viewer_link(_('View log'), "admin/view/view_upgrade_log.php?id=$i", null, $i, 'log.png')
+ .button('Clear'.$i, _('Clear'), _('Clear log'), ICON_DELETE), 'align=center');
+ submit_js_confirm('Clear'.$i, _("Do you really want to clear this upgrade log?"));
+ } else
+ label_cell('-', 'align=center');
+
+
+ if (!$status)
+ {
+ label_cell(radio(null, 'select_comp', $i, null, true), 'align=center');
+ $uptodate = false;
+ } else
+ label_cell(_('Up to date'));
+ end_row();
}
-start_form();
-start_table($table_style);
-$th = array(_("Version"), _("Description"), _("Sql file"), _("Install"),
- _("Force upgrade"));
-table_header($th);
+end_table();
+br();
-$k = 0; //row colour counter
-$partial = 0;
-foreach($installers as $i => $inst)
+div_start('upgrade_args');
+if (get_post('select_comp') !== '')
{
- alt_table_row_color($k);
- start_row();
- label_cell($inst->version);
- label_cell($inst->description);
- label_cell($inst->sql ? $inst->sql : '<i>'._('None').'</i>', 'align=center');
-// this is checked only for first (site admin) company,
-// but in fact we should always upgrade all data sets after
-// source upgrade.
- $check = $inst->installed(TB_PREF);
- if ($check === true)
- label_cell(_("Installed"));
- else
- if (!$check)
- check_cells(null,'install_'.$i, 0);
- else {
- label_cell("<span class=redfg>"
- . sprintf(_("Partially installed (%s)"), $check) . "</span>");
- $partial++;
- }
-
- check_cells(null,'force_'.$i, 0);
- end_row();
+ $patch = @$installers[$site_status[get_post('select_comp')]['version']];
+ if ($patch)
+ $patch->show_params(get_post('select_comp'));
}
-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();
+div_end();
+
+if ($uptodate)
+ display_note(_('All company database schemes are up to date.'));
+else {
+ if (get_post('select_comp') === '')
+ display_note(_("Select company for incremental upgrade."), 0, 1, "class='stockmankofg'");
+ submit_center('Upgrade', _('Upgrade'), true, _('Save database and perform upgrade'), 'nonajax');
}
-submit_center('Upgrade', _('Upgrade system'), true, _('Save database and perform upgrade'), 'process');
end_form();
end_page();
-?>
\ No newline at end of file