Add maintenance tasK: native -> utf8, utf8 -> utf8mb4
Note: Native to utf8 will not work if the data in the database table is actually utf8! These are helper functions for during the alpha, to make testing easier, not tasks for the beta/stable
This commit is contained in:
parent
af036ca58d
commit
be422b5e83
@ -20,6 +20,19 @@ if ($_POST['adminAction'] == "maintenanceMode") {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($_POST['adminAction'] == 'nativetoutf8') {
|
||||
# TODO: Check rights
|
||||
include S9Y_INCLUDE_PATH . 'include/functions_upgrader.inc.php';
|
||||
serendipity_upgrade_native_utf8();
|
||||
}
|
||||
|
||||
if ($_POST['adminAction'] == 'utf8toutf8mb4') {
|
||||
# TODO: Check rights
|
||||
include S9Y_INCLUDE_PATH . 'include/functions_upgrader.inc.php';
|
||||
echo serendipity_upgradeUTF8_UTF8mb4();
|
||||
}
|
||||
|
||||
switch($serendipity['GET']['adminAction']) {
|
||||
case 'integrity':
|
||||
$data['action'] = "integrity";
|
||||
@ -42,6 +55,7 @@ switch($serendipity['GET']['adminAction']) {
|
||||
$data['cleanup_template'] = $serendipity['template'];
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$data['maintenance_mode'] = serendipity_db_bool(serendipity_get_config_var("maintenanceMode", false));
|
||||
|
@ -484,6 +484,11 @@ function serendipity_upgradeUTF8_UTF8mb4() {
|
||||
$table = $table[0];
|
||||
$columns = serendipity_db_query('SHOW FULL COLUMNS FROM ' . $table);
|
||||
foreach($columns as $column) {
|
||||
if ($column['Collation'] && ( ! stristr($column['Collation'], 'utf8m4'))) {
|
||||
# if the column/table is already utf8mb4 we don't need to ugprade it, but we also do not need to stop the process. Some
|
||||
# other table might not be utf8mb4 already
|
||||
continue;
|
||||
}
|
||||
if ($column['Collation'] && ( ! ($column['Collation'] == 'utf8_unicode_ci' || $column['Collation'] == 'utf8_general_ci')) ) {
|
||||
return false;
|
||||
}
|
||||
@ -506,3 +511,39 @@ function serendipity_upgradeUTF8_UTF8mb4() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function serendipity_upgrade_native_utf8() {
|
||||
global $serendipity;
|
||||
|
||||
# are we even using mysql?
|
||||
if ($serendipity['dbType'] != 'mysqli') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (serendipity_utf8mb4_ready()) {
|
||||
# get all core tables
|
||||
$tables = serendipity_db_query("SHOW TABLES LIKE '" . str_replace('_', '\_', serendipity_db_escape_string($prefix)) . "%'");
|
||||
if (!is_array($tables)) {
|
||||
echo 'Could not analyze existing tables via SHOW TABLES, please check permissions.' . $tables;
|
||||
return false;
|
||||
}
|
||||
# now collect all their columns charsets. We want to see which ones are not utf8 already
|
||||
$targetTables = [];
|
||||
foreach ($tables as $table) {
|
||||
$table = $table[0];
|
||||
$columns = serendipity_db_query('SHOW FULL COLUMNS FROM ' . $table);
|
||||
foreach($columns as $column) {
|
||||
if ($column['Collation'] && ( ! stristr($column['Collation'], 'utf8'))) {
|
||||
$targetTables[] = $table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Good, now we can set it it utf8
|
||||
foreach ($targetTables AS $table) {
|
||||
serendipity_db_query('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -116,6 +116,39 @@
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
|
||||
{if 'siteConfiguration'|checkPermission || 'blogConfiguration'|checkPermission}
|
||||
<section id="maintenance_mode" class="equal_heights quick_list">
|
||||
<h3>MySQL: Native to UTF8</h3>
|
||||
|
||||
<p>{$CONST.NATIVE_CONVERSION_DESC}</p>
|
||||
<p><span class="msg_notice"><span class="icon-info-circled" aria-hidden="true"></span>{$CONST.NATIVE_CONVERSION_WARNING}</span></p>
|
||||
|
||||
<form method="POST" target="?">
|
||||
<input type="hidden" name="adminAction" value="nativetoutf8"/>
|
||||
<div class="form_select">
|
||||
<button type="submit">{$CONST.GO}</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="maintenance_mode" class="equal_heights quick_list">
|
||||
<h3>MySQL: UTF8 to UTF8MB4</h3>
|
||||
|
||||
<p>{$CONST.NATIVE_CONVERSION_DESC}</p>
|
||||
<p><span class="msg_notice"><span class="icon-info-circled" aria-hidden="true"></span>{$CONST.NATIVE_CONVERSION_WARNING}</span></p>
|
||||
|
||||
<form method="POST" target="?">
|
||||
<input type="hidden" name="adminAction" value="utf8toutf8mb4"/>
|
||||
<div class="form_select">
|
||||
<button type="submit">{$CONST.GO}</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
{serendipity_hookPlugin hook="backend_maintenance" hookAll="true"}
|
||||
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user