mirror of
https://github.com/itflow-org/itflow
synced 2026-11-18 02:17:27 +00:00
Add a collation check and repair to Admin > Debug: functions/database_collation.php reads from db.sql each table's default collation and each text column's, compares them with information_schema and can give every table that differs the collation db.sql has for it, one ALTER a table with a MODIFY a column built from its SHOW CREATE TABLE line with only the collation replaced, as database 3.6.5 does, so a binary column that was flattened goes back to utf8mb4_bin too and no column type changes; the ITFlow section gains a Database collation check that warns when any table differs, and the Database card lists them under Structure a row a table, in Copy for support as well, with a Repair collations button behind a confirm; the button posts to the new admin/post/debug.php, CSRF-checked and not tied to the request so a large table is not cut off with the browser, which writes an audit log entry naming the tables changed and a warning in App Logs for each one it had to leave, a table being changed whole or not at all; tables and columns db.sql does not have are not looked at; run through the page and against the whole schema on MySQL 8.0 and MariaDB 10.11; add both to the 26.11.7 changelog section
This commit is contained in:
43
admin/post/debug.php
Normal file
43
admin/post/debug.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - POST request handler for Admin > Debug
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
if (isset($_POST['repair_database_collation'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
// Give every table whose collation isn't db.sql's the one db.sql has
|
||||
// (functions/database_collation.php). Each table changed is rebuilt, and a very large
|
||||
// one can outlast the browser or a proxy in front of it - so the work is not tied to
|
||||
// the request, and what is left if it is cut off is left whole: a table is changed
|
||||
// entirely or not at all, and Repair again carries on with the rest.
|
||||
ignore_user_abort(true);
|
||||
set_time_limit(0);
|
||||
|
||||
$repair = databaseCollationRepair();
|
||||
$changed = count($repair['changed']);
|
||||
$failed = count($repair['failed']);
|
||||
|
||||
foreach ($repair['failed'] as $table => $why) {
|
||||
logApp('Database', 'warning', "Repair collations left the table $table with the collation it had: $why");
|
||||
}
|
||||
|
||||
if ($changed) {
|
||||
logAudit("Database", "Repair", "$session_name repaired the collation of " . ($changed === 1 ? '1 table' : "$changed tables") . ": " . implode(', ', $repair['changed']));
|
||||
}
|
||||
|
||||
if ($failed) {
|
||||
flashAlert(($changed ? ($changed === 1 ? '1 table' : "$changed tables") . ' repaired. ' : '')
|
||||
. ($failed === 1 ? '1 table' : "$failed tables") . " could not be changed and " . ($failed === 1 ? 'is' : 'are') . " as before - App Logs has why.", 'error');
|
||||
} elseif ($changed) {
|
||||
flashAlert(($changed === 1 ? '1 table now has' : "$changed tables now have") . " the collation db.sql has for " . ($changed === 1 ? 'it' : 'them') . ".");
|
||||
} else {
|
||||
flashAlert("Every table already has the collation db.sql has for it.");
|
||||
}
|
||||
|
||||
redirect("debug.php#debug-database");
|
||||
}
|
||||
Reference in New Issue
Block a user