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