public function setSystemAction()
{
$this->checkPermission("system_settings");
$values = \Zend_Json::decode($this->getParam("data"));
// email settings
$existingConfig = Config::getSystemConfig();
$existingValues = $existingConfig->toArray();
// fallback languages
$fallbackLanguages = [];
$languages = explode(",", $values["general.validLanguages"]);
$filteredLanguages = [];
foreach ($languages as $language) {
if (isset($values["general.fallbackLanguages." . $language])) {
$fallbackLanguages[$language] = str_replace(" ", "", $values["general.fallbackLanguages." . $language]);
}
if (\Zend_Locale::isLocale($language)) {
$filteredLanguages[] = $language;
}
}
// check if there's a fallback language endless loop
foreach ($fallbackLanguages as $sourceLang => $targetLang) {
$this->checkFallbackLanguageLoop($sourceLang, $fallbackLanguages);
}
// delete views if fallback languages has changed or the language is no more available
if (isset($existingValues['general']['fallbackLanguages']) && is_array($existingValues['general']['fallbackLanguages'])) {
$fallbackLanguagesChanged = array_diff_assoc($existingValues['general']['fallbackLanguages'], $fallbackLanguages);
$dbName = $existingValues["database"]["params"]["dbname"];
foreach ($fallbackLanguagesChanged as $language => $dummy) {
$this->deleteViews($language, $dbName);
}
}
$cacheExcludePatterns = $values["cache.excludePatterns"];
if (is_array($cacheExcludePatterns)) {
$cacheExcludePatterns = implode(',', $cacheExcludePatterns);
}
$settings = ["general" => ["timezone" => $values["general.timezone"], "path_variable" => $values["general.path_variable"], "domain" => $values["general.domain"], "redirect_to_maindomain" => $values["general.redirect_to_maindomain"], "language" => $values["general.language"], "validLanguages" => implode(",", $filteredLanguages), "fallbackLanguages" => $fallbackLanguages, "defaultLanguage" => $values["general.defaultLanguage"], "extjs6" => $values["general.extjs6"], "loginscreencustomimage" => $values["general.loginscreencustomimage"], "disableusagestatistics" => $values["general.disableusagestatistics"], "debug" => $values["general.debug"], "debug_ip" => $values["general.debug_ip"], "http_auth" => ["username" => $values["general.http_auth.username"], "password" => $values["general.http_auth.password"]], "custom_php_logfile" => $values["general.custom_php_logfile"], "debugloglevel" => $values["general.debugloglevel"], "disable_whoops" => $values["general.disable_whoops"], "debug_admin_translations" => $values["general.debug_admin_translations"], "devmode" => $values["general.devmode"], "logrecipient" => $values["general.logrecipient"], "viewSuffix" => $values["general.viewSuffix"], "instanceIdentifier" => $values["general.instanceIdentifier"], "show_cookie_notice" => $values["general.show_cookie_notice"]], "documents" => ["versions" => ["days" => $values["documents.versions.days"], "steps" => $values["documents.versions.steps"]], "default_controller" => $values["documents.default_controller"], "default_action" => $values["documents.default_action"], "error_pages" => ["default" => $values["documents.error_pages.default"]], "createredirectwhenmoved" => $values["documents.createredirectwhenmoved"], "allowtrailingslash" => $values["documents.allowtrailingslash"], "generatepreview" => $values["documents.generatepreview"]], "objects" => ["versions" => ["days" => $values["objects.versions.days"], "steps" => $values["objects.versions.steps"]]], "assets" => ["versions" => ["days" => $values["assets.versions.days"], "steps" => $values["assets.versions.steps"]], "icc_rgb_profile" => $values["assets.icc_rgb_profile"], "icc_cmyk_profile" => $values["assets.icc_cmyk_profile"], "hide_edit_image" => $values["assets.hide_edit_image"], "disable_tree_preview" => $values["assets.disable_tree_preview"]], "services" => ["google" => ["client_id" => $values["services.google.client_id"], "email" => $values["services.google.email"], "simpleapikey" => $values["services.google.simpleapikey"], "browserapikey" => $values["services.google.browserapikey"]]], "cache" => ["enabled" => $values["cache.enabled"], "lifetime" => $values["cache.lifetime"], "excludePatterns" => $cacheExcludePatterns, "excludeCookie" => $values["cache.excludeCookie"]], "outputfilters" => ["less" => $values["outputfilters.less"], "lesscpath" => $values["outputfilters.lesscpath"]], "webservice" => ["enabled" => $values["webservice.enabled"]], "httpclient" => ["adapter" => $values["httpclient.adapter"], "proxy_host" => $values["httpclient.proxy_host"], "proxy_port" => $values["httpclient.proxy_port"], "proxy_user" => $values["httpclient.proxy_user"], "proxy_pass" => $values["httpclient.proxy_pass"]], "applicationlog" => ["mail_notification" => ["send_log_summary" => $values['applicationlog.mail_notification.send_log_summary'], "filter_priority" => $values['applicationlog.mail_notification.filter_priority'], "mail_receiver" => $values['applicationlog.mail_notification.mail_receiver']], "archive_treshold" => $values['applicationlog.archive_treshold'], "archive_alternative_database" => $values['applicationlog.archive_alternative_database']]];
// email & newsletter
foreach (["email", "newsletter"] as $type) {
$settings[$type] = ["sender" => ["name" => $values[$type . ".sender.name"], "email" => $values[$type . ".sender.email"]], "return" => ["name" => $values[$type . ".return.name"], "email" => $values[$type . ".return.email"]], "method" => $values[$type . ".method"], "smtp" => ["host" => $values[$type . ".smtp.host"], "port" => $values[$type . ".smtp.port"], "ssl" => $values[$type . ".smtp.ssl"], "name" => $values[$type . ".smtp.name"], "auth" => ["method" => $values[$type . ".smtp.auth.method"], "username" => $values[$type . ".smtp.auth.username"]]]];
$smtpPassword = $values[$type . ".smtp.auth.password"];
if (!empty($smtpPassword)) {
$settings[$type]['smtp']['auth']['password'] = $smtpPassword;
}
if (array_key_exists($type . ".debug.emailAddresses", $values)) {
$settings[$type]["debug"] = ["emailaddresses" => $values[$type . ".debug.emailAddresses"]];
}
if (array_key_exists($type . ".bounce.type", $values)) {
$settings[$type]["bounce"] = ["type" => $values[$type . ".bounce.type"], "maildir" => $values[$type . ".bounce.maildir"], "mbox" => $values[$type . ".bounce.mbox"], "imap" => ["host" => $values[$type . ".bounce.imap.host"], "port" => $values[$type . ".bounce.imap.port"], "username" => $values[$type . ".bounce.imap.username"], "password" => $values[$type . ".bounce.imap.password"], "ssl" => $values[$type . ".bounce.imap.ssl"]]];
}
}
$settings["newsletter"]["usespecific"] = $values["newsletter.usespecific"];
$settings = array_merge($existingValues, $settings);
$configFile = \Pimcore\Config::locateConfigFile("system.php");
File::putPhpFile($configFile, to_php_data_file_format($settings));
$this->_helper->json(["success" => true]);
}