mirror of
https://github.com/e107inc/e107.git
synced 2025-08-04 21:57:51 +02:00
Issue #4501 - Improve verification and cron table engine.
This commit is contained in:
@@ -166,7 +166,7 @@ CREATE TABLE cron (
|
||||
cron_active INT(1) UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (cron_id),
|
||||
UNIQUE KEY cron_function (cron_function)
|
||||
) ENGINE = MYISAM;
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
||||
# Table structure for table `dblog` - db/debug/rolling
|
||||
|
@@ -382,7 +382,7 @@ class db_verify
|
||||
|
||||
$maybeCharset = isset($sqlDataArr['charset'][0]) ? $sqlDataArr['charset'][0] : 'INTERNAL_ERROR:CHARSET';
|
||||
$fileData['charset'] = $this->getIntendedCharset($this->sqlFileTables[$selection]['charset'][$key]);
|
||||
$sqlData['charset'] = $this->getCanonicalCharset($maybeCharset);
|
||||
$sqlData['charset'] = $sqlDataArr['charset'][0]; // check the actual charset. $this->getCanonicalCharset($maybeCharset);
|
||||
|
||||
/*
|
||||
$debugA = print_r($fileFieldData,TRUE); // Extracted Field Arrays
|
||||
@@ -399,10 +399,15 @@ class db_verify
|
||||
|
||||
if(isset($debugA) && (e_PAGE === 'db.php'))
|
||||
{
|
||||
$engineA = !empty($this->sqlFileTables[$selection]['engine'][0]) ? $this->sqlFileTables[$selection]['engine'][0] : 'unknown';
|
||||
$engineB = !empty($sqlDataArr['engine'][0]) ? $sqlDataArr['engine'][0] : 'unknown';
|
||||
|
||||
$charsetA = !empty($this->sqlFileTables[$selection]['charset'][0]) ? $this->sqlFileTables[$selection]['charset'][0] : 'not specified';
|
||||
$charsetB = !empty($sqlDataArr['charset'][0]) ? $sqlDataArr['charset'][0] : 'unknown';
|
||||
|
||||
$debug = "<table class='table table-bordered table-condensed'>
|
||||
<tr><td style='padding:5px;font-weight:bold'>FILE: ".$tbl." (key=".$key.")</td>
|
||||
<td style='padding:5px;font-weight:bold'>SQL: ".$tbl."</td>
|
||||
<tr><td style='padding:5px;font-weight:bold'>FILE: $tbl (key=$key) <span class='badge'>$engineA</span> $charsetA</td>
|
||||
<td style='padding:5px;font-weight:bold'>SQL: $tbl <span class='badge'>$engineB</span> $charsetB</td>
|
||||
</tr>
|
||||
<tr><td style='width:50%'><pre>".$debugA."</pre></td>
|
||||
<td style='width:50%'><pre>".$debugB."</pre></td></tr></table>";
|
||||
@@ -489,13 +494,13 @@ class db_verify
|
||||
|
||||
}
|
||||
|
||||
if ($fileData['engine'] != $sqlData['engine'])
|
||||
if ($fileData['engine'] !== $sqlData['engine'])
|
||||
{
|
||||
$this->errors[$tbl]['_status'] |= self::STATUS_TABLE_MISMATCH_STORAGE_ENGINE;
|
||||
$this->errors[$tbl]['_valid_' . self::STATUS_TABLE_MISMATCH_STORAGE_ENGINE] = $fileData['engine'];
|
||||
$this->errors[$tbl]['_invalid_' . self::STATUS_TABLE_MISMATCH_STORAGE_ENGINE] = $sqlData['engine'];
|
||||
}
|
||||
if ($fileData['charset'] != $sqlData['charset'])
|
||||
if ($fileData['charset'] !== $sqlData['charset'])
|
||||
{
|
||||
$this->errors[$tbl]['_status'] |= self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET;
|
||||
$this->errors[$tbl]['_valid_' . self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET] = $fileData['charset'];
|
||||
@@ -520,7 +525,7 @@ class db_verify
|
||||
{
|
||||
foreach($this->results as $tabs => $field)
|
||||
{
|
||||
$file = varset($this->results[$tabs]['_file']);
|
||||
$file = varset($this->results[$tabs]['_file'],$tabs);
|
||||
$errorStatus = is_int($this->errors[$tabs]['_status']) ?
|
||||
$this->errors[$tabs]['_status'] : self::STATUS_TABLE_OK;
|
||||
|
||||
@@ -599,6 +604,10 @@ class db_verify
|
||||
return $badTableCount;
|
||||
}
|
||||
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fileArray
|
||||
@@ -642,7 +651,7 @@ class db_verify
|
||||
self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET => DBVLAN_18,
|
||||
'mismatch' => DBVLAN_8,
|
||||
'missing_field' => DBVLAN_11,
|
||||
'ok' => ADMIN_TRUE_ICON,
|
||||
'ok' => defset('ADMIN_TRUE_ICON','true'),
|
||||
'missing_index' => DBVLAN_25,
|
||||
);
|
||||
|
||||
@@ -931,7 +940,7 @@ class db_verify
|
||||
$fdata = $this->getIndex($sqlFileData);
|
||||
$newval = $this->toMysql($fdata[$field],'index');
|
||||
}
|
||||
else
|
||||
elseif($mode == 'alter' || $mode === 'insert' || $mode === 'index')
|
||||
{
|
||||
$fdata = $this->getFields($sqlFileData);
|
||||
$newval = $this->toMysql($fdata[$field]);
|
||||
@@ -972,9 +981,13 @@ class db_verify
|
||||
$showCreateTable = $this->getSqlData($table);
|
||||
$currentSchema = $this->getSqlFileTables($showCreateTable);
|
||||
if($engine != $currentSchema['engine'][0])
|
||||
{
|
||||
$query .= "ALTER TABLE `" . MPREFIX . $table . "` ENGINE=" . $engine . ";";
|
||||
}
|
||||
if($charset != $currentSchema['charset'][0])
|
||||
{
|
||||
$query .= "ALTER TABLE `" . MPREFIX . $table . "` CONVERT TO CHARACTER SET " . $charset . ";";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1074,7 +1087,9 @@ class db_verify
|
||||
|
||||
$sql_data = preg_replace("#\/\*.*?\*\/#mis", '', $sql_data); // remove comments
|
||||
|
||||
$regex = "/CREATE TABLE (?:IF NOT EXISTS )?`?([\w]*)`?\s*?\(([^;]*)\)\s*((?:[\w\s]+=[^\s]+)+\s*)*;/i";
|
||||
// $regex = "/CREATE TABLE (?:IF NOT EXISTS )?`?([\w]*)`?\s*?\(([^;]*)\)\s*((?:[\w\s]+=[^\s]+)+\s*)*;/i";
|
||||
// $regex = "/CREATE TABLE (?:IF NOT EXISTS )?`?(\w*)`?\s*?\(([^;]*)\)\s*((?:[\w\s]+=\S+)+\s*)*;/i";
|
||||
$regex = "/CREATE TABLE (?:IF NOT EXISTS )?`?(\w*)`?\s*?\(([^;]*)\)\s*((?:[\w\s]+=[^;]+)+\s*)*;/i";
|
||||
|
||||
preg_match_all($regex,$sql_data,$match);
|
||||
|
||||
@@ -1116,7 +1131,8 @@ class db_verify
|
||||
$engine = null;
|
||||
$charset = null;
|
||||
|
||||
$tableOptionsRegex = "/([\w\s]+=[\w]+)+?\s*/";
|
||||
// $tableOptionsRegex = "/([\w\s]+=[\w]+)+?\s*/";
|
||||
$tableOptionsRegex = "/([\w\s]+=\s?\w+)+?\s*/";
|
||||
preg_match_all($tableOptionsRegex, $rawTableOptions, $tableOptionsSplit);
|
||||
$tableOptionsSplit = current($tableOptionsSplit);
|
||||
foreach ($tableOptionsSplit as $rawTableOption)
|
||||
@@ -1139,7 +1155,7 @@ class db_verify
|
||||
}
|
||||
}
|
||||
|
||||
$ret['engine'][] = $engine;
|
||||
$ret['engine'][] = str_replace('MYISAM', 'MyISAM', $engine);
|
||||
$ret['charset'][] = $charset;
|
||||
}
|
||||
|
||||
@@ -1383,7 +1399,7 @@ class db_verify
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='first form-inline' colspan='3'><label for='check-all-verify-jstarget-verify-table'>".$frm->checkbox_toggle('check-all-verify', 'verify_table', false )." ".LAN_CHECKALL.' | '.LAN_UNCHECKALL."</label></th>
|
||||
<th class='first form-inline' colspan='3'><label for='check-all-verify-jstarget-verify-table'>".$frm->checkbox_toggle('check-all-verify', 'verify_table' )." ".LAN_CHECKALL.' | '.LAN_UNCHECKALL."</label></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -1408,7 +1424,7 @@ class db_verify
|
||||
}
|
||||
else
|
||||
{
|
||||
$icon = E_16_E107;
|
||||
$icon = defset('E_16_E107');
|
||||
$name = LAN_CORE;
|
||||
}
|
||||
$text .= ($c === 0) ? "<tr>\n" : '';
|
||||
@@ -1461,7 +1477,7 @@ class db_verify
|
||||
*
|
||||
* @return string[] An unordered list of the storage engines supported by the current MySQL server
|
||||
*/
|
||||
private static function getAvailableStorageEngines()
|
||||
private function getAvailableStorageEngines()
|
||||
{
|
||||
$db = e107::getDb();
|
||||
$db->gen("SHOW ENGINES;");
|
||||
@@ -1481,8 +1497,20 @@ class db_verify
|
||||
*/
|
||||
public function getIntendedStorageEngine($maybeStorageEngine = null)
|
||||
{
|
||||
|
||||
if($maybeStorageEngine === null)
|
||||
{
|
||||
return $this->getIntendedStorageEngine(self::MOST_PREFERRED_STORAGE_ENGINE);
|
||||
}
|
||||
|
||||
if(strtoupper($maybeStorageEngine) === 'MYISAM')
|
||||
{
|
||||
$maybeStorageEngine = 'MyISAM';
|
||||
}
|
||||
elseif(strtoupper($maybeStorageEngine) === 'INNODB')
|
||||
{
|
||||
$maybeStorageEngine = 'InnoDB';
|
||||
}
|
||||
|
||||
if (!array_key_exists($maybeStorageEngine, $this->storageEnginePreferenceMap))
|
||||
{
|
||||
|
@@ -24,7 +24,7 @@
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$this->fail("Couldn't load db_verify object");
|
||||
self::fail("Couldn't load db_verify object");
|
||||
}
|
||||
|
||||
$this->dbv->__construct();
|
||||
@@ -209,11 +209,11 @@
|
||||
);
|
||||
|
||||
$actual = $this->dbv->getFields($data);
|
||||
$this->assertEquals($expected,$actual);
|
||||
|
||||
self::assertEquals($expected, $actual);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public function testClearCache()
|
||||
{
|
||||
@@ -278,7 +278,7 @@
|
||||
|
||||
|
||||
$result = $this->dbv->getIndex($data);
|
||||
$this->assertEquals($expected,$result);
|
||||
self::assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,7 +325,7 @@ EOF;
|
||||
);
|
||||
|
||||
$result = $this->dbv->getIndex($data);
|
||||
$this->assertEquals($expected,$result);
|
||||
self::assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -381,24 +381,24 @@ EOF;
|
||||
|
||||
$actual = $this->dbv->getFixQuery('alter', 'table', 'table_ip', $sqlFileData);
|
||||
$expected = "ALTER TABLE `e107_table` CHANGE `table_ip` `table_ip` VARCHAR(45) NOT NULL DEFAULT ''";
|
||||
$this->assertEquals($expected,$actual);
|
||||
self::assertEquals($expected, $actual);
|
||||
|
||||
|
||||
$actual = $this->dbv->getFixQuery('insert', 'table', 'table_auth', $sqlFileData);
|
||||
$expected = "ALTER TABLE `e107_table` ADD `table_auth` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER table_ip";
|
||||
$this->assertEquals($expected,$actual);
|
||||
self::assertEquals($expected, $actual);
|
||||
|
||||
$actual = $this->dbv->getFixQuery('insert', 'table', 'table_json', $sqlFileData);
|
||||
$expected = "ALTER TABLE `e107_table` ADD `table_json` JSON NOT NULL AFTER table_category";
|
||||
$this->assertEquals($expected,$actual);
|
||||
self::assertEquals($expected, $actual);
|
||||
|
||||
$actual = $this->dbv->getFixQuery('index', 'table', 'table_email', $sqlFileData);
|
||||
$expected = 'ALTER TABLE `e107_table` ADD UNIQUE `table_email` (table_email);';
|
||||
$this->assertEquals($expected,$actual);
|
||||
self::assertEquals($expected, $actual);
|
||||
|
||||
$actual = $this->dbv->getFixQuery('index', 'table', 'table_user', $sqlFileData);
|
||||
$expected = 'ALTER TABLE `e107_table` ADD INDEX `table_user` (table_user);';
|
||||
$this->assertEquals($expected,$actual);
|
||||
self::assertEquals($expected, $actual);
|
||||
|
||||
$actual = $this->dbv->getFixQuery('create', 'table', 'table_user', $sqlFileData, 'InnoDB');
|
||||
$expected = 'CREATE TABLE `e107_table` (table_id int(10) unsigned NOT NULL auto_increment,
|
||||
@@ -425,7 +425,7 @@ EOF;
|
||||
$expected = str_replace("\t", "", $expected);
|
||||
$actual = str_replace("\t", "", $actual);
|
||||
|
||||
$this->assertEquals($expected,$actual);
|
||||
self::assertEquals($expected, $actual);
|
||||
|
||||
//
|
||||
// echo $actual;
|
||||
@@ -464,11 +464,12 @@ EOF;
|
||||
foreach($tests as $k => $data)
|
||||
{
|
||||
$result = $this->dbv->toMysql($data);
|
||||
$this->assertEquals($expected[$k], $result);
|
||||
self::assertEquals($expected[$k], $result);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public function testRunFix()
|
||||
{
|
||||
@@ -504,6 +505,7 @@ EOF;
|
||||
{
|
||||
$tests = array(
|
||||
|
||||
|
||||
'missing_index' =>
|
||||
"CREATE TABLE `e107_submitnews` (
|
||||
`submitnews_id` int(10) unsigned NOT NULL,
|
||||
@@ -603,6 +605,14 @@ EOF;
|
||||
) ENGINE=MyISAM;
|
||||
|
||||
",
|
||||
'syntax_variant' =>
|
||||
"CREATE TABLE e107_test (
|
||||
`test_id` int(10) unsigned NOT NULL,
|
||||
`test_name` varchar(100) not null default '',
|
||||
|
||||
`test_summary` text,
|
||||
|
||||
) ENGINE = MYISAM;",
|
||||
|
||||
);
|
||||
|
||||
@@ -765,10 +775,25 @@ EOF;
|
||||
0 => 'MyISAM',
|
||||
1 => 'MyISAM',
|
||||
),
|
||||
)
|
||||
|
||||
),
|
||||
|
||||
'syntax_variant' => array(
|
||||
'tables' =>
|
||||
array(
|
||||
0 => 'test',
|
||||
),
|
||||
'data' =>
|
||||
array(
|
||||
0 => '`test_id` int(10) unsigned NOT NULL,
|
||||
`test_name` varchar(100) not null default \'\',
|
||||
|
||||
`test_summary` text,',
|
||||
),
|
||||
'engine' =>
|
||||
array(
|
||||
0 => 'MyISAM',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -777,15 +802,15 @@ EOF;
|
||||
|
||||
$actual = $this->dbv->getSqlFileTables($sql);
|
||||
|
||||
$this->assertEquals($actual['tables'], $expected[$table]['tables'], "Table ".$table." could not be parsed.");
|
||||
self::assertEquals($expected[$table]['tables'], $actual['tables'], "Table " . $table . " could not be parsed.");
|
||||
|
||||
foreach($expected[$table]['data'] as $k => $data)
|
||||
{
|
||||
$data = str_replace("\t", '', $data);
|
||||
$this->assertEquals($actual['data'][$k], $data, "Table ".$table."['data'][".$k."] did not match.");
|
||||
self::assertEquals($data, $actual['data'][$k], "Table " . $table . "['data'][" . $k . "] did not match.");
|
||||
}
|
||||
|
||||
$this->assertEquals($actual['engine'], $expected[$table]['engine']);
|
||||
self::assertEquals($expected[$table]['engine'], $actual['engine'], "Test Key: '" . $table. "' failed on 'engine'");
|
||||
|
||||
}
|
||||
|
||||
@@ -835,7 +860,7 @@ EOF;
|
||||
|
||||
$this->dbv->prepareResults('schedule', 'myplugin', $sqlData, $fileData);
|
||||
|
||||
$resultFields = $this->dbv->getResults('fields');
|
||||
$resultFields = $this->dbv->getResults();
|
||||
$expected = array(
|
||||
'schedule' =>
|
||||
array(
|
||||
@@ -905,9 +930,7 @@ EOF;
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
$this->assertEquals($expected, $resultFields);
|
||||
self::assertEquals($expected, $resultFields);
|
||||
|
||||
|
||||
$resultIndices = $this->dbv->getResults('indices');
|
||||
@@ -943,12 +966,29 @@ EOF;
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $resultIndices);
|
||||
self::assertEquals($expected, $resultIndices);
|
||||
|
||||
$fileData['charset'] = "utf8mb4";
|
||||
$sqlData['charset'] = "utf8";
|
||||
|
||||
$result = $this->dbv->prepareResults('schedule', 'myplugin', $sqlData, $fileData);
|
||||
$resultFields = $this->dbv->getErrors();
|
||||
$expected = array (
|
||||
'schedule' =>
|
||||
array (
|
||||
'_status' => 8,
|
||||
'_file' => 'myplugin',
|
||||
'_valid_8' => 'utf8mb4',
|
||||
'_invalid_8' => 'utf8',
|
||||
),
|
||||
);
|
||||
self::assertSame($expected, $resultFields);
|
||||
self::assertSame(1, $this->dbv->errors());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
public function testFixForm()
|
||||
{
|
||||
@@ -976,7 +1016,7 @@ EOF;
|
||||
|
||||
$output = $this->dbv->getCanonicalStorageEngine($input);
|
||||
|
||||
$this->assertEquals($input, $output);
|
||||
self::assertEquals($input, $output);
|
||||
}
|
||||
|
||||
public function testGetCanonicalStorageEngineUnknownStorageEngine()
|
||||
@@ -993,7 +1033,7 @@ EOF;
|
||||
|
||||
$output = $this->dbv->getCanonicalCharset($input);
|
||||
|
||||
$this->assertEquals($expected, $output);
|
||||
self::assertEquals($expected, $output);
|
||||
}
|
||||
|
||||
public function testGetCanonicalCharsetOther()
|
||||
@@ -1004,40 +1044,76 @@ EOF;
|
||||
{
|
||||
$output = $this->dbv->getCanonicalCharset($input);
|
||||
|
||||
$this->assertEquals($input, $output);
|
||||
self::assertEquals($input, $output);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetIntendedStorageEngine()
|
||||
{
|
||||
$output = $this->dbv->getIntendedStorageEngine("MyISAM");
|
||||
$this->assertEquals("InnoDB", $output);
|
||||
self::assertEquals("InnoDB", $output);
|
||||
|
||||
$output = $this->dbv->getIntendedStorageEngine("MYISAM");
|
||||
self::assertEquals("InnoDB", $output);
|
||||
|
||||
$output = $this->dbv->getIntendedStorageEngine("InnoDB");
|
||||
$this->assertEquals("InnoDB", $output);
|
||||
self::assertEquals("InnoDB", $output);
|
||||
|
||||
$output = $this->dbv->getIntendedStorageEngine("INNODB");
|
||||
self::assertEquals("InnoDB", $output);
|
||||
|
||||
$output = $this->dbv->getIntendedStorageEngine("Aria");
|
||||
$this->assertContains($output, ["Aria", "Maria", "MyISAM"]);
|
||||
self::assertContains($output, ["Aria", "Maria", "MyISAM"]);
|
||||
|
||||
$output = $this->dbv->getIntendedStorageEngine("MEMORY");
|
||||
$this->assertEquals("MEMORY", $output);
|
||||
self::assertEquals("MEMORY", $output);
|
||||
}
|
||||
|
||||
public function testGetIntendedCharset()
|
||||
{
|
||||
$output = $this->dbv->getIntendedCharset("");
|
||||
$this->assertEquals("utf8mb4", $output);
|
||||
self::assertEquals("utf8mb4", $output);
|
||||
|
||||
$output = $this->dbv->getIntendedCharset();
|
||||
$this->assertEquals("utf8mb4", $output);
|
||||
self::assertEquals("utf8mb4", $output);
|
||||
|
||||
$output = $this->dbv->getIntendedCharset("utf8");
|
||||
$this->assertEquals("utf8mb4", $output);
|
||||
self::assertEquals("utf8mb4", $output);
|
||||
|
||||
$output = $this->dbv->getIntendedCharset("utf8mb3");
|
||||
$this->assertEquals("utf8mb3", $output);
|
||||
self::assertEquals("utf8mb3", $output);
|
||||
|
||||
$output = $this->dbv->getIntendedCharset("latin1");
|
||||
$this->assertEquals("latin1", $output);
|
||||
self::assertEquals("latin1", $output);
|
||||
}
|
||||
|
||||
/*function testGetAvailableStorageEngines()
|
||||
{
|
||||
$result = $this->dbv->getAvailableStorageEngines();
|
||||
|
||||
}*/
|
||||
|
||||
public function testRunFix()
|
||||
{
|
||||
$sql = e107::getDb();
|
||||
|
||||
// Prepare table.
|
||||
$sql->gen('ALTER TABLE `#rss` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;');
|
||||
$sql->gen('SHOW CREATE TABLE `#rss`');
|
||||
$row = $sql->rows();
|
||||
self::assertStringNotContainsString('CHARSET=utf8mb4', $row[1]['Create Table']);
|
||||
|
||||
// Fix table.
|
||||
$this->dbv->compare('rss');
|
||||
$this->dbv->compileResults();
|
||||
$this->dbv->runFix();
|
||||
|
||||
// validate table.
|
||||
$sql->gen('SHOW CREATE TABLE `#rss`');
|
||||
$row = $sql->rows();
|
||||
|
||||
self::assertStringContainsString('CHARSET=utf8mb4', $row[1]['Create Table']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user