1
wishcraft
xoops 2.6.0 --> upgrade script for MySQL Engine=MyISAM to Engine=InnoDB

/**
 * 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...
Resized Image
http://www.ohloh.net/accounts/226400

Follow, Like & Read:-

twitter.com/RegaltyFamily
github.com/Chronolabs-Cooperative
facebook.com/DrAntonyRoberts

Login

Who's Online

317 user(s) are online (109 user(s) are browsing Support Forums)


Members: 0


Guests: 317


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits