Ip\Internal\Config\AdminController::saveValue PHP Method

saveValue() public method

public saveValue ( )
    public function saveValue()
    {
        $request = \Ip\ServiceLocator::request();
        $request->mustBePost();
        $post = $request->getPost();
        if (empty($post['fieldName'])) {
            throw new \Exception('Missing required parameter');
        }
        $fieldName = $post['fieldName'];
        if (!isset($post['value'])) {
            throw new \Exception('Missing required parameter');
        }
        $value = $post['value'];
        if (!in_array($fieldName, array('websiteTitle', 'websiteEmail', 'gmapsApiKey')) && !(in_array($fieldName, array('automaticCron', 'cronPassword', 'removeOldRevisions', 'removeOldRevisionsDays', 'removeOldEmails', 'removeOldEmailsDays', 'allowAnonymousUploads', 'trailingSlash')) && ipAdminPermission('Config advanced'))) {
            throw new \Exception('Unknown config value');
        }
        $emailValidator = new \Ip\Form\Validator\Email();
        $error = $emailValidator->getError(array('value' => $value), 'value', \Ip\Form::ENVIRONMENT_ADMIN);
        if ($fieldName === 'websiteEmail' && $error !== false) {
            return $this->returnError($error);
        }
        if (in_array($fieldName, array('websiteTitle', 'websiteEmail'))) {
            if (!isset($post['languageId'])) {
                throw new \Exception('Missing required parameter');
            }
            $languageId = $post['languageId'];
            $language = ipContent()->getLanguage($languageId);
            ipSetOptionLang('Config.' . $fieldName, $value, $language->getCode());
        } else {
            ipSetOption('Config.' . $fieldName, $value);
        }
        return new \Ip\Response\Json(array(1));
    }