1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 13:47:31 +02:00

Issue #4501 - Improve verification and cron table engine.

This commit is contained in:
camer0n
2023-12-05 16:05:56 -08:00
parent 84fe29cf12
commit 3d000c8dc3
3 changed files with 801 additions and 697 deletions

View File

@@ -166,7 +166,7 @@ CREATE TABLE cron (
cron_active INT(1) UNSIGNED NOT NULL, cron_active INT(1) UNSIGNED NOT NULL,
PRIMARY KEY (cron_id), PRIMARY KEY (cron_id),
UNIQUE KEY cron_function (cron_function) UNIQUE KEY cron_function (cron_function)
) ENGINE = MYISAM; ) ENGINE=InnoDB;
# Table structure for table `dblog` - db/debug/rolling # Table structure for table `dblog` - db/debug/rolling

View File

@@ -382,7 +382,7 @@ class db_verify
$maybeCharset = isset($sqlDataArr['charset'][0]) ? $sqlDataArr['charset'][0] : 'INTERNAL_ERROR:CHARSET'; $maybeCharset = isset($sqlDataArr['charset'][0]) ? $sqlDataArr['charset'][0] : 'INTERNAL_ERROR:CHARSET';
$fileData['charset'] = $this->getIntendedCharset($this->sqlFileTables[$selection]['charset'][$key]); $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 $debugA = print_r($fileFieldData,TRUE); // Extracted Field Arrays
@@ -399,10 +399,15 @@ class db_verify
if(isset($debugA) && (e_PAGE === 'db.php')) 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'> $debug = "<table class='table table-bordered table-condensed'>
<tr><td style='padding:5px;font-weight:bold'>FILE: ".$tbl." (key=".$key.")</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."</td> <td style='padding:5px;font-weight:bold'>SQL: $tbl <span class='badge'>$engineB</span> $charsetB</td>
</tr> </tr>
<tr><td style='width:50%'><pre>".$debugA."</pre></td> <tr><td style='width:50%'><pre>".$debugA."</pre></td>
<td style='width:50%'><pre>".$debugB."</pre></td></tr></table>"; <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]['_status'] |= self::STATUS_TABLE_MISMATCH_STORAGE_ENGINE;
$this->errors[$tbl]['_valid_' . self::STATUS_TABLE_MISMATCH_STORAGE_ENGINE] = $fileData['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']; $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]['_status'] |= self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET;
$this->errors[$tbl]['_valid_' . self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET] = $fileData['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) 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']) ? $errorStatus = is_int($this->errors[$tabs]['_status']) ?
$this->errors[$tabs]['_status'] : self::STATUS_TABLE_OK; $this->errors[$tabs]['_status'] : self::STATUS_TABLE_OK;
@@ -599,6 +604,10 @@ class db_verify
return $badTableCount; return $badTableCount;
} }
public function getErrors()
{
return $this->errors;
}
/** /**
* @param $fileArray * @param $fileArray
@@ -642,7 +651,7 @@ class db_verify
self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET => DBVLAN_18, self::STATUS_TABLE_MISMATCH_DEFAULT_CHARSET => DBVLAN_18,
'mismatch' => DBVLAN_8, 'mismatch' => DBVLAN_8,
'missing_field' => DBVLAN_11, 'missing_field' => DBVLAN_11,
'ok' => ADMIN_TRUE_ICON, 'ok' => defset('ADMIN_TRUE_ICON','true'),
'missing_index' => DBVLAN_25, 'missing_index' => DBVLAN_25,
); );
@@ -931,7 +940,7 @@ class db_verify
$fdata = $this->getIndex($sqlFileData); $fdata = $this->getIndex($sqlFileData);
$newval = $this->toMysql($fdata[$field],'index'); $newval = $this->toMysql($fdata[$field],'index');
} }
else elseif($mode == 'alter' || $mode === 'insert' || $mode === 'index')
{ {
$fdata = $this->getFields($sqlFileData); $fdata = $this->getFields($sqlFileData);
$newval = $this->toMysql($fdata[$field]); $newval = $this->toMysql($fdata[$field]);
@@ -971,10 +980,14 @@ class db_verify
case 'convert': case 'convert':
$showCreateTable = $this->getSqlData($table); $showCreateTable = $this->getSqlData($table);
$currentSchema = $this->getSqlFileTables($showCreateTable); $currentSchema = $this->getSqlFileTables($showCreateTable);
if ($engine != $currentSchema['engine'][0]) if($engine != $currentSchema['engine'][0])
$query .= "ALTER TABLE `".MPREFIX.$table."` ENGINE=".$engine.";"; {
if ($charset != $currentSchema['charset'][0]) $query .= "ALTER TABLE `" . MPREFIX . $table . "` ENGINE=" . $engine . ";";
$query .= "ALTER TABLE `".MPREFIX.$table."` CONVERT TO CHARACTER SET ".$charset.";"; }
if($charset != $currentSchema['charset'][0])
{
$query .= "ALTER TABLE `" . MPREFIX . $table . "` CONVERT TO CHARACTER SET " . $charset . ";";
}
break; break;
} }
@@ -1074,7 +1087,9 @@ class db_verify
$sql_data = preg_replace("#\/\*.*?\*\/#mis", '', $sql_data); // remove comments $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); preg_match_all($regex,$sql_data,$match);
@@ -1116,7 +1131,8 @@ class db_verify
$engine = null; $engine = null;
$charset = 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); preg_match_all($tableOptionsRegex, $rawTableOptions, $tableOptionsSplit);
$tableOptionsSplit = current($tableOptionsSplit); $tableOptionsSplit = current($tableOptionsSplit);
foreach ($tableOptionsSplit as $rawTableOption) foreach ($tableOptionsSplit as $rawTableOption)
@@ -1139,7 +1155,7 @@ class db_verify
} }
} }
$ret['engine'][] = $engine; $ret['engine'][] = str_replace('MYISAM', 'MyISAM', $engine);
$ret['charset'][] = $charset; $ret['charset'][] = $charset;
} }
@@ -1383,7 +1399,7 @@ class db_verify
</colgroup> </colgroup>
<thead> <thead>
<tr> <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> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -1408,7 +1424,7 @@ class db_verify
} }
else else
{ {
$icon = E_16_E107; $icon = defset('E_16_E107');
$name = LAN_CORE; $name = LAN_CORE;
} }
$text .= ($c === 0) ? "<tr>\n" : ''; $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 * @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 = e107::getDb();
$db->gen("SHOW ENGINES;"); $db->gen("SHOW ENGINES;");
@@ -1481,8 +1497,20 @@ class db_verify
*/ */
public function getIntendedStorageEngine($maybeStorageEngine = null) public function getIntendedStorageEngine($maybeStorageEngine = null)
{ {
if ($maybeStorageEngine === null)
if($maybeStorageEngine === null)
{
return $this->getIntendedStorageEngine(self::MOST_PREFERRED_STORAGE_ENGINE); 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)) if (!array_key_exists($maybeStorageEngine, $this->storageEnginePreferenceMap))
{ {

View File

@@ -1,5 +1,5 @@
<?php <?php
/** /**
* e107 website system * e107 website system
* *
* Copyright (C) 2008-2018 e107 Inc (e107.org) * Copyright (C) 2008-2018 e107 Inc (e107.org)
@@ -9,22 +9,22 @@
*/ */
class db_verifyTest extends \Codeception\Test\Unit class db_verifyTest extends \Codeception\Test\Unit
{ {
/** @var db_verify */ /** @var db_verify */
private $dbv; private $dbv;
protected function _before() protected function _before()
{ {
require_once(e_HANDLER."db_verify_class.php"); require_once(e_HANDLER . "db_verify_class.php");
try try
{ {
$this->dbv = $this->make('db_verify'); $this->dbv = $this->make('db_verify');
} }
catch (Exception $e) catch(Exception $e)
{ {
$this->fail("Couldn't load db_verify object"); self::fail("Couldn't load db_verify object");
} }
$this->dbv->__construct(); $this->dbv->__construct();
@@ -53,9 +53,9 @@
e107_name varchar(100) NOT NULL default '', e107_name varchar(100) NOT NULL default '',
PRIMARY KEY (table_id)"; PRIMARY KEY (table_id)";
$expected = array ( $expected = array(
'table_id' => 'table_id' =>
array ( array(
'type' => 'INT', 'type' => 'INT',
'value' => '10', 'value' => '10',
'attributes' => 'UNSIGNED', 'attributes' => 'UNSIGNED',
@@ -63,7 +63,7 @@
'default' => 'AUTO_INCREMENT', 'default' => 'AUTO_INCREMENT',
), ),
'table_name' => 'table_name' =>
array ( array(
'type' => 'VARCHAR', 'type' => 'VARCHAR',
'value' => '100', 'value' => '100',
'attributes' => '', 'attributes' => '',
@@ -71,7 +71,7 @@
'default' => 'DEFAULT \'\'', 'default' => 'DEFAULT \'\'',
), ),
'table_email' => 'table_email' =>
array ( array(
'type' => 'VARCHAR', 'type' => 'VARCHAR',
'value' => '100', 'value' => '100',
'attributes' => '', 'attributes' => '',
@@ -79,7 +79,7 @@
'default' => 'DEFAULT \'\'', 'default' => 'DEFAULT \'\'',
), ),
'table_user' => 'table_user' =>
array ( array(
'type' => 'INT', 'type' => 'INT',
'value' => '10', 'value' => '10',
'attributes' => 'UNSIGNED', 'attributes' => 'UNSIGNED',
@@ -87,7 +87,7 @@
'default' => 'DEFAULT \'0\'', 'default' => 'DEFAULT \'0\'',
), ),
'table_title' => 'table_title' =>
array ( array(
'type' => 'VARCHAR', 'type' => 'VARCHAR',
'value' => '200', 'value' => '200',
'attributes' => '', 'attributes' => '',
@@ -95,7 +95,7 @@
'default' => 'DEFAULT \'\'', 'default' => 'DEFAULT \'\'',
), ),
'table_category' => 'table_category' =>
array ( array(
'type' => 'TINYINT', 'type' => 'TINYINT',
'value' => '3', 'value' => '3',
'attributes' => 'UNSIGNED', 'attributes' => 'UNSIGNED',
@@ -103,7 +103,7 @@
'default' => 'DEFAULT \'0\'', 'default' => 'DEFAULT \'0\'',
), ),
'table_json' => 'table_json' =>
array ( array(
'type' => 'JSON', 'type' => 'JSON',
'value' => '', 'value' => '',
'attributes' => '', 'attributes' => '',
@@ -111,7 +111,7 @@
'default' => '', 'default' => '',
), ),
'table_item' => 'table_item' =>
array ( array(
'type' => 'TEXT', 'type' => 'TEXT',
'value' => '', 'value' => '',
'attributes' => '', 'attributes' => '',
@@ -119,7 +119,7 @@
'default' => '', 'default' => '',
), ),
'table_datestamp' => 'table_datestamp' =>
array ( array(
'type' => 'INT', 'type' => 'INT',
'value' => '10', 'value' => '10',
'attributes' => 'UNSIGNED', 'attributes' => 'UNSIGNED',
@@ -127,7 +127,7 @@
'default' => 'DEFAULT \'0\'', 'default' => 'DEFAULT \'0\'',
), ),
'table_ip' => 'table_ip' =>
array ( array(
'type' => 'VARCHAR', 'type' => 'VARCHAR',
'value' => '45', 'value' => '45',
'attributes' => '', 'attributes' => '',
@@ -135,7 +135,7 @@
'default' => 'DEFAULT \'\'', 'default' => 'DEFAULT \'\'',
), ),
'table_auth' => 'table_auth' =>
array ( array(
'type' => 'TINYINT', 'type' => 'TINYINT',
'value' => '3', 'value' => '3',
'attributes' => 'UNSIGNED', 'attributes' => 'UNSIGNED',
@@ -143,7 +143,7 @@
'default' => 'DEFAULT \'0\'', 'default' => 'DEFAULT \'0\'',
), ),
'table_file' => 'table_file' =>
array ( array(
'type' => 'TEXT', 'type' => 'TEXT',
'value' => '', 'value' => '',
'attributes' => '', 'attributes' => '',
@@ -151,7 +151,7 @@
'default' => '', 'default' => '',
), ),
'table_keywords' => 'table_keywords' =>
array ( array(
'type' => 'VARCHAR', 'type' => 'VARCHAR',
'value' => '255', 'value' => '255',
'attributes' => '', 'attributes' => '',
@@ -159,7 +159,7 @@
'default' => 'DEFAULT \'\'', 'default' => 'DEFAULT \'\'',
), ),
'table_description' => 'table_description' =>
array ( array(
'type' => 'TEXT', 'type' => 'TEXT',
'value' => '', 'value' => '',
'attributes' => '', 'attributes' => '',
@@ -167,7 +167,7 @@
'default' => '', 'default' => '',
), ),
'table_summary' => 'table_summary' =>
array ( array(
'type' => 'TEXT', 'type' => 'TEXT',
'value' => '', 'value' => '',
'attributes' => '', 'attributes' => '',
@@ -175,7 +175,7 @@
'default' => '', 'default' => '',
), ),
'table_media' => 'table_media' =>
array ( array(
'type' => 'TEXT', 'type' => 'TEXT',
'value' => '', 'value' => '',
'attributes' => '', 'attributes' => '',
@@ -183,7 +183,7 @@
'default' => '', 'default' => '',
), ),
'table_email2' => 'table_email2' =>
array ( array(
'type' => 'TINYINT', 'type' => 'TINYINT',
'value' => '3', 'value' => '3',
'attributes' => 'UNSIGNED', 'attributes' => 'UNSIGNED',
@@ -191,7 +191,7 @@
'default' => 'DEFAULT \'0\'', 'default' => 'DEFAULT \'0\'',
), ),
'table_email90' => 'table_email90' =>
array ( array(
'type' => 'TINYINT', 'type' => 'TINYINT',
'value' => '3', 'value' => '3',
'attributes' => 'UNSIGNED', 'attributes' => 'UNSIGNED',
@@ -199,7 +199,7 @@
'default' => 'DEFAULT \'0\'', 'default' => 'DEFAULT \'0\'',
), ),
'e107_name' => 'e107_name' =>
array ( array(
'type' => 'VARCHAR', 'type' => 'VARCHAR',
'value' => '100', 'value' => '100',
'attributes' => '', 'attributes' => '',
@@ -209,12 +209,12 @@
); );
$actual = $this->dbv->getFields($data); $actual = $this->dbv->getFields($data);
$this->assertEquals($expected,$actual); self::assertEquals($expected, $actual);
} }
/*
/*
public function testClearCache() public function testClearCache()
{ {
@@ -244,7 +244,7 @@
{ {
} }
*/ */
public function testGetIndex() public function testGetIndex()
{ {
@@ -278,7 +278,7 @@
$result = $this->dbv->getIndex($data); $result = $this->dbv->getIndex($data);
$this->assertEquals($expected,$result); self::assertEquals($expected, $result);
} }
/** /**
@@ -325,7 +325,7 @@ EOF;
); );
$result = $this->dbv->getIndex($data); $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); $actual = $this->dbv->getFixQuery('alter', 'table', 'table_ip', $sqlFileData);
$expected = "ALTER TABLE `e107_table` CHANGE `table_ip` `table_ip` VARCHAR(45) NOT NULL DEFAULT ''"; $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); $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"; $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); $actual = $this->dbv->getFixQuery('insert', 'table', 'table_json', $sqlFileData);
$expected = "ALTER TABLE `e107_table` ADD `table_json` JSON NOT NULL AFTER table_category"; $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); $actual = $this->dbv->getFixQuery('index', 'table', 'table_email', $sqlFileData);
$expected = 'ALTER TABLE `e107_table` ADD UNIQUE `table_email` (table_email);'; $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); $actual = $this->dbv->getFixQuery('index', 'table', 'table_user', $sqlFileData);
$expected = 'ALTER TABLE `e107_table` ADD INDEX `table_user` (table_user);'; $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'); $actual = $this->dbv->getFixQuery('create', 'table', 'table_user', $sqlFileData, 'InnoDB');
$expected = 'CREATE TABLE `e107_table` (table_id int(10) unsigned NOT NULL auto_increment, $expected = 'CREATE TABLE `e107_table` (table_id int(10) unsigned NOT NULL auto_increment,
@@ -422,10 +422,10 @@ EOF;
KEY `table_user` (`table_user`) KEY `table_user` (`table_user`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;'; ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;';
$expected = str_replace("\t", "",$expected); $expected = str_replace("\t", "", $expected);
$actual = str_replace("\t", "",$actual); $actual = str_replace("\t", "", $actual);
$this->assertEquals($expected,$actual); self::assertEquals($expected, $actual);
// //
// echo $actual; // echo $actual;
@@ -437,7 +437,7 @@ EOF;
{ {
$tests = array( $tests = array(
0 => 0 =>
array ( array(
'type' => 'TINYINT', 'type' => 'TINYINT',
'value' => '3', 'value' => '3',
'attributes' => 'UNSIGNED', 'attributes' => 'UNSIGNED',
@@ -445,7 +445,7 @@ EOF;
'default' => 'DEFAULT \'0\'', 'default' => 'DEFAULT \'0\'',
), ),
1 => 1 =>
array ( array(
'type' => 'JSON', 'type' => 'JSON',
'value' => '', 'value' => '',
'attributes' => '', 'attributes' => '',
@@ -461,15 +461,16 @@ EOF;
); );
foreach($tests as $k=>$data) foreach($tests as $k => $data)
{ {
$result = $this->dbv->toMysql($data); $result = $this->dbv->toMysql($data);
$this->assertEquals($expected[$k], $result); self::assertEquals($expected[$k], $result);
} }
} }
/*
/*
public function testRunFix() public function testRunFix()
{ {
@@ -499,11 +500,12 @@ EOF;
{ {
} }
*/ */
public function testGetSqlFileTables() public function testGetSqlFileTables()
{ {
$tests = array( $tests = array(
'missing_index' => 'missing_index' =>
"CREATE TABLE `e107_submitnews` ( "CREATE TABLE `e107_submitnews` (
`submitnews_id` int(10) unsigned NOT NULL, `submitnews_id` int(10) unsigned NOT NULL,
@@ -603,18 +605,26 @@ EOF;
) ENGINE=MyISAM; ) 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;",
); );
$expected = array( $expected = array(
'missing_index' => array ( 'missing_index' => array(
'tables' => 'tables' =>
array ( array(
0 => 'submitnews', 0 => 'submitnews',
), ),
'data' => 'data' =>
array ( array(
0 => '`submitnews_id` int(10) unsigned NOT NULL, 0 => '`submitnews_id` int(10) unsigned NOT NULL,
`submitnews_name` varchar(100) NOT NULL DEFAULT \'\', `submitnews_name` varchar(100) NOT NULL DEFAULT \'\',
`submitnews_email` varchar(100) NOT NULL DEFAULT \'\', `submitnews_email` varchar(100) NOT NULL DEFAULT \'\',
@@ -632,19 +642,19 @@ EOF;
`submitnews_user` int(10) unsigned NOT NULL DEFAULT \'0\'', `submitnews_user` int(10) unsigned NOT NULL DEFAULT \'0\'',
), ),
'engine' => 'engine' =>
array ( array(
0 => 'MyISAM', 0 => 'MyISAM',
), ),
), ),
'user_extended' => array ( 'user_extended' => array(
'tables' => 'tables' =>
array ( array(
0 => 'user_extended', 0 => 'user_extended',
), ),
'data' => 'data' =>
array ( array(
0 => '`user_extended_id` int(10) unsigned NOT NULL DEFAULT \'0\', 0 => '`user_extended_id` int(10) unsigned NOT NULL DEFAULT \'0\',
`user_hidden_fields` text, `user_hidden_fields` text,
`user_country` varchar(255) DEFAULT NULL, `user_country` varchar(255) DEFAULT NULL,
@@ -658,18 +668,18 @@ EOF;
PRIMARY KEY (`user_extended_id`)', PRIMARY KEY (`user_extended_id`)',
), ),
'engine' => 'engine' =>
array ( array(
0 => 'MyISAM', 0 => 'MyISAM',
), ),
), ),
'banlist' => array ( 'banlist' => array(
'tables' => 'tables' =>
array ( array(
0 => 'banlist', 0 => 'banlist',
), ),
'data' => 'data' =>
array ( array(
0 => '`banlist_id` int(10) unsigned NOT NULL AUTO_INCREMENT, 0 => '`banlist_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`banlist_ip` varchar(100) NOT NULL DEFAULT \'\', `banlist_ip` varchar(100) NOT NULL DEFAULT \'\',
`banlist_bantype` tinyint(3) NOT NULL DEFAULT \'0\', `banlist_bantype` tinyint(3) NOT NULL DEFAULT \'0\',
@@ -684,19 +694,19 @@ EOF;
KEY `banlist_ip` (`banlist_ip`)', KEY `banlist_ip` (`banlist_ip`)',
), ),
'engine' => 'engine' =>
array ( array(
0 => 'MyISAM', 0 => 'MyISAM',
), ),
), ),
'test_json' => array ( 'test_json' => array(
'tables' => 'tables' =>
array ( array(
0 => 'test_comment', 0 => 'test_comment',
), ),
'data' => 'data' =>
array ( array(
0 => '`eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT, 0 => '`eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`eml_hash` varchar(20) NOT NULL, `eml_hash` varchar(20) NOT NULL,
`eml_datestamp` int(11) unsigned NOT NULL, `eml_datestamp` int(11) unsigned NOT NULL,
@@ -706,18 +716,18 @@ EOF;
UNIQUE KEY `eml_hash` (`eml_hash`)', UNIQUE KEY `eml_hash` (`eml_hash`)',
), ),
'engine' => 'engine' =>
array ( array(
0 => 'MyISAM', 0 => 'MyISAM',
), ),
), ),
'test_comment' => array ( 'test_comment' => array(
'tables' => 'tables' =>
array ( array(
0 => 'test_comment', 0 => 'test_comment',
), ),
'data' => 'data' =>
array ( array(
0 => '`eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT, 0 => '`eml_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`eml_hash` varchar(20) NOT NULL, `eml_hash` varchar(20) NOT NULL,
`eml_datestamp` int(11) unsigned NOT NULL, `eml_datestamp` int(11) unsigned NOT NULL,
@@ -727,20 +737,20 @@ EOF;
UNIQUE KEY `eml_hash` (`eml_hash`)', UNIQUE KEY `eml_hash` (`eml_hash`)',
), ),
'engine' => 'engine' =>
array ( array(
0 => 'InnoDB', 0 => 'InnoDB',
), ),
), ),
'multiple' => 'multiple' =>
array ( array(
'tables' => 'tables' =>
array ( array(
0 => 'plugin', 0 => 'plugin',
1 => 'rate', 1 => 'rate',
), ),
'data' => 'data' =>
array ( array(
0 => 'plugin_id int(10) unsigned NOT NULL auto_increment, 0 => 'plugin_id int(10) unsigned NOT NULL auto_increment,
plugin_name varchar(100) NOT NULL default \'\', plugin_name varchar(100) NOT NULL default \'\',
plugin_version varchar(10) NOT NULL default \'\', plugin_version varchar(10) NOT NULL default \'\',
@@ -761,14 +771,29 @@ EOF;
PRIMARY KEY (rate_id)', PRIMARY KEY (rate_id)',
), ),
'engine' => 'engine' =>
array ( array(
0 => 'MyISAM', 0 => 'MyISAM',
1 => '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); $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) foreach($expected[$table]['data'] as $k => $data)
{ {
$data = str_replace("\t", '', $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); $this->dbv->prepareResults('schedule', 'myplugin', $sqlData, $fileData);
$resultFields = $this->dbv->getResults('fields'); $resultFields = $this->dbv->getResults();
$expected = array( $expected = array(
'schedule' => 'schedule' =>
array( array(
@@ -905,9 +930,7 @@ EOF;
); );
self::assertEquals($expected, $resultFields);
$this->assertEquals($expected, $resultFields);
$resultIndices = $this->dbv->getResults('indices'); $resultIndices = $this->dbv->getResults('indices');
@@ -943,13 +966,30 @@ 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() public function testFixForm()
{ {
@@ -976,7 +1016,7 @@ EOF;
$output = $this->dbv->getCanonicalStorageEngine($input); $output = $this->dbv->getCanonicalStorageEngine($input);
$this->assertEquals($input, $output); self::assertEquals($input, $output);
} }
public function testGetCanonicalStorageEngineUnknownStorageEngine() public function testGetCanonicalStorageEngineUnknownStorageEngine()
@@ -993,51 +1033,87 @@ EOF;
$output = $this->dbv->getCanonicalCharset($input); $output = $this->dbv->getCanonicalCharset($input);
$this->assertEquals($expected, $output); self::assertEquals($expected, $output);
} }
public function testGetCanonicalCharsetOther() public function testGetCanonicalCharsetOther()
{ {
$inputs = ["latin1", "utf8mb3", "utf8mb4"]; $inputs = ["latin1", "utf8mb3", "utf8mb4"];
foreach ($inputs as $input) foreach($inputs as $input)
{ {
$output = $this->dbv->getCanonicalCharset($input); $output = $this->dbv->getCanonicalCharset($input);
$this->assertEquals($input, $output); self::assertEquals($input, $output);
} }
} }
public function testGetIntendedStorageEngine() public function testGetIntendedStorageEngine()
{ {
$output = $this->dbv->getIntendedStorageEngine("MyISAM"); $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"); $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"); $output = $this->dbv->getIntendedStorageEngine("Aria");
$this->assertContains($output, ["Aria", "Maria", "MyISAM"]); self::assertContains($output, ["Aria", "Maria", "MyISAM"]);
$output = $this->dbv->getIntendedStorageEngine("MEMORY"); $output = $this->dbv->getIntendedStorageEngine("MEMORY");
$this->assertEquals("MEMORY", $output); self::assertEquals("MEMORY", $output);
} }
public function testGetIntendedCharset() public function testGetIntendedCharset()
{ {
$output = $this->dbv->getIntendedCharset(""); $output = $this->dbv->getIntendedCharset("");
$this->assertEquals("utf8mb4", $output); self::assertEquals("utf8mb4", $output);
$output = $this->dbv->getIntendedCharset(); $output = $this->dbv->getIntendedCharset();
$this->assertEquals("utf8mb4", $output); self::assertEquals("utf8mb4", $output);
$output = $this->dbv->getIntendedCharset("utf8"); $output = $this->dbv->getIntendedCharset("utf8");
$this->assertEquals("utf8mb4", $output); self::assertEquals("utf8mb4", $output);
$output = $this->dbv->getIntendedCharset("utf8mb3"); $output = $this->dbv->getIntendedCharset("utf8mb3");
$this->assertEquals("utf8mb3", $output); self::assertEquals("utf8mb3", $output);
$output = $this->dbv->getIntendedCharset("latin1"); $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']);
} }
}