<commit_before><?php
class DefaultController extends Controller
{
    public $layout = 'application.modules.install.views.layouts.main';

    public $stepName;

    private $alreadyInstalledFlag;

    public function init()
    {
        $this->alreadyInstalledFlag = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . '.ai';
    }

    protected function beforeAction($action)
    {
        // проверка на то, что сайт уже установлен...
        if (file_exists($this->alreadyInstalledFlag) && $this->action->id != 'finish')
        {
            throw new CHttpException(404, Yii::t('install', 'Страница не найдена!'));
        }

        return parent::beforeAction($action);
    }

    public function actionIndex()
    {
        $this->stepName = Yii::t('install', 'Шаг первый : "Приветствие!"');

        $this->render('index');
    }

    public function actionRequirements()
    {
        $this->stepName = Yii::t('install', 'Шаг второй : "Проверка системных требований"');


        $requirements = array(
            array(
                Yii::t('yii', 'PHP version'),
                true,
                version_compare(PHP_VERSION, "5.1.0", ">="),
                '<a href="http://www.yiiframework.com">Yii Framework</a>',
                Yii::t('yii', 'PHP 5.1.0 or higher is required.')),
            array(
                Yii::t('yii', 'Reflection extension'),
                true,
                class_exists('Reflection', false),
                '<a href="http://www.yiiframework.com">Yii Framework</a>',
                ''),
            array(
                Yii::t('yii', 'PCRE extension'),
                true,
                extension_loaded("pcre"),
                '<a href="http://www.yiiframework.com">Yii Framework</a>',
                ''),
            array(
                Yii::t('yii', 'SPL extension'),
                true,
                extension_loaded("SPL"),
                '<a href="http://www.yiiframework.com">Yii Framework</a>',
                ''),
            array(
                Yii::t('yii', 'DOM extension'),
                false,
                class_exists("DOMDocument", false),
                '<a href="http://www.yiiframework.com/doc/api/CHtmlPurifier">CHtmlPurifier</a>, <a href="http://www.yiiframework.com/doc/api/CWsdlGenerator">CWsdlGenerator</a>',
                ''),
            array(
                Yii::t('yii', 'PDO extension'),
                false,
                extension_loaded('pdo'),
                Yii::t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
                ''),
            array(
                Yii::t('yii', 'PDO SQLite extension'),
                false,
                extension_loaded('pdo_sqlite'),
                Yii::t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
                Yii::t('yii', 'This is required if you are using SQLite database.')),
            array(
                Yii::t('yii', 'PDO MySQL extension'),
                false,
                extension_loaded('pdo_mysql'),
                Yii::t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
                Yii::t('yii', 'This is required if you are using MySQL database.')),
            array(
                Yii::t('yii', 'PDO PostgreSQL extension'),
                false,
                extension_loaded('pdo_pgsql'),
                Yii::t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
                Yii::t('yii', 'This is required if you are using PostgreSQL database.')),
            array(
                Yii::t('yii', 'Memcache extension'),
                false,
                extension_loaded("memcache"),
                '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>',
                ''),
            array(
                Yii::t('yii', 'APC extension'),
                false,
                extension_loaded("apc"),
                '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>',
                ''),
            array(
                Yii::t('yii', 'Mcrypt extension'),
                false,
                extension_loaded("mcrypt"),
                '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>',
                Yii::t('yii', 'This is required by encrypt and decrypt methods.')),
            array(
                Yii::t('yii', 'SOAP extension'),
                false,
                extension_loaded("soap"),
                '<a href="http://www.yiiframework.com/doc/api/CWebService">CWebService</a>, <a href="http://www.yiiframework.com/doc/api/CWebServiceAction">CWebServiceAction</a>',
                '')
        );

        $result = 1;

        foreach ($requirements as $i => $requirement)
        {
            if ($requirement[1] && !$requirement[2])
            {
                $result = 0;
            }
            else if ($result > 0 && !$requirement[1] && !$requirement[2])
            {
                $result = -1;
            }
            if ($requirement[4] === '')
            {
                $requirements[$i][4] = '&nbsp;';
            }
        }

        $this->render('requirements', array('requirements' => $requirements, 'result' => $result));
    }

    public function actionDbsettings()
    {
        $this->stepName = Yii::t('install', 'Шаг третий : "Соединение с базой данных"');

        $dbConfFile = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'db.php';

        $sqlDataDir = $this->module->basePath . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;

        $sqlFile = $sqlDataDir . 'yupe.sql';

        $form = new DbSettingsForm();

        if (Yii::app()->request->isPostRequest)
        {
            $form->setAttributes($_POST['DbSettingsForm']);

            if ($form->validate())
            {
                try
                {
                    //@TODO правильня обработка указанного номера порта - сейчас вообще не учитывается
                    $connectionString = "mysql:host={$form->host};dbname=$form->dbName";
                    $connection = new CDbConnection($connectionString, $form->user, $form->password);
                    $connection->connectionString = $connectionString;
                    $connection->username = $form->user;
                    $connection->password = $<PASSWORD>;
                    $connection->emulatePrepare = true;
                    $connection->charset = 'utf8';
                    $connection->active = true;

                    Yii::app()->setComponent('db', $connection);

                    $dbParams = array(
                        'class' => 'CDbConnection',
                        'connectionString' => "mysql:host={$form->host};dbname=$form->dbName",
                        'username' => $form->user,
                        'password' => $<PASSWORD>,
                        'emulatePrepare' => true,
                        'charset' => 'utf8',
                        'enableParamLogging' => 1,
                        'enableProfiling' => 1,
                        'schemaCachingDuration' => 108000,
                        'tablePrefix' => ''
                    );

                    $dbConfString = "<?php\n return " . var_export($dbParams, true) . " ;\n?>";

                    $fh = fopen($dbConfFile, 'w+');

                    if (!$fh)
                    {
                        $form->addError('', Yii::t('install', "Не могу открыть файл '{file}' для записии!", array('{file}' => $dbConfFile)));
                    }
                    else
                    {
                        //@TODO корректная обработка ошибок IO
                        fwrite($fh, $dbConfString);

                        fclose($fh);

                        @chmod($dbConfFile, 0666);

                        $result = $this->executeSql($sqlFile);

                        // обработать если есть все файлы с расшмрением .sql
                        $sqlFiles = glob("{$sqlDataDir}*.sql");


                        //@TODO завернуть это все в транзакцию  
                        if (is_array($sqlFiles) && count($sqlFiles) > 1)
                        {
                            foreach ($sqlFiles as $file)
                            {
                                if ($file != $sqlFile)
                                {
                                    $this->executeSql($file);
                                }
                            }
                        }

                        Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('install', 'Настройки базы данных успешно сохранены! База данных проинициализирована!'));

                        $this->redirect(array('/install/default/createuser/'));
                    }

                }
                catch (Exception $e)
                {
                    $form->addError('', $e->getMessage());
                }
            }
        }

        $result = $sqlResult = false;

        if (file_exists($dbConfFile) && is_writable($dbConfFile))<commit_msg>Временное решение проблемы с установкой<commit_after><?php
class DefaultController extends Controller
{
    public $layout = 'application.modules.install.views.layouts.main';

    public $stepName;

    private $alreadyInstalledFlag;

    public function init()
    {
        $this->alreadyInstalledFlag = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . '.ai';
    }

    protected function beforeAction($action)
    {
        // проверка на то, что сайт уже установлен...
        if (file_exists($this->alreadyInstalledFlag) && $this->action->id != 'finish' && $this->action->id != 'sitesettings')
        {
            throw new CHttpException(404, Yii::t('install', 'Страница не найдена!'));
        }

        return parent::beforeAction($action);
    }

    public function actionIndex()
    {
        $this->stepName = Yii::t('install', 'Шаг первый : "Приветствие!"');

        $this->render('index');
    }

    public function actionRequirements()
    {
        $this->stepName = Yii::t('install', 'Шаг второй : "Проверка системных требований"');


        $requirements = array(
            array(
                Yii::t('yii', 'PHP version'),
                true,
                version_compare(PHP_VERSION, "5.1.0", ">="),
                '<a href="http://www.yiiframework.com">Yii Framework</a>',
                Yii::t('yii', 'PHP 5.1.0 or higher is required.')),
            array(
                Yii::t('yii', 'Reflection extension'),
                true,
                class_exists('Reflection', false),
                '<a href="http://www.yiiframework.com">Yii Framework</a>',
                ''),
            array(
                Yii::t('yii', 'PCRE extension'),
                true,
                extension_loaded("pcre"),
                '<a href="http://www.yiiframework.com">Yii Framework</a>',
                ''),
            array(
                Yii::t('yii', 'SPL extension'),
                true,
                extension_loaded("SPL"),
                '<a href="http://www.yiiframework.com">Yii Framework</a>',
                ''),
            array(
                Yii::t('yii', 'DOM extension'),
                false,
                class_exists("DOMDocument", false),
                '<a href="http://www.yiiframework.com/doc/api/CHtmlPurifier">CHtmlPurifier</a>, <a href="http://www.yiiframework.com/doc/api/CWsdlGenerator">CWsdlGenerator</a>',
                ''),
            array(
                Yii::t('yii', 'PDO extension'),
                false,
                extension_loaded('pdo'),
                Yii::t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
                ''),
            array(
                Yii::t('yii', 'PDO SQLite extension'),
                false,
                extension_loaded('pdo_sqlite'),
                Yii::t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
                Yii::t('yii', 'This is required if you are using SQLite database.')),
            array(
                Yii::t('yii', 'PDO MySQL extension'),
                false,
                extension_loaded('pdo_mysql'),
                Yii::t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
                Yii::t('yii', 'This is required if you are using MySQL database.')),
            array(
                Yii::t('yii', 'PDO PostgreSQL extension'),
                false,
                extension_loaded('pdo_pgsql'),
                Yii::t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
                Yii::t('yii', 'This is required if you are using PostgreSQL database.')),
            array(
                Yii::t('yii', 'Memcache extension'),
                false,
                extension_loaded("memcache"),
                '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>',
                ''),
            array(
                Yii::t('yii', 'APC extension'),
                false,
                extension_loaded("apc"),
                '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>',
                ''),
            array(
                Yii::t('yii', 'Mcrypt extension'),
                false,
                extension_loaded("mcrypt"),
                '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>',
                Yii::t('yii', 'This is required by encrypt and decrypt methods.')),
            array(
                Yii::t('yii', 'SOAP extension'),
                false,
                extension_loaded("soap"),
                '<a href="http://www.yiiframework.com/doc/api/CWebService">CWebService</a>, <a href="http://www.yiiframework.com/doc/api/CWebServiceAction">CWebServiceAction</a>',
                '')
        );

        $result = 1;

        foreach ($requirements as $i => $requirement)
        {
            if ($requirement[1] && !$requirement[2])
            {
                $result = 0;
            }
            else if ($result > 0 && !$requirement[1] && !$requirement[2])
            {
                $result = -1;
            }
            if ($requirement[4] === '')
            {
                $requirements[$i][4] = '&nbsp;';
            }
        }

        $this->render('requirements', array('requirements' => $requirements, 'result' => $result));
    }

    public function actionDbsettings()
    {
        $this->stepName = Yii::t('install', 'Шаг третий : "Соединение с базой данных"');

        $dbConfFile = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'db.php';

        $sqlDataDir = $this->module->basePath . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;

        $sqlFile = $sqlDataDir . 'yupe.sql';

        $form = new DbSettingsForm();

        if (Yii::app()->request->isPostRequest)
        {
            $form->setAttributes($_POST['DbSettingsForm']);

            if ($form->validate())
            {
                try
                {
                    //@TODO правильня обработка указанного номера порта - сейчас вообще не учитывается
                    $connectionString = "mysql:host={$form->host};dbname=$form->dbName";
                    $connection = new CDbConnection($connectionString, $form->user, $form->password);
                    $connection->connectionString = $connectionString;
                    $connection->username = $form->user;
                    $connection->password = $<PASSWORD>;
                    $connection->emulatePrepare = true;
                    $connection->charset = 'utf8';
                    $connection->active = true;

                    Yii::app()->setComponent('db', $connection);

                    $dbParams = array(
                        'class' => 'CDbConnection',
                        'connectionString' => "mysql:host={$form->host};dbname=$form->dbName",
                        'username' => $form->user,
                        'password' => $<PASSWORD>,
                        'emulatePrepare' => true,
                        'charset' => 'utf8',
                        'enableParamLogging' => 1,
                        'enableProfiling' => 1,
                        'schemaCachingDuration' => 108000,
                        'tablePrefix' => ''
                    );

                    $dbConfString = "<?php\n return " . var_export($dbParams, true) . " ;\n?>";

                    $fh = fopen($dbConfFile, 'w+');

                    if (!$fh)
                    {
                        $form->addError('', Yii::t('install', "Не могу открыть файл '{file}' для записии!", array('{file}' => $dbConfFile)));
                    }
                    else
                    {
                        //@TODO корректная обработка ошибок IO
                        fwrite($fh, $dbConfString);

                        fclose($fh);

                        @chmod($dbConfFile, 0666);

                        $result = $this->executeSql($sqlFile);

                        // обработать если есть все файлы с расширением .sql
                        $sqlFiles = glob("{$sqlDataDir}*.sql");


                        //@TODO завернуть это все в транзакцию  
                        if (is_array($sqlFiles) && count($sqlFiles) > 1)
                        {
                            foreach ($sqlFiles as $file)
                            {
                                if ($file != $sqlFile)
                                {
                                    $this->executeSql($file);
                                }
                            }
                        }

                        Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('install', 'Настройки базы данных успешно сохранены! База данных проинициализирована!'));

                        $this->redirect(array('/install/default/createuser/'));
                    }

                }
                catch (Exception $e)
                {
                    $form->addError('', $e->getMessage());
                }
            }
        }

        $result = $sqlResult = false;

        if (file_exists($dbConfFile) && is_writable($dbConfFile))
{'fraction_non_alphanumeric': 0.14796275364659023, 'fraction_numerical': 0.0036600462888207114, 'mean_word_length': 1.4341674308921788, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 185, 'https://': 0, 'lorem ipsum': 0, 'www.': 30, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2766646', 'n_tokens_mistral': 5470, 'n_tokens_neox': 5092, 'n_words': 887}