Merge pull request #24507 from frederic34/repair_script
NEW repair script skip views
This commit is contained in:
commit
a30242eadc
@ -129,6 +129,17 @@ interface Database
|
|||||||
public function DDLListTables($database, $table = '');
|
public function DDLListTables($database, $table = '');
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
|
|
||||||
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
|
/**
|
||||||
|
* List tables into a database with table type
|
||||||
|
*
|
||||||
|
* @param string $database Name of database
|
||||||
|
* @param string $table Name of table filter ('xxx%')
|
||||||
|
* @return array List of tables in an array
|
||||||
|
*/
|
||||||
|
public function DDLListTablesFull($database, $table = '');
|
||||||
|
// phpcs:enable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return last request executed with query()
|
* Return last request executed with query()
|
||||||
*
|
*
|
||||||
|
|||||||
@ -716,6 +716,38 @@ class DoliDBMysqli extends DoliDB
|
|||||||
return $listtables;
|
return $listtables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
|
/**
|
||||||
|
* List tables into a database
|
||||||
|
*
|
||||||
|
* @param string $database Name of database
|
||||||
|
* @param string $table Nmae of table filter ('xxx%')
|
||||||
|
* @return array List of tables in an array
|
||||||
|
*/
|
||||||
|
public function DDLListTablesFull($database, $table = '')
|
||||||
|
{
|
||||||
|
// phpcs:enable
|
||||||
|
$listtables = array();
|
||||||
|
|
||||||
|
$like = '';
|
||||||
|
if ($table) {
|
||||||
|
$tmptable = preg_replace('/[^a-z0-9\.\-\_%]/i', '', $table);
|
||||||
|
|
||||||
|
$like = "LIKE '".$this->escape($tmptable)."'";
|
||||||
|
}
|
||||||
|
$tmpdatabase = preg_replace('/[^a-z0-9\.\-\_]/i', '', $database);
|
||||||
|
|
||||||
|
$sql = "SHOW FULL TABLES FROM `".$tmpdatabase."` ".$like.";";
|
||||||
|
|
||||||
|
$result = $this->query($sql);
|
||||||
|
if ($result) {
|
||||||
|
while ($row = $this->fetch_row($result)) {
|
||||||
|
$listtables[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $listtables;
|
||||||
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
/**
|
/**
|
||||||
* List information of columns into a table.
|
* List information of columns into a table.
|
||||||
|
|||||||
@ -977,6 +977,34 @@ class DoliDBPgsql extends DoliDB
|
|||||||
return $listtables;
|
return $listtables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
|
/**
|
||||||
|
* List tables into a database
|
||||||
|
*
|
||||||
|
* @param string $database Name of database
|
||||||
|
* @param string $table Name of table filter ('xxx%')
|
||||||
|
* @return array List of tables in an array
|
||||||
|
*/
|
||||||
|
public function DDLListTablesFull($database, $table = '')
|
||||||
|
{
|
||||||
|
// phpcs:enable
|
||||||
|
$listtables = array();
|
||||||
|
|
||||||
|
$escapedlike = '';
|
||||||
|
if ($table) {
|
||||||
|
$tmptable = preg_replace('/[^a-z0-9\.\-\_%]/i', '', $table);
|
||||||
|
|
||||||
|
$escapedlike = " AND table_name LIKE '".$this->escape($tmptable)."'";
|
||||||
|
}
|
||||||
|
$result = pg_query($this->db, "SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = 'public'".$escapedlike." ORDER BY table_name");
|
||||||
|
if ($result) {
|
||||||
|
while ($row = $this->fetch_row($result)) {
|
||||||
|
$listtables[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $listtables;
|
||||||
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
/**
|
/**
|
||||||
* List information of columns into a table.
|
* List information of columns into a table.
|
||||||
|
|||||||
@ -896,6 +896,38 @@ class DoliDBSqlite3 extends DoliDB
|
|||||||
return $listtables;
|
return $listtables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
|
/**
|
||||||
|
* List tables into a database with table type
|
||||||
|
*
|
||||||
|
* @param string $database Name of database
|
||||||
|
* @param string $table Name of table filter ('xxx%')
|
||||||
|
* @return array List of tables in an array
|
||||||
|
*/
|
||||||
|
public function DDLListTablesFull($database, $table = '')
|
||||||
|
{
|
||||||
|
// phpcs:enable
|
||||||
|
$listtables = array();
|
||||||
|
|
||||||
|
$like = '';
|
||||||
|
if ($table) {
|
||||||
|
$tmptable = preg_replace('/[^a-z0-9\.\-\_%]/i', '', $table);
|
||||||
|
|
||||||
|
$like = "LIKE '".$this->escape($tmptable)."'";
|
||||||
|
}
|
||||||
|
$tmpdatabase = preg_replace('/[^a-z0-9\.\-\_]/i', '', $database);
|
||||||
|
|
||||||
|
$sql = "SHOW FULL TABLES FROM ".$tmpdatabase." ".$like.";";
|
||||||
|
//print $sql;
|
||||||
|
$result = $this->query($sql);
|
||||||
|
if ($result) {
|
||||||
|
while ($row = $this->fetch_row($result)) {
|
||||||
|
$listtables[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $listtables;
|
||||||
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
/**
|
/**
|
||||||
* List information of columns into a table.
|
* List information of columns into a table.
|
||||||
|
|||||||
@ -205,6 +205,18 @@ class TraceableDB extends DoliDB
|
|||||||
return $this->db->DDLListTables($database, $table);
|
return $this->db->DDLListTables($database, $table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List tables into a database with table info
|
||||||
|
*
|
||||||
|
* @param string $database Name of database
|
||||||
|
* @param string $table Nmae of table filter ('xxx%')
|
||||||
|
* @return array List of tables in an array
|
||||||
|
*/
|
||||||
|
public function DDLListTablesFull($database, $table = '')
|
||||||
|
{
|
||||||
|
return $this->db->DDLListTablesFull($database, $table);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return last request executed with query()
|
* Return last request executed with query()
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1244,7 +1244,7 @@ if ($ok && GETPOST('force_utf8_on_tables', 'alpha')) {
|
|||||||
if ($db->type == "mysql" || $db->type == "mysqli") {
|
if ($db->type == "mysql" || $db->type == "mysqli") {
|
||||||
$force_utf8_on_tables = GETPOST('force_utf8_on_tables', 'alpha');
|
$force_utf8_on_tables = GETPOST('force_utf8_on_tables', 'alpha');
|
||||||
|
|
||||||
$listoftables = $db->DDLListTables($db->database_name);
|
$listoftables = $db->DDLListTablesFull($db->database_name);
|
||||||
|
|
||||||
// Disable foreign key checking for avoid errors
|
// Disable foreign key checking for avoid errors
|
||||||
if ($force_utf8_on_tables == 'confirmed') {
|
if ($force_utf8_on_tables == 'confirmed') {
|
||||||
@ -1255,14 +1255,18 @@ if ($ok && GETPOST('force_utf8_on_tables', 'alpha')) {
|
|||||||
|
|
||||||
foreach ($listoftables as $table) {
|
foreach ($listoftables as $table) {
|
||||||
// do not convert llx_const if mysql encrypt/decrypt is used
|
// do not convert llx_const if mysql encrypt/decrypt is used
|
||||||
if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match('/\_const$/', $table)) {
|
if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match('/\_const$/', $table[0])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($table[1] == 'VIEW') {
|
||||||
|
print '<tr><td colspan="2">'.$table[0].' is a '.$table[1].' (Skipped)</td></tr>';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<tr><td colspan="2">';
|
print '<tr><td colspan="2">';
|
||||||
print $table;
|
print $table[0];
|
||||||
$sql1 = "ALTER TABLE ".$table." ROW_FORMAT=dynamic";
|
$sql1 = "ALTER TABLE ".$table[0]." ROW_FORMAT=dynamic";
|
||||||
$sql2 = "ALTER TABLE ".$table." CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci";
|
$sql2 = "ALTER TABLE ".$table[0]." CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci";
|
||||||
print '<!-- '.$sql1.' -->';
|
print '<!-- '.$sql1.' -->';
|
||||||
print '<!-- '.$sql2.' -->';
|
print '<!-- '.$sql2.' -->';
|
||||||
if ($force_utf8_on_tables == 'confirmed') {
|
if ($force_utf8_on_tables == 'confirmed') {
|
||||||
@ -1297,7 +1301,7 @@ if ($ok && GETPOST('force_utf8mb4_on_tables', 'alpha')) {
|
|||||||
if ($db->type == "mysql" || $db->type == "mysqli") {
|
if ($db->type == "mysql" || $db->type == "mysqli") {
|
||||||
$force_utf8mb4_on_tables = GETPOST('force_utf8mb4_on_tables', 'alpha');
|
$force_utf8mb4_on_tables = GETPOST('force_utf8mb4_on_tables', 'alpha');
|
||||||
|
|
||||||
$listoftables = $db->DDLListTables($db->database_name);
|
$listoftables = $db->DDLListTablesFull($db->database_name);
|
||||||
|
|
||||||
// Disable foreign key checking for avoid errors
|
// Disable foreign key checking for avoid errors
|
||||||
if ($force_utf8mb4_on_tables == 'confirmed') {
|
if ($force_utf8mb4_on_tables == 'confirmed') {
|
||||||
@ -1308,14 +1312,18 @@ if ($ok && GETPOST('force_utf8mb4_on_tables', 'alpha')) {
|
|||||||
|
|
||||||
foreach ($listoftables as $table) {
|
foreach ($listoftables as $table) {
|
||||||
// do not convert llx_const if mysql encrypt/decrypt is used
|
// do not convert llx_const if mysql encrypt/decrypt is used
|
||||||
if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match('/\_const$/', $table)) {
|
if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match('/\_const$/', $table[0])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($table[1] == 'VIEW') {
|
||||||
|
print '<tr><td colspan="2">'.$table[0].' is a '.$table[1].' (Skipped)</td></tr>';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<tr><td colspan="2">';
|
print '<tr><td colspan="2">';
|
||||||
print $table;
|
print $table[0];
|
||||||
$sql1 = "ALTER TABLE ".$table." ROW_FORMAT=dynamic";
|
$sql1 = "ALTER TABLE ".$table[0]." ROW_FORMAT=dynamic";
|
||||||
$sql2 = "ALTER TABLE ".$table." CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
|
$sql2 = "ALTER TABLE ".$table[0]." CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
|
||||||
print '<!-- '.$sql1.' -->';
|
print '<!-- '.$sql1.' -->';
|
||||||
print '<!-- '.$sql2.' -->';
|
print '<!-- '.$sql2.' -->';
|
||||||
if ($force_utf8mb4_on_tables == 'confirmed') {
|
if ($force_utf8mb4_on_tables == 'confirmed') {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user