<commit_before><?php

namespace app\controllers\admin;

use app\components\HTMLTools;
use app\components\Tools;
use app\components\updater\UpdateChecker;
use app\components\UrlHelper;
use app\models\db\Consultation;
use app\models\db\ConsultationFile;
use app\models\db\ConsultationSettingsTag;
use app\models\db\ConsultationText;
use app\models\db\ISupporter;
use app\models\AdminTodoItem;
use app\models\db\Site;
use app\models\db\User;
use app\models\exceptions\FormError;
use app\models\forms\AntragsgruenUpdateModeForm;
use app\models\forms\ConsultationCreateForm;
use yii\web\Response;

/**
 * Class IndexController
 * @package app\controllers\admin
 */
class IndexController extends AdminBase
{
    use SiteAccessTrait;

    public static $REQUIRED_PRIVILEGES = [
        User::PRIVILEGE_CONSULTATION_SETTINGS,
        User::PRIVILEGE_SITE_ADMIN,
    ];

    /**
     * @return string
     */
    public function actionIndex()
    {
        if ($this->isPostSet('flushCaches') && User::currentUserIsSuperuser()) {
            $this->consultation->flushCacheWithChildren();
            \Yii::$app->session->setFlash('success', \Yii::t('admin', 'index_flushed_cached'));
        }

        if ($this->isPostSet('delSite')) {
            $this->site->setDeleted();
            return $this->render('site_deleted', []);
        }

        return $this->render(
            'index',
            [
                'site'         => $this->site,
                'consultation' => $this->consultation
            ]
        );
    }

    /**
     * @return string
     * @throws FormError
     * @throws \Exception
     * @throws \Throwable
     * @throws \yii\db\StaleObjectException
     */
    public function actionConsultation()
    {
        $model = $this->consultation;

        $locale = Tools::getCurrentDateLocale();

        if ($this->isPostSet('save')) {
            $this->saveTags($model);
            $post = \Yii::$app->request->post();

            $data = $post['consultation'];
            $model->setAttributes($data);

            $settingsInput = (isset($post['settings']) ? $post['settings'] : []);
            $settings      = $model->getSettings();
            $settings->saveForm($settingsInput, $post['settingsFields']);
            if (isset($_FILES['newLogo'])) {
                try {
                    $file = ConsultationFile::uploadImage($this->consultation, 'newLogo');
                    $settings->logoUrl = $file->getUrl();
                } catch (FormError $e) {
                    \yii::$app->session->setFlash('error', $e->getMessage());
                }
            }
            $model->setSettings($settings);

            if (preg_match('/^[\w_-]+$/i', $data['urlPath'])) {
                $model->urlPath = $data['urlPath'];
            } else {
                \yii::$app->session->setFlash('error', \Yii::t('admin', 'con_url_path_err'));
            }

            if ($model->save()) {
                $settingsInput = (isset($post['siteSettings']) ? $post['siteSettings'] : []);
                $siteSettings  = $model->site->getSettings();
                $siteSettings->saveForm($settingsInput, $post['siteSettingsFields']);
                $model->site->setSettings($siteSettings);
                if ($model->site->currentConsultationId == $model->id) {
                    $model->site->status = ($settings->maintenanceMode ? Site::STATUS_INACTIVE : Site::STATUS_ACTIVE);
                }
                $model->site->save();
<commit_msg>Prevent a warning when changing consultation settings<commit_after><?php

namespace app\controllers\admin;

use app\components\HTMLTools;
use app\components\Tools;
use app\components\updater\UpdateChecker;
use app\components\UrlHelper;
use app\models\db\Consultation;
use app\models\db\ConsultationFile;
use app\models\db\ConsultationSettingsTag;
use app\models\db\ConsultationText;
use app\models\db\ISupporter;
use app\models\AdminTodoItem;
use app\models\db\Site;
use app\models\db\User;
use app\models\exceptions\FormError;
use app\models\forms\AntragsgruenUpdateModeForm;
use app\models\forms\ConsultationCreateForm;
use yii\web\Response;

/**
 * Class IndexController
 * @package app\controllers\admin
 */
class IndexController extends AdminBase
{
    use SiteAccessTrait;

    public static $REQUIRED_PRIVILEGES = [
        User::PRIVILEGE_CONSULTATION_SETTINGS,
        User::PRIVILEGE_SITE_ADMIN,
    ];

    /**
     * @return string
     */
    public function actionIndex()
    {
        if ($this->isPostSet('flushCaches') && User::currentUserIsSuperuser()) {
            $this->consultation->flushCacheWithChildren();
            \Yii::$app->session->setFlash('success', \Yii::t('admin', 'index_flushed_cached'));
        }

        if ($this->isPostSet('delSite')) {
            $this->site->setDeleted();
            return $this->render('site_deleted', []);
        }

        return $this->render(
            'index',
            [
                'site'         => $this->site,
                'consultation' => $this->consultation
            ]
        );
    }

    /**
     * @return string
     * @throws FormError
     * @throws \Exception
     * @throws \Throwable
     * @throws \yii\db\StaleObjectException
     */
    public function actionConsultation()
    {
        $model = $this->consultation;

        $locale = Tools::getCurrentDateLocale();

        if ($this->isPostSet('save')) {
            $this->saveTags($model);
            $post = \Yii::$app->request->post();

            $data = $post['consultation'];
            $model->setAttributes($data);

            $settingsInput = (isset($post['settings']) ? $post['settings'] : []);
            $settings      = $model->getSettings();
            $settings->saveForm($settingsInput, $post['settingsFields']);
            if (isset($_FILES['newLogo']) && $_FILES['newLogo']['tmp_name']) {
                try {
                    $file = ConsultationFile::uploadImage($this->consultation, 'newLogo');
                    $settings->logoUrl = $file->getUrl();
                } catch (FormError $e) {
                    \yii::$app->session->setFlash('error', $e->getMessage());
                }
            }
            $model->setSettings($settings);

            if (preg_match('/^[\w_-]+$/i', $data['urlPath'])) {
                $model->urlPath = $data['urlPath'];
            } else {
                \yii::$app->session->setFlash('error', \Yii::t('admin', 'con_url_path_err'));
            }

            if ($model->save()) {
                $settingsInput = (isset($post['siteSettings']) ? $post['siteSettings'] : []);
                $siteSettings  = $model->site->getSettings();
                $siteSettings->saveForm($settingsInput, $post['siteSettingsFields']);
                $model->site->setSettings($siteSettings);
                if ($model->site->currentConsultationId == $model->id) {
                    $model->site->status = ($settings->maintenanceMode ? Site::STATUS_INACTIVE : Site::STATUS_ACTIVE);
                }
                $model->site->save();

{'fraction_non_alphanumeric': 0.15875035340684196, 'fraction_numerical': 0.0, 'mean_word_length': 2.2588668816213726, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4424316', 'n_tokens_mistral': 2071, 'n_tokens_neox': 2037, 'n_words': 301}