Last active
December 27, 2015 18:59
-
-
Save ssv445/7373939 to your computer and use it in GitHub Desktop.
PHP CLI script to update Joomla configuration file
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
<?php | |
// | |
$joomlaroot = isset($argv[1]) ? $argv[1] : die("First argument required and it should be absolute-joomla-root-path"); | |
$i=2; | |
$args = array(); | |
while($i <= $argc){ | |
if(isset($argv[$i]) && isset($argv[$i+1])){ | |
$key = $argv[$i]; | |
$value = $argv[$i+1]; | |
//echo "\n found args [ $key |:::| $value]"; | |
}else{ | |
break; | |
} | |
$args[$key]=$value; | |
$i+=2; | |
} | |
// for including files require it | |
define('JPATH_PLATFORM', 1) ; | |
define('JPATH_BASE', $joomlaroot); | |
require $joomlaroot.'/configuration.php'; | |
$formatter = null; | |
if(file_exists($joomlaroot.'/libraries/joomla/registry/format.php')){ | |
include_once $joomlaroot.'/libraries/joomla/registry/format.php'; | |
include_once $joomlaroot.'/libraries/joomla/registry/format/php.php'; | |
// formatter | |
$formatter = new JRegistryFormatPHP(); | |
} | |
if(file_exists($joomlaroot.'/libraries/framework/Joomla/Registry/AbstractRegistryFormat.php')){ | |
include_once $joomlaroot.'/libraries/framework/Joomla/Registry/AbstractRegistryFormat.php'; | |
include_once $joomlaroot.'/libraries/framework/Joomla/Registry/Format/Php.php'; | |
// formatter | |
$formatter = new Joomla\Registry\Format\Php(); | |
} | |
//load prev config | |
$config = new JConfig(); | |
// update new config | |
foreach($args as $k=>$v){ | |
if(isset($config->$k)){ | |
$config->$k = $v; | |
echo " Updating [$k |:::| $v]"; | |
}else{ | |
echo " ERROR **** Invalid config [$k |:::| $v]"; | |
} | |
} | |
$params = array('class' => 'JConfig', 'closingtag' => false); | |
$str = $formatter->objectToString($config, $params); | |
// write new config | |
file_put_contents($joomlaroot.'/configuration.php', $str); | |
echo "\n"; |
Updated for latest joomla version
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use as
php update-joomla-config.php /path/to/joomla/folder config-name1 config-value1 config-name2 config-value2 ...