Skip to content

Commit a69489b

Browse files
committed
Avoid display warning about disk space when database is already UTF8.
1 parent 4452b6b commit a69489b

File tree

1 file changed

+46
-48
lines changed

1 file changed

+46
-48
lines changed
Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<?php
22

3+
// No need to do anything if already converted and not forcing an update
34
$isUTF8 = getConfig('UTF8converted');
45

6+
if ($isUTF8 && !isset($cline['f'])) {
7+
echo s('The DB was already converted to UTF-8 on').' '.$isUTF8;
8+
cl_output(s('The DB was already converted to UTF-8 on').' '.$isUTF8);
9+
10+
return;
11+
}
512
//# convert DB to UTF-8
613
if (!$GLOBALS['commandline']) {
714
ob_end_flush();
@@ -11,13 +18,9 @@
1118
}
1219
}
1320

14-
if (isset($cline['f'])) { //# force
15-
unset($isUTF8);
16-
}
17-
1821
//# check diskspace. this operation duplicates the space required.
1922
$maxsize = 0;
20-
$req = Sql_Query('select (data_length+index_length) tablesize
23+
$req = Sql_Query('select (data_length+index_length) tablesize
2124
from information_schema.tables
2225
where table_schema="' .$GLOBALS['database_name'].'"');
2326

@@ -49,54 +52,49 @@
4952

5053
cl_output(s('Converting DB to use UTF-8, please wait'));
5154

52-
if (empty($isUTF8)) {
53-
set_time_limit(5000);
54-
55-
echo s('Converting DB to use UTF-8, please wait').'<br/>';
56-
//# convert to UTF8
57-
$dbname = $GLOBALS['database_name'];
58-
if (!empty($dbname)) {
59-
//# the conversion complains about a key length
60-
Sql_Query(sprintf('alter table '.$GLOBALS['tables']['user_blacklist_data'].' change column email email varchar(150) not null unique'));
61-
62-
$req = Sql_Query('select * from information_schema.columns where table_schema = "'.$dbname.'" and CHARACTER_SET_NAME != "utf8"');
63-
64-
$dbcolumns = array();
65-
$dbtables = array();
66-
while ($row = Sql_Fetch_Assoc($req)) {
67-
//# make sure to only change our own tables, in case we share with other applications
68-
if (in_array($row['TABLE_NAME'], array_values($GLOBALS['tables']))) {
69-
$dbcolumns[] = $row;
70-
$dbtables[$row['TABLE_NAME']] = $row['TABLE_NAME'];
71-
}
72-
}
55+
set_time_limit(5000);
7356

74-
cl_output($GLOBALS['I18N']->get('Upgrading the database to use UTF-8, please wait'));
75-
foreach ($dbtables as $dbtable) {
76-
set_time_limit(600);
77-
echo($GLOBALS['I18N']->get('Upgrading table ').' '.$dbtable).'<br/>';
78-
flush();
79-
cl_output($GLOBALS['I18N']->get('Upgrading table ').' '.$dbtable);
80-
Sql_Query(sprintf('alter table %s default charset utf8', $dbtable), 1);
81-
}
57+
echo s('Converting DB to use UTF-8, please wait').'<br/>';
58+
//# convert to UTF8
59+
$dbname = $GLOBALS['database_name'];
60+
if (!empty($dbname)) {
61+
//# the conversion complains about a key length
62+
Sql_Query(sprintf('alter table '.$GLOBALS['tables']['user_blacklist_data'].' change column email email varchar(150) not null unique'));
63+
64+
$req = Sql_Query('select * from information_schema.columns where table_schema = "'.$dbname.'" and CHARACTER_SET_NAME != "utf8"');
8265

83-
foreach ($dbcolumns as $dbcolumn) {
84-
set_time_limit(600);
85-
echo($GLOBALS['I18N']->get('Upgrading column ').' '.$dbcolumn['COLUMN_NAME']).'<br/>';
86-
flush();
87-
cl_output($GLOBALS['I18N']->get('Upgrading column ').' '.$dbcolumn['COLUMN_NAME']);
88-
Sql_Query(sprintf('alter table %s change column %s %s %s character set utf8',
89-
$dbcolumn['TABLE_NAME'], $dbcolumn['COLUMN_NAME'], $dbcolumn['COLUMN_NAME'], $dbcolumn['COLUMN_TYPE']),
90-
1);
66+
$dbcolumns = array();
67+
$dbtables = array();
68+
while ($row = Sql_Fetch_Assoc($req)) {
69+
//# make sure to only change our own tables, in case we share with other applications
70+
if (in_array($row['TABLE_NAME'], array_values($GLOBALS['tables']))) {
71+
$dbcolumns[] = $row;
72+
$dbtables[$row['TABLE_NAME']] = $row['TABLE_NAME'];
9173
}
92-
cl_output($GLOBALS['I18N']->get('upgrade to UTF-8, done'));
93-
saveConfig('UTF8converted', date('Y-m-d H:i'), 0);
94-
} else {
95-
echo s('Unable to determine the name of the database to convert');
9674
}
75+
76+
cl_output($GLOBALS['I18N']->get('Upgrading the database to use UTF-8, please wait'));
77+
foreach ($dbtables as $dbtable) {
78+
set_time_limit(600);
79+
echo($GLOBALS['I18N']->get('Upgrading table ').' '.$dbtable).'<br/>';
80+
flush();
81+
cl_output($GLOBALS['I18N']->get('Upgrading table ').' '.$dbtable);
82+
Sql_Query(sprintf('alter table %s default charset utf8', $dbtable), 1);
83+
}
84+
85+
foreach ($dbcolumns as $dbcolumn) {
86+
set_time_limit(600);
87+
echo($GLOBALS['I18N']->get('Upgrading column ').' '.$dbcolumn['COLUMN_NAME']).'<br/>';
88+
flush();
89+
cl_output($GLOBALS['I18N']->get('Upgrading column ').' '.$dbcolumn['COLUMN_NAME']);
90+
Sql_Query(sprintf('alter table %s change column %s %s %s character set utf8',
91+
$dbcolumn['TABLE_NAME'], $dbcolumn['COLUMN_NAME'], $dbcolumn['COLUMN_NAME'], $dbcolumn['COLUMN_TYPE']),
92+
1);
93+
}
94+
cl_output($GLOBALS['I18N']->get('upgrade to UTF-8, done'));
95+
saveConfig('UTF8converted', date('Y-m-d H:i'), 0);
9796
} else {
98-
echo s('The DB was already converted to UTF-8 on').' '.$isUTF8;
99-
cl_output(s('The DB was already converted to UTF-8 on').' '.$isUTF8);
97+
echo s('Unable to determine the name of the database to convert');
10098
}
10199

102100
echo '<br/>'.s('All Done');

0 commit comments

Comments
 (0)