From: <nat...@us...> - 2008-09-30 16:07:23
|
Revision: 2577 http://perp.svn.sourceforge.net/perp/?rev=2577&view=rev Author: nathangray Date: 2008-09-30 16:07:09 +0000 (Tue, 30 Sep 2008) Log Message: ----------- Adjust change_table_engine() to make tables parameter optional, if not provided, all tables for the given app will be altered to InnoDB Modified Paths: -------------- trunk/perp_api/inc/class.so_perp_api.inc.php Modified: trunk/perp_api/inc/class.so_perp_api.inc.php =================================================================== --- trunk/perp_api/inc/class.so_perp_api.inc.php 2008-09-30 16:02:54 UTC (rev 2576) +++ trunk/perp_api/inc/class.so_perp_api.inc.php 2008-09-30 16:07:09 UTC (rev 2577) @@ -704,15 +704,39 @@ return $fprice; } - public function change_table_engine(&$db, Array $tables, $engine = 'InnoDB') { + public static function change_table_engine(&$db, $appname, Array $tables = array(), $engine = 'InnoDB') { if($db->Type != 'mysql' && $db->m_odb->Type != 'mysql') { return false; } + if(!method_exists($db, 'get_table_definitions') && property_exists($db, 'm_odb')) { + $use_db = $db->m_odb; + + if(count($tables) == 0) { + // Get all tables for that app + $definitions = $use_db->get_table_definitions($appname); + $tables = array_keys($definitions); + } + } elseif (count($tables) > 0) { + $use_db = $db; + } else { + throw new egw_exception_wrong_parameter('No tables provided, and unable to determine tables from ' . get_class($db)); + } + + if(!$appname) { + if(strpos($GLOBALS['egw_info']['flags']['currentapp'], 'perp_') === 0) { + $appname = $GLOBALS['egw_info']['flags']['currentapp']; + } else { + throw new egw_exception_wrong_parameter('Invalid appname, change_table_engine only works with pERP applications'); + } + } + + $alter = 'ALTER TABLE %s ENGINE = InnoDB'; // If using MySQL, need to specify InnoDB tables foreach($tables as $table) { $alter_query = sprintf($alter, $table); +echo $alter_query . '<br />'; $db->query($alter_query); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |