1
/**
* Class Upgrade_2014
*/
if (!class_exists('Upgrade_MySQL_InnoDB')) {
class Upgrade_MySQL_InnoDB extends XoopsUpgrade
{
public function isApplied()
{
$applied = true;
$result = $GLOBALS['xoopsDB']->queryF('SHOW TABLES IN `' . XOOPS_DB_NAME . '` WHERE `Tables_in_' . XOOPS_DB_NAME . '` LIKE "' . XOOPS_DB_PREFIX . '%"');
while($table = $GLOBALS['xoopsDB']->fetchArray($result))
{
$createtbl = $GLOBALS['xoopsDB']->queryF('SHOW CREATE TABLE `' . $table['Tables_in_' . XOOPS_DB_NAME] . '`');
list($tbl, $create) = $GLOBALS['xoopsDB']->fetchRow($createtbl);
if (strpos(strtolower($create),'myisam'))
$applied = false;
}
return $applied;
}
public function apply()
{
$applied = true;
$result = $GLOBALS['xoopsDB']->queryF('SHOW TABLES IN `' . XOOPS_DB_NAME . '` WHERE `Tables_in_' . XOOPS_DB_NAME . '` LIKE "' . XOOPS_DB_PREFIX . '%"');
while($table = $GLOBALS['xoopsDB']->fetchArray($result))
{
$createtbl = $GLOBALS['xoopsDB']->queryF('SHOW CREATE TABLE `' . $table['Tables_in_' . XOOPS_DB_NAME] . '`');
list($tbl, $create) = $GLOBALS['xoopsDB']->fetchRow($createtbl);
if (strpos(strtolower($create),'myisam'))
{
if ($GLOBALS['xoopsDB']->queryF('RENAME TABLE `' . $tbl . '` to `old_' . $tbl . '`'))
{
if ($GLOBALS['xoopsDB']->queryF(str_replace('MyISAM', 'InnoDB', $create)))
{
$fields = array();
$fldsresult = $GLOBALS['xoopsDB']->queryF('SHOW FIELDS IN `' . $tbl . '`');
while($fldsrow = $GLOBALS['xoopsDB']->fetchArray($fldsresult))
$fields[] = $fldsrow['Field'];
$GLOBALS['xoopsDB']->queryF('START TRANSACTION');
if ($GLOBALS['xoopsDB']->queryF(die('INSERT INTO `' . $tbl . '` (`' . implode('`, `', $fields) . '`) SELECT `' . implode('`, `', $fields) .' FROM `old_' . $tbl . '`')))
$GLOBALS['xoopsDB']->queryF('DROP TABLE `old_' . $tbl . '`');
$GLOBALS['xoopsDB']->queryF('COMMIT');
} else {
$GLOBALS['xoopsDB']->queryF('RENAME TABLE `old_' . $tbl . '` to `' . $tbl . '`');
}
}
}
}
}
public function __construct()
{
parent::__construct(basename(__DIR__));
$this->task = array('database');
}
}
}
$upg = new Upgrade_MySQL_InnoDB();
return $upg;
The following code is for an /upgrade module for changing the database from engine myisam to engine innodb which is horribly more efficent and devicive, it will have to be massaged into place with the classname as patchClass name...