Skip to content

Commit 61e1e23

Browse files
authored
main php file added
1 parent b735a3e commit 61e1e23

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

engine_change.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/**
4+
* @package Engine Change
5+
* @author Rishi Vishwakarma www.rishinc.com
6+
* @copyright Copyright (C) 2016 www.rishinc.com
7+
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
8+
*/
9+
10+
// no direct access
11+
defined('_JEXEC') or die('Restricted access');
12+
13+
jimport('joomla.plugin.plugin');
14+
15+
class plgSystemEngine_change extends JPlugin
16+
{
17+
18+
public function onAfterInitialise()
19+
{
20+
//init vars
21+
$engine_change = $this->params->get('engine_change');
22+
$opposite = $this->getEngineType($engine_change);
23+
24+
//set database query
25+
$db = JFactory::getDbo();
26+
$query = $db->getQuery(true);
27+
$query->select('TABLE_NAME');
28+
$query->from('INFORMATION_SCHEMA.TABLES');
29+
30+
$query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"
31+
. JFactory::getConfig()->get("db")
32+
. "' AND ENGINE = '" . $opposite . "'";
33+
34+
if ($db->setQuery($query))
35+
{
36+
$results = $db->loadObjectList();
37+
}
38+
else
39+
{
40+
return;
41+
}
42+
43+
if (!empty($results))
44+
{
45+
//cycle through tables and reset the Engine
46+
foreach ($results as $result)
47+
{
48+
$tableName = $result->TABLE_NAME;
49+
$newQuery = "ALTER TABLE " . $tableName . " ENGINE=" . $engine_change;
50+
51+
try
52+
{
53+
$db->setQuery($newQuery);
54+
$db->execute();
55+
} catch (Exception $e)
56+
{
57+
/* echo $e->getMessage(); */
58+
}
59+
}
60+
}
61+
}
62+
63+
64+
//helps set init vars
65+
protected function getEngineType($ec) // var $var = engine_change
66+
{
67+
if ($ec == 'MyISAM')
68+
{
69+
return 'InnoDB';
70+
}
71+
else
72+
{
73+
return 'MyISAM';
74+
}
75+
}
76+
77+
}

0 commit comments

Comments
 (0)