Generates and writes the content of the application's configuration
file.
public writePHPConfig ( Horde_Variables $formvars, string &$php = null ) : boolean | ||
$formvars | Horde_Variables | The processed configuration form data. |
$php | string | The content of the generated configuration file. |
return | boolean | True if the configuration file could be written immediately to the file system. |
/** * Creates default configuration files for all installed applications. * * @throws Horde_Exception */ public function writeAllConfigs() { foreach ($GLOBALS['registry']->listAllApps() as $app) { if ($app == 'horde' || !file_exists($GLOBALS['registry']->get('fileroot', $app) . '/config/conf.xml')) { continue; } $config = new Horde_Config($app); $configFile = $config->configFile(); if (!$config->writePHPConfig(new Horde_Variables())) { throw new Horde_Exception('Cannot write configuration file ' . Horde_Util::realPath($configFile)); } } }
$php = ''; $path = $registry->get('fileroot', $app) . '/config'; $configFile = $path . '/conf.php'; if (is_link($configFile)) { $configFile = readlink($configFile); } if ($vars->submitbutton == _("Revert Configuration")) { if (@copy($path . '/conf.bak.php', $configFile)) { $notification->push(_("Successfully reverted configuration. Reload to see changes."), 'horde.success'); @unlink($path . '/conf.bak.php'); } else { $notification->push(_("Could not revert configuration."), 'horde.error'); } } elseif ($form->validate($vars)) { $config = new Horde_Config($app); if ($config->writePHPConfig($vars, $php)) { Horde::url('admin/config/index.php', true)->redirect(); } else { $notification->push(sprintf(_("Could not save the configuration file %s. You can either use one of the options to save the code back on %s or copy manually the code below to %s."), Horde_Util::realPath($configFile), Horde::link(Horde::url('admin/config/index.php') . '#update', _("Configuration")) . _("Configuration") . '</a>', Horde_Util::realPath($configFile)), 'horde.warning', array('content.raw', 'sticky')); } } elseif ($form->isSubmitted()) { $notification->push(_("There was an error in the configuration form. Perhaps you left out a required field."), 'horde.error'); } $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/admin/config')); $view->addHelper('Text'); $view->php = $php; /* Create the link for the diff popup only if stored in session. */ if ($session->exists('horde', 'config/' . $app)) { $url = Horde::url('admin/config/diff.php', true)->add('app', $app); $view->diff_popup = Horde::link('#', '', '', '', Horde::popupJs($url, array('height' => 480, 'width' => 640, 'urlencode' => true)) . 'return false;') . _("show differences") . '</a>'; }
$notification->push(_("Could not contact server. Try again later."), 'horde.error'); } } /* Update configurations if requested. */ if ($vars->action == 'config') { foreach ($a as $app) { $path = $registry->get('fileroot', $app) . '/config'; if (!file_exists($path . '/conf.xml') || file_exists($path . '/conf.php') && ($xml_ver = $hconfig->getVersion(@file_get_contents($path . '/conf.xml'))) !== false && ($php_ver = $hconfig->getVersion(@file_get_contents($path . '/conf.php'))) !== false && $xml_ver == $php_ver) { continue; } $vars = new Horde_Variables(); $form = new Horde_Config_Form($vars, $app, true); $form->setSubmitted(true); if ($form->validate($vars)) { $config = new Horde_Config($app); if (!$config->writePHPConfig($vars)) { $notification->push(sprintf(_("Could not save the configuration file %s. Use one of the options below to save the code."), Horde_Util::realPath($config->configFile())), 'horde.warning', array('content.raw', 'sticky')); } } else { $notification->push(sprintf(_("The configuration for %s cannot be updated automatically. Please update the configuration manually."), $app), 'horde.error'); } } } /* Update schema if requested. */ if ($vars->action == 'schema') { $apps = isset($vars->app) ? array($vars->app) : $migration->apps; foreach ($apps as $app) { $migrator = $migration->getMigrator($app); if ($migrator->getTargetVersion() <= $migrator->getCurrentVersion()) { continue; }