|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +// No need to do anything if already converted and not forcing an update |
3 | 4 | $isUTF8 = getConfig('UTF8converted'); |
4 | 5 |
|
| 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 | +} |
5 | 12 | //# convert DB to UTF-8 |
6 | 13 | if (!$GLOBALS['commandline']) { |
7 | 14 | ob_end_flush(); |
|
11 | 18 | } |
12 | 19 | } |
13 | 20 |
|
14 | | -if (isset($cline['f'])) { //# force |
15 | | - unset($isUTF8); |
16 | | -} |
17 | | - |
18 | 21 | //# check diskspace. this operation duplicates the space required. |
19 | 22 | $maxsize = 0; |
20 | | -$req = Sql_Query('select (data_length+index_length) tablesize |
| 23 | +$req = Sql_Query('select (data_length+index_length) tablesize |
21 | 24 | from information_schema.tables |
22 | 25 | where table_schema="' .$GLOBALS['database_name'].'"'); |
23 | 26 |
|
|
26 | 29 | $maxsize = $row['tablesize']; |
27 | 30 | } |
28 | 31 | } |
29 | | -$maxsize = (int) $maxsize; |
30 | | -$avail = disk_free_space('/'); //# we have no idea where MySql stores the data, so this is only a crude check and warning. |
31 | | - |
32 | 32 | $maxsize = (int) ($maxsize * 1.2); //# add another 20% |
| 33 | +$row = Sql_Fetch_Row_Query('select @@datadir'); |
| 34 | +$dataDir = $row[0]; |
| 35 | +$avail = disk_free_space($dataDir); |
33 | 36 |
|
34 | 37 | $require_confirmation = !isset($_GET['force']) || $_GET['force'] != 'yes'; |
35 | 38 |
|
|
49 | 52 |
|
50 | 53 | cl_output(s('Converting DB to use UTF-8, please wait')); |
51 | 54 |
|
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); |
73 | 56 |
|
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"'); |
82 | 65 |
|
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']; |
91 | 73 | } |
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'); |
96 | 74 | } |
| 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); |
97 | 96 | } 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'); |
100 | 98 | } |
101 | 99 |
|
102 | 100 | echo '<br/>'.s('All Done'); |
0 commit comments