Example #1
0
 public function actionInstall()
 {
     if (Yii::app()->db->username) {
         throw new CHttpException(404, 'Система уже установлена');
     }
     // Список требований
     $minPhp = '5.3';
     $testFunc = array('chmod', 'mkdir', 'copy');
     $disFunc = explode(',', ini_get('disable_functions'));
     $testExt = array('pdo', 'pdo_mysql', 'gd', 'mbstring', 'ctype');
     $confFile = __DIR__ . '/../../include/db.config.inc.php';
     $assetDir = __DIR__ . '/../../assets';
     $runtimeDir = __DIR__ . '/../runtime';
     // Проверка подключения к БД
     if (Yii::app()->request->isAjaxRequest) {
         $form = new InstallForm('test');
         $form->attributes = $_POST['InstallForm'];
         $conn = $form->testConnect();
         if ($conn !== TRUE) {
             Yii::app()->end('<span class="text-error">' . $conn . '</span>');
         }
         Yii::app()->end('<span class="text-success">Соединение установлено</span>');
     }
     $error = array();
     // Проверка требований
     if (version_compare(PHP_VERSION, $minPhp, '<')) {
         $error[] = 'Вы используете PHP версию ниже рекомендуемой';
     }
     foreach ($testFunc as $func) {
         if (!function_exists($func) || in_array($func, $disFunc)) {
             $error[] = "Недоступна функция {$func}";
         }
     }
     foreach ($testExt as $ext) {
         if (!extension_loaded($ext)) {
             $error[] = "Недоступно расширение {$ext}";
         }
     }
     if (!is_writable($confFile)) {
         if (!chmod($confFile, 0666)) {
             $error[] = 'Недостаточно прав для записи в конфиг';
         }
     }
     if (!is_writable($assetDir)) {
         if (!chmod($assetDir, 0777)) {
             exit('Недостаточно прав для записи в папку /assets');
         }
     }
     if (!is_writable($runtimeDir)) {
         if (!chmod($runtimeDir, 0777)) {
             exit('Недостаточно прав для записи в папку /protected/runtime');
         }
     }
     $form = new InstallForm();
     $success = FALSE;
     // ПОСТ? Ошибок нет? Устанавливаем!
     if (!count($error) && Yii::app()->request->isPostRequest) {
         $form->attributes = $_POST['InstallForm'];
         if ($form->validate()) {
             $res = $form->installDB();
             if ($res !== TRUE) {
                 $form->addError('', $res);
             } else {
                 $success = TRUE;
             }
         }
     }
     $this->render('install', array('form' => $form, 'error' => $error, 'success' => $success));
 }