Skip to content

Instantly share code, notes, and snippets.

@fmarangi
Created December 1, 2013 09:35
Show Gist options
  • Save fmarangi/7730443 to your computer and use it in GitHub Desktop.
Save fmarangi/7730443 to your computer and use it in GitHub Desktop.
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