Skip to content

Instantly share code, notes, and snippets.

@therouv
Forked from fmarangi/config_exporter.php
Created December 2, 2013 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therouv/7749743 to your computer and use it in GitHub Desktop.
Save therouv/7749743 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