Skip to content

Instantly share code, notes, and snippets.

@ssv445
Last active December 27, 2015 18:59
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 ssv445/7373939 to your computer and use it in GitHub Desktop.
Save ssv445/7373939 to your computer and use it in GitHub Desktop.
PHP CLI script to update Joomla configuration file
<?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";
@ssv445
Copy link
Author

ssv445 commented Nov 8, 2013

Use as
php update-joomla-config.php /path/to/joomla/folder config-name1 config-value1 config-name2 config-value2 ...

@ssv445
Copy link
Author

ssv445 commented May 26, 2015

Updated for latest joomla version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment