Exemplo n.º 1
0
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     $model = new ConfigForm(Yii::getPathOfAlias('application.config.settings') . '.php');
     $InitConf = $model->getConfig();
     if (isset($_POST['config'])) {
         $model->updateConfig($_POST['config']);
         if ($model->validate()) {
             $model->saveToFile();
             $this->refresh();
         }
     }
     $this->render('/config', array('model' => $model));
 }
Exemplo n.º 2
0
 public function saveDBInstallStatusConfig($status)
 {
     $conf_form = new ConfigForm($this->config_params_path . $this->install_db);
     $conf_form->updateParam('install_database_status', $status);
     $conf_form->saveToFile();
 }
Exemplo n.º 3
0
    public function actionInstall() {
        global $CONFIG; // Путь к файлу конфигурации для его изменения
        $this->layout = "/install-layout";
        $db_error = false;
        $model = new InstallForm;

        if (Yii::app()->params['installed'] !== "yes") {

            if (!is_writable($CONFIG)) {
                $model->addError("site_name", "Файл " . $CONFIG . " должен быть доступен для записи");
            }

            if (!is_writable(Yii::getPathOfAlias('application.config.settings') . ".php")) {
                $model->addError("site_name", "Файл " 
                        .Yii::getPathOfAlias('application.config.settings') . ".php" 
                        . " должен быть доступен для записи");
            }

            if (!is_writable(Yii::getPathOfAlias('application.runtime'))) {
                $model->addError("site_name", "папка " 
                        .Yii::getPathOfAlias('application.runtime') 
                        . " должена быть доступена для записи");
            }

            if (!is_writable(Yii::app()->basePath . "/../assets")) {
                $model->addError("site_name", "папка /assets должена быть доступена для записи");
            }

            if (isset($_POST['InstallForm'])) {
                $model->attributes = $_POST['InstallForm'];

                // данные Mysql 
                $server = trim(stripslashes($_POST['InstallForm']['mysql_server']));
                $username = trim(stripslashes($_POST['InstallForm']['mysql_login']));
                $password = trim(stripslashes($_POST['InstallForm']['mysql_password']));
                $db_name = trim(stripslashes($_POST['InstallForm']['mysql_db_name']));

                // данные пользователя                     
                if (!$model->validate() or $model->userpass !== $model->userpass2) {
                    $model->addError('userpass2', "Пароли не совпадают");
                }

                if (!$model->errors) {
                    $db_con = mysqli_connect($server, $username, $password) or $db_error = mysqli_error();
                    mysqli_select_db($db_con, $db_name) or $db_error = mysqli_error($db_con);
                }

                if (!$db_error and ! $model->errors) {
                    $config_data = require $CONFIG;



                    $dump_file = file_get_contents(Yii::getPathOfAlias('application.data.install') . '.sql');

                    // Сохранение данных о пользователе 
                    $dump_file.=" INSERT INTO `users` 
                                    (`username`, `password`, `email`, `activkey`, `superuser`, `status`)     VALUES "
                            . "('" . $model->username . "', '" . UserModule::encrypting($model->userpass) . "', "
                            . "'" . $model->useremail . "', '" . UserModule::encrypting(microtime() . $model->userpass) . "',"
                            . " 1, 1);";

                    mysqli_multi_query($db_con, $dump_file) or $db_error = mysqli_error($db_con);

                    if (!$db_error) {
                        // Заполнение конфигурации
                        $config_data['components']['db'] = array(
                            'connectionString' => 'mysql:host=' . $server . ';dbname=' . $db_name,
                            'emulatePrepare' => true,
                            'username' => $username,
                            'password' => $password,
                            'charset' => 'utf8',
                            'tablePrefix' => '',
                        );
                        $config_data['name'] = trim(stripslashes($_POST['InstallForm']['site_name']));
                        $config_data['params'] = "require";

                        $config_array_str = var_export($config_data, true);
                        $config_array_str = str_replace("'params' => 'require',", "'params' => require 'settings.php',", $config_array_str);
                        //Сохранение конфигурации 
                        file_put_contents($CONFIG, "<? return " . $config_array_str . " ?>");

                        // Сохранение настроек
                        $settings = new ConfigForm(Yii::getPathOfAlias('application.config.settings') . ".php");
                        $settings->updateParam('adminEmail', $model->useremail);
                        $settings->updateParam('installed', 'yes');
                        $settings->saveToFile();

                        $this->redirect(array('site/index'));
                    }
                }
            }

            $this->render('install', array('model' => $model, 'db_error' => $db_error));
        } else {
            $this->redirect(array('site/index'));
        }
    }
Exemplo n.º 4
0
 public function createDefaultFiles()
 {
     if (!$this->configExists($this->config_params_path . $this->file_db_long_params)) {
         $db_params = new ConfigForm($this->config_params_path . $this->file_db_long_params);
         $db_params->updateParam('username', '');
         $db_params->updateParam('password', '');
         $db_params->updateParam('host', '');
         $db_params->updateParam('port', '');
         $db_params->updateParam('dbname', '');
         $db_params->saveToFile();
     }
     if (!$this->configExists($this->config_params_path . $this->install_db_long)) {
         $db_params = new ConfigForm($this->config_params_path . $this->install_db_long);
         $db_params->updateParam('checked_database_long_status', 0);
         $db_params->updateParam('install_database_long_status', 0);
         $db_params->saveToFile();
     }
     if (!$this->configExists($this->config_params_path . $this->file_database_long_sync_config)) {
         $conf_form = new ConfigForm($this->config_params_path . $this->file_database_long_sync_config);
         $conf_form->updateParam('sync_id', 'delaircoSyncDb');
         $conf_form->updateParam('periodicity', 'minutely');
         $conf_form->updateParam('interval', 1);
         $conf_form->updateParam('startTime', '');
         $conf_form->updateParam('delete_periodicity', 'DAY');
         $conf_form->updateParam('delete_period', 3);
         $conf_form->updateParam('max_row', 3000);
         $conf_form->saveToFile();
     }
     if (!$this->configExists($this->config_params_path . $this->file_mysql_long)) {
         $conf_form = new ConfigForm($this->config_params_path . $this->file_mysql_long);
         $conf_form->updateParam('class', 'CDbConnection');
         $conf_form->updateParam('connectionString', 'mysql:host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->dbname);
         $conf_form->updateParam('username', $this->user);
         $conf_form->updateParam('password', $this->password);
         $conf_form->updateParam('charset', 'utf8');
         $conf_form->updateParam('emulatePrepare', true);
         $conf_form->updateParam('enableParamLogging', false);
         $conf_form->updateParam('enableProfiling', false);
         $conf_form->updateParam('persistent', true);
         $conf_form->updateParam('initSQLs', array("set time_zone='+00:00';"));
         $conf_form->saveToFile();
     }
 }
Exemplo n.º 5
0
 public function saveInstallProcessStatus($status)
 {
     $conf_form = new ConfigForm($this->config_params_path . $this->file_install);
     $conf_form->updateParam('install_status', $status);
     $conf_form->saveToFile();
 }