-
-
Save therouv/7749743 to your computer and use it in GitHub Desktop.
This file contains 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
class ConfigExporter extends Mage_Shell_Abstract | |
{ | |
public function run() | |
{ | |
$xml = new Varien_Simplexml_Element('<config />'); | |
foreach ($this->getConfigValues($this->getArg('path')) as $item) { | |
try { | |
$path = $this->_getConfigPath($item['scope'], $item['scope_id'], $item['path']); | |
$xml->setNode($path, $item['value']); | |
} catch (Exception $e) { | |
} | |
} | |
echo $xml->asNiceXml(); | |
} | |
protected function _getConfigPath($scope, $scopeId, $path) | |
{ | |
switch ($scope) { | |
case 'default': | |
$path = $scope . '/' . $path; | |
break; | |
case 'stores': | |
$store = Mage::app()->getStore($scopeId); | |
$path = $scope . '/' . $store->getCode() . '/' . $path; | |
break; | |
case 'websites': | |
$website = Mage::app()->getWebsite($scopeId); | |
$path = $scope . '/' . $website->getCode() . '/' . $path; | |
break; | |
} | |
return $path; | |
} | |
public function getConfigValues($path = '') | |
{ | |
$collection = Mage::getResourceModel('core/config_data_collection'); | |
if (!empty($path)) { | |
if (false === strpos($path, '%')) { | |
$path .= '%'; | |
} | |
$collection->addFieldToFilter('path', array('like' => $path)); | |
} | |
return $collection; | |
} | |
public function usageHelp() | |
{ | |
return <<<'USAGE' | |
Usage: php -f config_exporter.php -- [options] | |
-h Short alias for help | |
help This help | |
--path Configuration path to export. This can contain wildcards using | |
the '%' char, e.g. 'web/%' | |
USAGE; | |
} | |
} | |
$shell = new ConfigExporter(); | |
$shell->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment