*/
protected $doneUpdates;
- /**
- * @var array Shaarli's configuration array.
- */
- protected $config;
-
/**
* @var LinkDB instance.
*/
* Object constructor.
*
* @param array $doneUpdates Updates which are already done.
- * @param array $config Shaarli's configuration array.
* @param LinkDB $linkDB LinkDB instance.
* @param boolean $isLoggedIn True if the user is logged in.
*/
- public function __construct($doneUpdates, $config, $linkDB, $isLoggedIn)
+ public function __construct($doneUpdates, $linkDB, $isLoggedIn)
{
$this->doneUpdates = $doneUpdates;
- $this->config = $config;
$this->linkDB = $linkDB;
$this->isLoggedIn = $isLoggedIn;
*/
public function updateMethodMergeDeprecatedConfigFile()
{
- $config_file = $this->config['config']['CONFIG_FILE'];
+ $conf = ConfigManager::getInstance();
- if (is_file($this->config['config']['DATADIR'].'/options.php')) {
- include $this->config['config']['DATADIR'].'/options.php';
+ if (is_file($conf->get('config.DATADIR') . '/options.php')) {
+ include $conf->get('config.DATADIR') . '/options.php';
// Load GLOBALS into config
+ $allowedKeys = array_merge(ConfigPhp::$ROOT_KEYS);
+ $allowedKeys[] = 'config';
foreach ($GLOBALS as $key => $value) {
- $this->config[$key] = $value;
+ if (in_array($key, $allowedKeys)) {
+ $conf->set($key, $value);
+ }
}
- $this->config['config']['CONFIG_FILE'] = $config_file;
- writeConfig($this->config, $this->isLoggedIn);
-
- unlink($this->config['config']['DATADIR'].'/options.php');
+ $conf->write($this->isLoggedIn);
+ unlink($conf->get('config.DATADIR').'/options.php');
}
return true;
*/
public function updateMethodRenameDashTags()
{
- $linklist = $this->linkDB->filter();
+ $conf = ConfigManager::getInstance();
+ $linklist = $this->linkDB->filterSearch();
foreach ($linklist as $link) {
$link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']);
$link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true)));
$this->linkDB[$link['linkdate']] = $link;
}
- $this->linkDB->savedb($this->config['config']['PAGECACHE']);
+ $this->linkDB->savedb($conf->get('config.PAGECACHE'));
return true;
}
+
+ /**
+ * Move old configuration in PHP to the new config system in JSON format.
+ *
+ * Will rename 'config.php' into 'config.save.php' and create 'config.json'.
+ */
+ public function updateMethodConfigToJson()
+ {
+ $conf = ConfigManager::getInstance();
+
+ // JSON config already exists, nothing to do.
+ if ($conf->getConfigIO() instanceof ConfigJson) {
+ return true;
+ }
+
+ $configPhp = new ConfigPhp();
+ $configJson = new ConfigJson();
+ $oldConfig = $configPhp->read($conf::$CONFIG_FILE . '.php');
+ rename($conf->getConfigFile(), $conf::$CONFIG_FILE . '.save.php');
+ $conf->setConfigIO($configJson);
+ $conf->reload();
+
+ foreach (ConfigPhp::$ROOT_KEYS as $key) {
+ $conf->set($key, $oldConfig[$key]);
+ }
+
+ // Set sub config keys (config and plugins)
+ $subConfig = array('config', 'plugins');
+ foreach ($subConfig as $sub) {
+ foreach ($oldConfig[$sub] as $key => $value) {
+ $conf->set($sub .'.'. $key, $value);
+ }
+ }
+
+ try{
+ $conf->write($this->isLoggedIn);
+ return true;
+ } catch (IOException $e) {
+ error_log($e->getMessage());
+ return false;
+ }
+ }
}
/**
}
}
-
/**
* Read the updates file, and return already done updates.
*