/**
  * Creates a new ParseOtchetFile model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ParseOtchetFile();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Beispiel #2
0
 public function actionUpdateReportFile()
 {
     return;
     $this->checkPath();
     $count = 0;
     $files = 0;
     foreach (ParseOtchet::find()->limit(10)->all() as $model) {
         if (ParseOtchetFile::findOne(['parse_otchet_id' => $model->id]) === null && $model->url_otchet !== null && $model->text === null) {
             $saw = new NokogiriHelper(file_get_contents($model->url_otchet));
             $text = [];
             foreach ($saw->get('div.post p') as $p) {
                 if (isset($p['a'])) {
                     foreach ($p['a'] as $a) {
                         echo $a['href'] . "\n\n";
                         $file = file_get_contents($a['href']);
                         $url_base = "C:/OpenServer/domains/yii2-papa/statics/web/ksk/otchet/{$model->id}";
                         $this->checkPath($url_base);
                         $size = sizeof(scandir($url_base));
                         if (file_put_contents("{$url_base}/{$size}.jpg", $file) !== false) {
                             $modelFile = new ParseOtchetFile();
                             $modelFile->file_name = $a['title'];
                             $modelFile->path = "{$url_base}/{$size}.jpg";
                             $modelFile->parse_otchet_id = $model->id;
                             if ($modelFile->save()) {
                                 $files++;
                                 echo str_pad("otchet-{$model->id}", 15) . str_pad("{$modelFile->path}", 50) . str_pad("SUCCESS", 15) . "\n";
                             } else {
                                 echo str_pad("otchet-{$model->id}", 15) . str_pad(Json::encode($modelFile->errors), 50) . str_pad("ERROR MODEL", 15) . "\n";
                             }
                         } else {
                             echo str_pad("otchet-{$model->id}", 15) . str_pad("{$url_base}/{$size}.jpg", 50) . str_pad("ERROR FILE", 15) . "\n";
                         }
                     }
                 }
                 !isset($p['#text']) ?: ($text[] = $p['#text']);
             }
             $model = ParseOtchet::findOne($model->id);
             $model->text = $this->formatText($text);
             $model->save();
             $count++;
         }
     }
     echo "updated - {$count}\ncreated files - {$files}\n";
 }