Created
June 23, 2014 14:56
-
-
Save lukefowell/437d2c5a84fbe243a35f to your computer and use it in GitHub Desktop.
PHP File to list and enable/disable Magento modules. Run from root of Magento, must be under Authentication due. Not for use on production
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cwd = getcwd(); | |
if($handle = opendir($cwd.'/app/etc/modules/')) | |
{ | |
$modules = array(); | |
while(false !== ($entry = readdir($handle))) | |
{ | |
if(preg_match('/\.xml$/', $entry)) | |
{ | |
$xml = simplexml_load_file($cwd.'/app/etc/modules/'.$entry); | |
$moduleName = str_replace('.xml', '', $entry); | |
if($xml) | |
{ | |
$result = $xml->xpath('///active'); | |
foreach($result as $found) | |
{ | |
$modules[$entry] = array( | |
'xml' => $xml, | |
'active' => (string)$found, | |
'module_name' => $moduleName | |
); | |
} | |
} | |
} | |
} | |
closedir($handle); | |
} | |
if(isset($_POST['module'])) | |
{ | |
$xml = $modules[$_POST['module'].'.xml']['xml']; | |
if($xml) | |
{ | |
$value = $xml->xpath('//active'); | |
if($_POST['status'][$_POST['module']] == 'false') | |
{ | |
$value[0][0] = 'true'; | |
} | |
else | |
{ | |
$value[0][0] = 'false'; | |
} | |
$xml->asXML($cwd.'/app/etc/modules/'.$_POST['module'].'.xml'); | |
$modules[$_POST['module'].'.xml']['xml'] = $xml; | |
$modules[$_POST['module'].'.xml']['active'] = $value[0][0]; | |
} | |
} | |
?> | |
<html> | |
<head></head> | |
<body> | |
<form action="" name="enable_disable" method="post"> | |
<table> | |
<thead> | |
<tr> | |
<th>Module Name</th> | |
<th>Status</th> | |
<th> </th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php foreach($modules as $module): ?> | |
<tr> | |
<td <?php if($module['active'] == 'false'): ?>style="color:red; font-weight:bold;"<?php endif; ?>><?php echo $module['module_name']; ?></td> | |
<td <?php if($module['active'] == 'false'): ?>style="color:red; font-weight:bold;"<?php endif; ?>><?php echo $module['active']; ?></td> | |
<td> | |
<input type="hidden" name="status[<?php echo $module['module_name']; ?>]" value="<?php echo $module['active']; ?>" /> | |
<button <?php if($module['active'] == 'false'): ?>style="color:green; font-weight:bold;"<?php endif; ?> type="submit" name="module" value="<?php echo $module['module_name']; ?>"> | |
<?php if($module['active'] == 'false'): ?> | |
Enable | |
<?php else: ?> | |
Disable | |
<?php endif; ?> | |
</button> | |
</td> | |
</tr> | |
<?php endforeach; ?> | |
</tbody> | |
</table> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment