mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 14:17:49 +02:00
Added method to db_verify to improve testing.
This commit is contained in:
@@ -33,7 +33,7 @@ class db_verify
|
|||||||
private $internalError = false;
|
private $internalError = false;
|
||||||
|
|
||||||
var $fieldTypes = array('time','timestamp','datetime','year','tinyblob','blob',
|
var $fieldTypes = array('time','timestamp','datetime','year','tinyblob','blob',
|
||||||
'mediumblob','longblob','tinytext','mediumtext','longtext','text','date');
|
'mediumblob','longblob','tinytext','mediumtext','longtext','text','date', 'json');
|
||||||
|
|
||||||
var $fieldTypeNum = array('bit','tinyint','smallint','mediumint','integer','int','bigint',
|
var $fieldTypeNum = array('bit','tinyint','smallint','mediumint','integer','int','bigint',
|
||||||
'real','double','float','decimal','numeric','varchar','char ','binary','varbinary','enum','set'); // space after 'char' required.
|
'real','double','float','decimal','numeric','varchar','char ','binary','varbinary','enum','set'); // space after 'char' required.
|
||||||
@@ -639,7 +639,7 @@ class db_verify
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function toMysql($data,$mode = 'field')
|
public function toMysql($data,$mode = 'field')
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!$data) return;
|
if(!$data) return;
|
||||||
@@ -663,11 +663,17 @@ class db_verify
|
|||||||
|
|
||||||
if(!in_array(strtolower($data['type']), $this->fieldTypes))
|
if(!in_array(strtolower($data['type']), $this->fieldTypes))
|
||||||
{
|
{
|
||||||
return $data['type']."(".$data['value'].") ".$data['attributes']." ".$data['null']." ".$data['default'];
|
$ret = $data['type']."(".$data['value'].") ".$data['attributes']." ".$data['null']." ".$data['default'];
|
||||||
|
return trim($ret);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $data['type']." ".$data['attributes']." ".$data['null']." ".$data['default'];
|
$ret = $data['type'];
|
||||||
|
$ret .= !empty($data['attributes']) ? " ".$data['attributes'] : '';
|
||||||
|
$ret .= !empty($data['null']) ? " ".$data['null'] : '';
|
||||||
|
$ret .= !empty($data['default']) ? " ".$data['default'] : '';
|
||||||
|
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -708,43 +714,26 @@ class db_verify
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix tables
|
* @param string $mode index|alter|insert|drop|create|indexdrop
|
||||||
* FixArray eg. [core][table][field] = alter|create|index| etc.
|
* @param string $table eg. submitnews
|
||||||
|
* @param string $field eg. submitnews_id
|
||||||
|
* @param string $sqlFileData (after CREATE) eg. dblog_id int(10) unsigned NOT NULL auto_increment, ..... KEY....
|
||||||
|
* @param int $id
|
||||||
|
* @return string SQL query
|
||||||
*/
|
*/
|
||||||
function runFix($fixArray='')
|
function getFixQuery($mode,$table,$field,$sqlFileData)
|
||||||
{
|
|
||||||
$mes = e107::getMessage();
|
|
||||||
$log = e107::getAdminLog();
|
|
||||||
|
|
||||||
if(!is_array($fixArray))
|
|
||||||
{
|
|
||||||
$fixArray = $this->fixList; // Fix All
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
foreach($fixArray as $j=>$file)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach($file as $table=>$val)
|
|
||||||
{
|
|
||||||
|
|
||||||
$id = $this->getId($this->sqlFileTables[$j]['tables'],$table);
|
|
||||||
$toFix = count($val);
|
|
||||||
|
|
||||||
foreach($val as $field=>$fixes)
|
|
||||||
{
|
|
||||||
foreach($fixes as $mode)
|
|
||||||
{
|
|
||||||
if(substr($mode,0,5)== 'index')
|
if(substr($mode,0,5)== 'index')
|
||||||
{
|
{
|
||||||
$fdata = $this->getIndex($this->sqlFileTables[$j]['data'][$id]);
|
$fdata = $this->getIndex($sqlFileData);
|
||||||
$newval = $this->toMysql($fdata[$field],'index');
|
$newval = $this->toMysql($fdata[$field],'index');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$fdata = $this->getFields($sqlFileData);
|
||||||
$fdata = $this->getFields($this->sqlFileTables[$j]['data'][$id]);
|
|
||||||
$newval = $this->toMysql($fdata[$field]);
|
$newval = $this->toMysql($fdata[$field]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -774,11 +763,48 @@ class db_verify
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'create':
|
case 'create':
|
||||||
$query = "CREATE TABLE `".MPREFIX.$table."` (".$this->sqlFileTables[$j]['data'][$id].") ENGINE=MyISAM;";
|
$query = "CREATE TABLE `".MPREFIX.$table."` (".$sqlFileData.") ENGINE=MyISAM;";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix tables
|
||||||
|
* FixArray eg. [core][table][field] = alter|create|index| etc.
|
||||||
|
*/
|
||||||
|
function runFix($fixArray='')
|
||||||
|
{
|
||||||
|
$mes = e107::getMessage();
|
||||||
|
$log = e107::getAdminLog();
|
||||||
|
|
||||||
|
if(!is_array($fixArray))
|
||||||
|
{
|
||||||
|
$fixArray = $this->fixList; // Fix All
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
foreach($fixArray as $j=>$file)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach($file as $table=>$val)
|
||||||
|
{
|
||||||
|
|
||||||
|
$id = $this->getId($this->sqlFileTables[$j]['tables'],$table);
|
||||||
|
$toFix = count($val);
|
||||||
|
|
||||||
|
foreach($val as $field=>$fixes)
|
||||||
|
{
|
||||||
|
foreach($fixes as $mode)
|
||||||
|
{
|
||||||
|
|
||||||
|
$query = $this->getFixQuery($mode,$table,$field,$this->sqlFileTables[$j]['data'][$id]);
|
||||||
|
|
||||||
|
|
||||||
// $mes->addDebug("Query: ".$query);
|
// $mes->addDebug("Query: ".$query);
|
||||||
// continue;
|
// continue;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user