protected function getStdIn($message)
 {
     do {
         $this->stdout($message, Console::FG_YELLOW);
         $data = Console::stdin();
     } while (!$data);
     return $data;
 }
Пример #2
0
 /**
  * Установка ФИАС
  * @throws BadRequestHttpException
  * @throws ErrorException
  * @throws \yii\db\Exception
  */
 public function actionFias()
 {
     ini_set('memory_limit', '512M');
     //конфиг скачиваемых файлов
     $downloadFiles = [['url' => 'http://basicdata.ru/data/fias/fias_addrobj_table.sql.bz2', 'filename' => 'fias_addrobj_table.sql.bz2', 'sqlFilename' => 'fias_addrobj_table.sql'], ['url' => 'http://basicdata.ru/data/fias/fias_addrobj_index.sql.bz2', 'filename' => 'fias_addrobj_index.sql.bz2', 'sqlFilename' => 'fias_addrobj_index.sql'], ['url' => 'http://basicdata.ru/data/fias/fias_addrobj_data.sql.bz2', 'filename' => 'fias_addrobj_data.sql.bz2', 'sqlFilename' => 'fias_addrobj_data.sql']];
     $this->stdout('Сейчас будут загружены следующие файлы: ' . PHP_EOL);
     foreach ($downloadFiles as $fileRow) {
         $this->stdout($fileRow['url'] . PHP_EOL, Console::FG_GREEN);
     }
     $this->stdout('Загрузить их? [Y/n] ');
     $downloadConfirm = mb_strtolower(Console::stdin());
     $this->stdout(PHP_EOL);
     if ($downloadConfirm !== '' && $downloadConfirm !== 'y') {
         $this->stdout('Завершаем выполнение' . PHP_EOL, Console::FG_RED);
         return;
     }
     $downloadDir = $this->getDownloadDir('fias');
     $this->stdout('Удаляем таблицу, если она есть... ');
     Yii::$app->db->createCommand('DROP TABLE IF EXISTS `d_fias_addrobj`;')->execute();
     $this->stdout('готово' . PHP_EOL);
     foreach ($downloadFiles as $fileRow) {
         $this->stdout('Загружаем файл ' . $fileRow['url'] . PHP_EOL);
         $this->stdout('Размер файла: ' . number_format($this->getDownloadFileSize($fileRow['url']), 0, '.', ' ') . ' байт' . PHP_EOL);
         $this->downloadFile($fileRow['url'], $fileRow['filename'], $downloadDir);
         $this->stdout('готово' . PHP_EOL);
         $this->stdout('Распаковываем файл ' . $fileRow['filename'] . '... ');
         $this->unpackFile($downloadDir . DIRECTORY_SEPARATOR . $fileRow['filename']);
         $this->stdout('готово' . PHP_EOL);
         $this->stdout('Загружаем файл в БД... ');
         $this->loadDb($downloadDir . DIRECTORY_SEPARATOR . $fileRow['sqlFilename']);
         $this->stdout('готово' . PHP_EOL);
     }
     $this->stdout('Добавляем нужные индексы...');
     Yii::$app->db->createCommand('ALTER TABLE `d_fias_addrobj`ADD INDEX `aolevel_actstatus_formalname` (`aolevel`, `actstatus`, `formalname`);')->execute();
     $this->stdout('готово' . PHP_EOL);
     $this->stdout('Удаляем временный каталог...');
     exec('rm -rf ' . $downloadDir, $output, $return);
     if ($return !== 0) {
         throw new ErrorException('Ошибка при удалении временного каталога');
     }
     $this->stdout('готово' . PHP_EOL);
 }
Пример #3
0
 /**
  * Gets input from STDIN and returns a string right-trimmed for EOLs.
  *
  * @param boolean $raw If set to true, returns the raw string without trimming
  * @return string the string read from stdin
  */
 public static function stdin($raw = false)
 {
     return parent::stdin($raw);
 }