forked from extern/egroupware
fixed not working system-charset conversation (now removed) with backup and re-install of backup with a different charset. A setable client encoding is used if availible.
This commit is contained in:
parent
e124126405
commit
341eb15afb
@ -140,9 +140,10 @@
|
||||
/**
|
||||
* Backup all data in the form of a (compressed) csv file
|
||||
*
|
||||
* @param $f resource file opened with fopen for reading
|
||||
* @param resource $f file opened with fopen for reading
|
||||
* @param boolean $convert_to_system_charset=false convert the restored data to the selected system-charset
|
||||
*/
|
||||
function restore($f)
|
||||
function restore($f,$convert_to_system_charset=false)
|
||||
{
|
||||
@set_time_limit(0);
|
||||
ini_set('auto_detect_line_endings',true);
|
||||
@ -178,12 +179,17 @@
|
||||
$charset = trim(substr($line,9));
|
||||
// needed if mbstring.func_overload > 0, else eg. substr does not work with non ascii chars
|
||||
@ini_set('mbstring.internal_encoding',$charset);
|
||||
|
||||
// set the DB's client encoding (for mysql only if api_version >= 1.0.1.019)
|
||||
if (substr($this->db->Type,0,5) != 'mysql' || !is_object($GLOBALS['egw_setup']) ||
|
||||
$api_version && !$GLOBALS['egw_setup']->alessthanb($api_version,'1.0.1.019'))
|
||||
if ((!$convert_to_system_charset || $this->db->capabilities['client_encoding']) &&
|
||||
(substr($this->db->Type,0,5) != 'mysql' || !is_object($GLOBALS['egw_setup']) ||
|
||||
$api_version && !$GLOBALS['egw_setup']->alessthanb($api_version,'1.0.1.019')))
|
||||
{
|
||||
$this->db->Link_ID->SetCharSet($charset);
|
||||
$this->schema_proc->system_charset = $charset; // so schema_proc uses it for the creation of the tables
|
||||
if (!$convert_to_system_charset)
|
||||
{
|
||||
$this->schema_proc->system_charset = $charset; // so schema_proc uses it for the creation of the tables
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -209,12 +215,31 @@
|
||||
if (feof($f)) break;
|
||||
continue;
|
||||
}
|
||||
if ($convert_to_system_charset && !$this->db->capabilities['client_encoding'])
|
||||
{
|
||||
if ($GLOBALS['egw_setup'])
|
||||
{
|
||||
if (!is_object($GLOBALS['egw_setup']->translation->sql))
|
||||
{
|
||||
$GLOBALS['egw_setup']->translation->setup_translation_sql();
|
||||
}
|
||||
$translation =& $GLOBALS['egw_setup']->translation->sql;
|
||||
}
|
||||
else
|
||||
{
|
||||
$translation =& $GLOBALS['egw']->translation;
|
||||
}
|
||||
}
|
||||
if ($table) // do we already reached the data part
|
||||
{
|
||||
$data = $this->csv_split($line,$cols);
|
||||
|
||||
if (count($data) == count($cols))
|
||||
{
|
||||
if ($convert_to_system_charset && !$this->db->capabilities['client_encoding'])
|
||||
{
|
||||
$translation->convert($data,$charset);
|
||||
}
|
||||
$this->db->insert($table,$data,False,__LINE__,__FILE__,'all-apps',true);
|
||||
}
|
||||
else
|
||||
@ -236,6 +261,16 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($convert_to_system_charset) // store the changed charset
|
||||
{
|
||||
$this->db->insert($GLOBALS['egw_setup']->config_table,array(
|
||||
'config_value' => $GLOBALS['egw_setup']->system_charset,
|
||||
),array(
|
||||
'config_app' => 'phpgwapi',
|
||||
'config_name' => 'system_charset',
|
||||
),__LINE__,__FILE__);
|
||||
}
|
||||
$this->db->transaction_commit();
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,7 @@
|
||||
'distinct_on_text' => true, // is the DB able to use DISTINCT with a text or blob column
|
||||
'like_on_text' => true, // is the DB able to use LIKE with text columns
|
||||
'name_case' => 'upper', // case of returned column- and table-names: upper, lower(pgSql), preserv(MySQL)
|
||||
'client_encoding' => false, // db uses a changeable clientencoding
|
||||
'order_on_text' => true, // is the DB able to order by a given text column, boolean or
|
||||
); // string for sprintf for a cast (eg. 'CAST(%s AS varchar)')
|
||||
|
||||
@ -330,10 +331,12 @@
|
||||
case 'mysqli':
|
||||
$this->capabilities['sub_queries'] = (float) $db_version >= 4.1;
|
||||
$this->capabilities['name_case'] = 'preserv';
|
||||
$this->capabilities['client_encoding'] = (float) $db_version >= 4.1;
|
||||
break;
|
||||
|
||||
case 'postgres':
|
||||
$this->capabilities['name_case'] = 'lower';
|
||||
$this->capabilities['client_encoding'] = (float) $db_version >= 7.4;
|
||||
break;
|
||||
|
||||
case 'mssql':
|
||||
|
@ -178,8 +178,8 @@
|
||||
|
||||
$setup_tpl->set_var('db_step_text',lang('Step %1 - Simple Application Management',1));
|
||||
$setup_tpl->set_var('lang_system_charset',lang('<b>charset to use</b> (use utf-8 if you plan to use languages with different charsets):'));
|
||||
$setup_tpl->set_var('system_charset',$GLOBALS['egw_setup']->translation->get_charsets('system_charset',
|
||||
$GLOBALS['egw_setup']->system_charset));
|
||||
$setup_tpl->set_var('system_charset',str_replace('&','&',$GLOBALS['egw_setup']->translation->get_charsets('system_charset',
|
||||
$GLOBALS['egw_setup']->system_charset)));
|
||||
|
||||
switch($GLOBALS['egw_info']['setup']['stage']['db'])
|
||||
{
|
||||
@ -246,6 +246,9 @@
|
||||
$setup_tpl->set_var('lang_restore',lang('Or you can install a previous backup.'));
|
||||
$setup_tpl->set_var('upload','<input type="file" name="uploaded" /> '.
|
||||
'<input type="submit" name="upload" value="'.htmlspecialchars(lang('install backup')).'" title="'.htmlspecialchars(lang("uploads a backup and installs it on your DB")).'" />');
|
||||
$setup_tpl->set_var('convert_checkbox','<input type="checkbox" name="convert_charset" id="convert_checkbox" value="1"/>');
|
||||
$setup_tpl->set_var('lang_convert_charset','<label for="convert_checkbox">'.
|
||||
lang('Convert backup to charset selected above').'</label>');
|
||||
$setup_tpl->parse('V_db_stage_3','B_db_stage_3');
|
||||
$db_filled_block = $setup_tpl->get_var('V_db_stage_3');
|
||||
$setup_tpl->set_var('V_db_filled_block',$db_filled_block);
|
||||
@ -317,7 +320,7 @@
|
||||
if (is_resource($f = $db_backup->fopen_backup($_FILES['uploaded']['tmp_name'],true)))
|
||||
{
|
||||
echo '<p align="center">'.lang('restore started, this might take a view minutes ...')."</p>\n".str_repeat(' ',4096);
|
||||
$db_backup->restore($f);
|
||||
$db_backup->restore($f,$_POST['convert_charset']);
|
||||
fclose($f);
|
||||
echo '<p align="center">'.lang('restore finished')."</p>\n";
|
||||
unlink($_FILES['uploaded']['tmp_name']);
|
||||
@ -551,9 +554,9 @@
|
||||
'submit',lang('Manage Languages'),
|
||||
'');
|
||||
// show system-charset and offer conversation
|
||||
$btn_manage_lang .= lang('Current system-charset is %1, click %2here%3 to change it.',
|
||||
$GLOBALS['egw_setup']->system_charset ? "'".$GLOBALS['egw_setup']->system_charset."'" : lang('not set'),
|
||||
'<a href="system_charset.php">','</a>');
|
||||
$btn_manage_lang .= lang('Current system-charset is %1.',$GLOBALS['egw_setup']->system_charset ?
|
||||
"'<b>".$GLOBALS['egw_setup']->system_charset."</b>'" : lang('not set'))."\n";
|
||||
$btn_manage_lang .= lang('To change the charset: back up your database, deinstall all applications and re-install the backup with "convert backup to charset selected" checked.');
|
||||
$setup_tpl->set_var('lang_table_data',$btn_manage_lang);
|
||||
break;
|
||||
default:
|
||||
|
@ -108,6 +108,7 @@ contain setup de enth
|
||||
continue setup de Weiter
|
||||
continue to the header admin setup de Weiter zur Headerverwaltung
|
||||
convert setup de Konvertieren
|
||||
convert backup to charset selected above setup de Konvertiere Datensicherung zu oben ausgewähltem Zeichensatz
|
||||
could not open header.inc.php for writing! setup de Konnte die Datei header.inc.php nicht zum schreiben öffen!
|
||||
country selection setup de Länderauswahl
|
||||
create setup de erstellen
|
||||
@ -123,7 +124,7 @@ created setup de erzeugt
|
||||
created header.inc.php! setup de header.inc.php erzeugt!
|
||||
creating tables setup de Erstelle Tabellen
|
||||
current system-charset setup de Aktueller Systemzeichensatz
|
||||
current system-charset is %1, click %2here%3 to change it. setup de Aktueller Systemzeichensatz ist %1, %2hier%3 klicken um ihn zu ändern.
|
||||
current system-charset is %1. setup de Aktueller Systemzeichensatz ist %1.
|
||||
current version setup de Gegenwärtige Version
|
||||
currently installed languages: %1 <br /> setup de Gegenwärtig installierte Sprachen: %1 <br />
|
||||
database instance (egw domain) setup de Datenbankinstanz (eGW Domain)
|
||||
@ -460,6 +461,7 @@ this should be around 30 bytes in length.<br />note: the default has been random
|
||||
this stage is completed<br /> setup de Dieser Schritt ist abgeschlossen<br />
|
||||
to a version it does not know about setup de auf eine Version von der nichts bekannt ist
|
||||
to allow password authentification add the following line to your pg_hba.conf (above all others) and restart postgres: setup de um Passwort Authentifizierung zu verwenden, folgende Zeile (vor allen anderen) in ihre pg_hba.conf einfügen UND postgres neu starten
|
||||
to change the charset: back up your database, deinstall all applications and re-install the backup with "convert backup to charset selected" checked. setup de Zum Ändern des Zeichensatzes: Datenbank sichern, alle Anwendungen deinstallieren und die Datensicherung mit "Konvertiere zum ausgewählten Zeichensatz" abgehakt wieder installieren.
|
||||
to setup 1 admin account and 3 demo accounts. setup de zum Anlegen von eines Administratorkontos und ggf. 3 Demo-Benutzerkonten.
|
||||
top setup de oben
|
||||
translations added setup de Übersetzungen hinzugefügt
|
||||
|
@ -108,6 +108,7 @@ contain setup en contain
|
||||
continue setup en Continue
|
||||
continue to the header admin setup en Continue to the Header Admin
|
||||
convert setup en Convert
|
||||
convert backup to charset selected above setup en Convert backup to charset selected above
|
||||
could not open header.inc.php for writing! setup en Could not open header.inc.php for writing!
|
||||
country selection setup en Country Selection
|
||||
create setup en Create
|
||||
@ -123,7 +124,7 @@ created setup en created
|
||||
created header.inc.php! setup en Created header.inc.php!
|
||||
creating tables setup en Creating Tables
|
||||
current system-charset setup en Current system-charset
|
||||
current system-charset is %1, click %2here%3 to change it. setup en Current system-charset is %1, click %2here%3 to change it.
|
||||
current system-charset is %1. setup en Current system-charset is %1.
|
||||
current version setup en Current Version
|
||||
currently installed languages: %1 <br /> setup en Currently installed languages: %1 <br />
|
||||
database instance (egw domain) setup en Database instance (eGW domain)
|
||||
@ -460,6 +461,7 @@ this should be around 30 bytes in length.<br />note: the default has been random
|
||||
this stage is completed<br /> setup en This stage is completed<br />
|
||||
to a version it does not know about setup en to a version it does not know about
|
||||
to allow password authentification add the following line to your pg_hba.conf (above all others) and restart postgres: setup en to allow password authentification add the following line to your pg_hba.conf (above all others) AND restart postgres:
|
||||
to change the charset: back up your database, deinstall all applications and re-install the backup with "convert backup to charset selected" checked. setup en To change the charset: back up your database, deinstall all applications and re-install the backup with "convert backup to charset selected" checked.
|
||||
to setup 1 admin account and 3 demo accounts. setup en to setup 1 admin account and 3 demo accounts.
|
||||
top setup en top
|
||||
translations added setup en Translations Added
|
||||
|
@ -1,214 +0,0 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* eGroupWare - Setup - change / convert system-charset *
|
||||
* http://www.eGroupWare.org *
|
||||
* Written by RalfBecker@outdoor-training.de *
|
||||
* -------------------------------------------- *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU General Public License as published by the *
|
||||
* Free Software Foundation; either version 2 of the License, or (at your *
|
||||
* option) any later version. *
|
||||
\**************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
$diagnostics = 1; // can be set to 0=non, 1=some (default for now), 2=all
|
||||
|
||||
$GLOBALS['egw_info'] = array(
|
||||
'flags' => array(
|
||||
'noheader' => True,
|
||||
'nonavbar' => True,
|
||||
'currentapp' => 'home',
|
||||
'noapi' => True
|
||||
));
|
||||
include('./inc/functions.inc.php');
|
||||
// Authorize the user to use setup app and load the database
|
||||
// Does not return unless user is authorized
|
||||
if (!$GLOBALS['egw_setup']->auth('Config') || @$_POST['cancel'])
|
||||
{
|
||||
Header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
$GLOBALS['egw_setup']->loaddb();
|
||||
|
||||
$GLOBALS['egw_setup']->translation->setup_translation_sql();
|
||||
$translation = &$GLOBALS['egw_setup']->translation->sql;
|
||||
$translation->translation(True); // to get the mbstring warnings
|
||||
|
||||
$tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup');
|
||||
$setup_tpl = CreateObject('phpgwapi.Template',$tpl_root);
|
||||
$setup_tpl->set_file(array(
|
||||
'T_head' => 'head.tpl',
|
||||
'T_footer' => 'footer.tpl',
|
||||
'T_system_charset' => 'system_charset.tpl',
|
||||
));
|
||||
|
||||
$stage_title = lang('Change system-charset');
|
||||
$stage_desc = lang('This program will convert your database to a new system-charset.');
|
||||
|
||||
if ($diagnostics || !@$_POST['convert'])
|
||||
{
|
||||
$GLOBALS['egw_setup']->html->show_header($stage_title,False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')');
|
||||
}
|
||||
if (@$_POST['convert'])
|
||||
{
|
||||
if (empty($_POST['current_charset']))
|
||||
{
|
||||
$errors[] = lang('You need to select your current charset!');
|
||||
$GLOBALS['egw_setup']->html->show_header($stage_title,False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
convert_db($_POST['current_charset'],$_POST['new_charset'],$diagnostics);
|
||||
|
||||
if (!$diagnostics)
|
||||
{
|
||||
Header('Location: index.php');
|
||||
}
|
||||
echo '<h3>'.lang("Database successfully converted from '%1' to '%2'",$_POST[current_charset],$_POST[new_charset])."</h3>\n";
|
||||
echo '<p>'.lang('Click <a href="index.php">here</a> to return to setup.')."</p>\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function convert_db($from,$to,$diagnostics=1)
|
||||
{
|
||||
if ($diagnostics) echo "<h3>Converting database from '$from' to '$to'</h3>\n";
|
||||
|
||||
@set_time_limit(0); // this might take a while
|
||||
|
||||
$db2 = $GLOBALS['egw_setup']->db;
|
||||
$setup_info = $GLOBALS['egw_setup']->detection->get_versions();
|
||||
$setup_info = $GLOBALS['egw_setup']->detection->get_db_versions($setup_info);
|
||||
// Visit each app/setup dir, look for a phpgw_lang file
|
||||
|
||||
foreach($setup_info as $app => $data)
|
||||
{
|
||||
if ($diagnostics) echo "<p><b>$app</b>: ";
|
||||
|
||||
if (!isset($data['tables']) || !count($data['tables']) ||
|
||||
!$GLOBALS['egw_setup']->app_registered($app) ||
|
||||
!($table_definitions = $db2->get_table_definitions($app)))
|
||||
{
|
||||
if ($diagnostics) echo "skipping (no tables or not installed)</p>\n";
|
||||
continue;
|
||||
}
|
||||
foreach($table_definitions as $table => $definition)
|
||||
{
|
||||
if ($diagnostics) { echo "<br />start converting table '$table' ... "; }
|
||||
$db2->set_column_definitions($definitions['fd']);
|
||||
$updates = 0;
|
||||
$GLOBALS['egw_setup']->db->query("SELECT * FROM $table",__LINE__,__FILE__);
|
||||
while($columns = $GLOBALS['egw_setup']->db->row(True))
|
||||
{
|
||||
$update = array();
|
||||
foreach($columns as $name => $data)
|
||||
{
|
||||
switch($definition['fd'][$name]['type'])
|
||||
{
|
||||
case 'char':
|
||||
case 'varchar':
|
||||
case 'text':
|
||||
case 'longtext':
|
||||
$converted = $GLOBALS['translation']->convert($data,$from,$to);
|
||||
if ($converted != $data)
|
||||
{
|
||||
$update[$name] = $converted;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (count($update))
|
||||
{
|
||||
if (count($definition['pk']))
|
||||
{
|
||||
$db2->query($query="UPDATE $table SET ".$db2->column_data_implode(',',$update)." WHERE ".$db2->column_data_implode(' AND ',$columns,True,$definition['pk']),__LINE__,__FILE__);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if we have no primary key, we need to delete and re-write the row
|
||||
$db2->query($query="DELETE FROM $table WHERE ".$db2->column_data_implode(' AND ',$columns),__LINE__,__FILE__);
|
||||
if ($diagnostics > 1) echo " $query<br />\n";
|
||||
$db2->query($query="INSERT INTO $table (".implode(',',array_keys($columns)).") VALUES (".$db2->column_data_implode(',',array_merge($columns,$update),False).")",__LINE__,__FILE__);
|
||||
}
|
||||
if ($diagnostics > 1) echo " $query<p>\n";
|
||||
++$updates;
|
||||
}
|
||||
}
|
||||
if ($diagnostics)
|
||||
{
|
||||
$GLOBALS['egw_setup']->db->query("SELECT count(*) FROM $table",__LINE__,__FILE__);
|
||||
$GLOBALS['egw_setup']->db->next_record();
|
||||
$total = $GLOBALS['egw_setup']->db->f(0);
|
||||
echo " done, $updates/$total rows updated";
|
||||
}
|
||||
}
|
||||
}
|
||||
$GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->config_table,array(
|
||||
'config_value' => $to,
|
||||
),array(
|
||||
'config_app' => 'phpgwapi',
|
||||
'config_name' => 'systemcharset',
|
||||
),__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
$setup_tpl->set_var('stage_title',$stage_title);
|
||||
$setup_tpl->set_var('stage_desc',$stage_desc);
|
||||
$setup_tpl->set_var('error_msg',is_array($errors) ? implode('<br />',$errors) : ' ');
|
||||
|
||||
$setup_tpl->set_var('lang_convert',lang('Convert'));
|
||||
$setup_tpl->set_var('lang_cancel',lang('Cancel'));
|
||||
$setup_tpl->set_var('lang_current',lang('Current system-charset'));
|
||||
$setup_tpl->set_var('lang_convert_to',lang('Charset to convert to'));
|
||||
$setup_tpl->set_var('lang_warning','<b>'.lang('Setting the system-charset to UTF-8 (unicode) allows the coexistens of data from languages of different charsets.').'</b><br />'.
|
||||
lang('If you use only languages of the same charset (eg. western european ones) you dont need to set a system-charset!'));
|
||||
|
||||
$installed_charsets = $translation->get_installed_charsets();
|
||||
if ($translation->system_charset || count($installed_charsets) == 1)
|
||||
{
|
||||
reset($installed_charsets);
|
||||
list($current_charset) = each($installed_charsets);
|
||||
if ($translation->system_charset)
|
||||
{
|
||||
$current_charset = $translation->system_charset;
|
||||
}
|
||||
$setup_tpl->set_var('current_charset',"<b>$current_charset</b>".
|
||||
"<input type=\"hidden\" name=\"current_charset\" value=\"$current_charset\" />\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
$options = '<option value="">'.lang('select one...')."</option>\n";
|
||||
foreach($installed_charsets as $charset => $description)
|
||||
{
|
||||
$options .= "<option value=\"$charset\">$description</option>\n";
|
||||
}
|
||||
$setup_tpl->set_var('current_charset',"<select name=\"current_charset\">\n$options</select>\n");
|
||||
}
|
||||
if ($translation->system_charset == 'utf-8' || count($installed_charsets) == 1)
|
||||
{
|
||||
reset($installed_charsets);
|
||||
list($other_charset) = each($installed_charsets);
|
||||
if (!$translation->system_charset || $other_charset == $translation->system_charset)
|
||||
{
|
||||
$other_charset = 'utf-8';
|
||||
}
|
||||
$setup_tpl->set_var('new_charset',"<b>$other_charset</b><input type=\"hidden\" name=\"new_charset\" value=\"$other_charset\" />\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($translation->system_charset != 'utf-8')
|
||||
{
|
||||
$options = '<option value="utf-8">'.lang('utf-8 (Unicode)')."</option>\n";
|
||||
}
|
||||
foreach($installed_charsets as $charset => $description)
|
||||
{
|
||||
if ($charset != $translation->system_charset)
|
||||
{
|
||||
$options .= "<option value=\"$charset\">$description</option>\n";
|
||||
}
|
||||
}
|
||||
$setup_tpl->set_var('new_charset',"<select name=\"new_charset\">\n$options</select>\n");
|
||||
}
|
||||
$setup_tpl->pparse('out','T_system_charset');
|
||||
$GLOBALS['egw_setup']->html->show_footer();
|
||||
?>
|
@ -72,7 +72,8 @@
|
||||
<input type="submit" name="label" value="{install}" /> {coreapps}
|
||||
<hr />
|
||||
{lang_restore}<br />
|
||||
{upload}
|
||||
{upload}<br />
|
||||
{convert_checkbox} {lang_convert_charset}
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user