Skip to content

Commit

Permalink
Fix updating config file if 'plugins' option is not defined yet (#149…
Browse files Browse the repository at this point in the history
…0508)
  • Loading branch information
alecpl committed Aug 27, 2015
1 parent 7320d96 commit c4a2261
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/Roundcube/Composer/PluginInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,39 @@ private function rcubeAlterConfig($plugin_name, $add)
$varname = '$config';

if (empty($config) && !empty($rcmail_config)) {
$config = $rcmail_config;
$config = $rcmail_config;
$varname = '$rcmail_config';
}

if (is_array($config) && is_writeable($config_file)) {
$config_templ = @file_get_contents($config_file);
$active_plugins = (array) $config['plugins'];
$config_templ = @file_get_contents($config_file) ?: '';
$config_plugins = !empty($config['plugins']) ? ((array) $config['plugins']) : array();
$active_plugins = $config_plugins;

if ($add && !in_array($plugin_name, $active_plugins)) {
$active_plugins[] = $plugin_name;
} elseif (!$add && ($i = array_search($plugin_name, $active_plugins)) !== false) {
unset($active_plugins[$i]);
}

if ($active_plugins != $config['plugins']) {
if ($active_plugins != $config_plugins) {
$count = 0;
$var_export = "array(\n\t'" . join("',\n\t'", $active_plugins) . "',\n);";
$new_config = preg_replace(
"/(\\$varname\['plugins'\])\s+=\s+(.+);/Uims",
"\\1 = " . $var_export,
$config_templ);
$config_templ, -1, $count);

// 'plugins' option does not exist yet, add it...
if (!$count) {
$var_txt = "\n{$varname}['plugins'] = $var_export;\n";
$new_config = str_replace('?>', $var_txt . '?>', $config_templ, $count);

if (!$count) {
$new_config = $config_templ . $var_txt;
}
}

$success = file_put_contents($config_file, $new_config);
}
}
Expand Down

0 comments on commit c4a2261

Please sign in to comment.