Exemplo n.º 1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(SourceRepository $sourceRepo)
 {
     $this->source->sync_status = "downloading";
     $this->source->save();
     $id = $this->source->id;
     $name = $this->source->name;
     $url = $this->source->origin_url;
     $sourceRepo->addRecord($this->source, "Starting download");
     $response = $sourceRepo->copyRemoteFile($url, storage_path('app/sources/' . $id . '/o/file.raw'));
     if (!$response) {
         // update sync_status
         $this->source->sync_status = "error";
         $sourceRepo->addRecord($this->source, "No response received from server origin", "error");
     } elseif ($response->getStatusCode() == 200) {
         // update origin_format
         $this->source->origin_format = $sourceRepo->guessResponseType($response, $url);
         // update origin_size
         $this->source->origin_size = $sourceRepo->guessResponseLength($response);
         // update synced_at
         $this->source->synced_at = Carbon::now()->toDateTimeString();
         // update sync_status
         $this->source->sync_status = "downloaded";
         $this->source->save();
         // Queue the source to be converted
         $this->dispatch(new ConvertSource($this->source));
         $sourceRepo->addRecord($this->source, "Download success!", "success");
     } else {
         // update sync_status
         $this->source->sync_status = "error";
         $statusCode = $response->getStatusCode();
         $sourceRepo->addRecord($this->source, "Server origin respondend with status code {$statusCode} while downloading" . "error");
     }
     $this->source->save();
 }
Exemplo n.º 2
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(SourceRepository $sourceRepo)
 {
     $this->source->sync_status = "processing";
     $this->source->save();
     $id = $this->source->id;
     $rawFilePath = 'sources/' . $id . '/o/file.raw';
     $procFilePath = 'sources/' . $id . '/p/file.processed';
     // File exists in storage/app/sources/XX/o/file.raw ?
     if (!Storage::exists($rawFilePath)) {
         // update sync_status
         $this->source->sync_status = "error";
         $sourceRepo->addRecord($this->source, "Raw file in {$rawFilePath} does not exists!", "error");
     } elseif (Storage::mimeType($rawFilePath) != 'text/plain' && Storage::mimeType($rawFilePath) != 'application/octet-stream') {
         // update sync_status
         $this->source->sync_status = "error";
         $fileMimeType = Storage::mimeType($rawFilePath);
         $sourceRepo->addRecord($this->source, "Mime type {$fileMimeType} of file in {$rawFilePath} not supported!", "error");
     } else {
         $result = $sourceRepo->convertToGeoJSON($this->source, $rawFilePath, $procFilePath);
         if ($result == true) {
             $this->source->sync_status = "processed";
             // Queue the source to be published
             $this->dispatch(new PublishSource($this->source));
         } else {
             $this->source->sync_status = "error";
         }
     }
     $this->source->save();
     $sourceRepo->addRecord($this->source, "Source processed successfully!", "success");
 }
Exemplo n.º 3
0
 /**
  * Создание источника
  * @return string
  */
 public function actionCreate()
 {
     $model = new Source();
     $uploadImg = new UploadForm();
     if (Yii::$app->request->isPost) {
         $uploadImg->img = UploadedFile::getInstance($uploadImg, 'img');
         if ($uploadImg->img && $uploadImg->validate()) {
             $uploadImg->img->saveAs('uploads/covers/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension);
         } else {
             print_r($uploadImg->getErrors());
         }
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->title = Yii::$app->request->post('Source')['title'];
         $model->author_id = Yii::$app->request->post('Source')['author_id'];
         $model->status = Yii::$app->request->post('Source')['status'];
         $model->cat_id = Yii::$app->request->post('Source')['cat_id'];
         if (isset($uploadImg->img)) {
             $model->cover = Url::base() . 'uploads/covers/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension;
         }
         $model->save(false);
         $sources = Source::find();
         $dataProvider = new ActiveDataProvider(['query' => $sources]);
         return $this->redirect(Url::toRoute('source/index'));
     } else {
         return $this->render('_form', ['model' => $model, 'uploadImg' => $uploadImg]);
     }
 }
Exemplo n.º 4
0
 public function actionCreateAjax()
 {
     $model = new Source();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         echo Json::encode(Source::find()->asArray()->all());
     } else {
         echo "0";
     }
 }
Exemplo n.º 5
0
 /**
  * Creates a new Source model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Source();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 6
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(SourceRepository $sourceRepo)
 {
     $this->source->sync_status = "publishing";
     $this->source->save();
     $id = $this->source->id;
     $hash = $this->source->hash;
     $procFilePath = 'storage/app/sources/' . $id . '/p/file.processed';
     $pubFilePath = 'public/sources/' . $hash . '.geojson';
     // File exists in storage/app/sources/p/file.processed ?
     if (!Storage::disk('base')->exists($procFilePath)) {
         // update sync_status
         $this->source->sync_status = "error";
         $sourceRepo->addRecord($this->source, "Processed file in {$procFilePath} does not exists!", "error");
     } else {
         $result = $sourceRepo->publish($this->source, $procFilePath, $pubFilePath);
         if ($result == true) {
             $this->source->sync_status = "ready";
         } else {
             $this->source->sync_status = "error";
         }
     }
     $this->source->save();
     $sourceRepo->addRecord($this->source, "Source published successfully!", "success");
 }
Exemplo n.º 7
0
 public function uploadSource(Source $source, Request $request)
 {
     //create directory structure
     Storage::makeDirectory('sources/' . $source->id . '/o');
     Storage::makeDirectory('sources/' . $source->id . '/p');
     //move temp file to raw path
     if ($request->hasFile('origin_file')) {
         $source->origin_format = $request->file('origin_file')->getClientOriginalExtension();
         $source->origin_size = $request->file('origin_file')->getClientSize();
         $source->origin_file = $request->file('origin_file')->getClientOriginalName();
         $source->save();
         $request->file('origin_file')->move(storage_path('app/sources/' . $source->id . '/o'), 'file.raw');
         // Queue the source to be converted
         $this->dispatch(new ConvertSource($source));
     }
 }
Exemplo n.º 8
0
 function actionGetMusicLinksAlbom($new_artist)
 {
     $dir = '/home/romanych/Музыка/Thoughts_and_klassik/best_alboms/' . $new_artist;
     //return var_dump($dir);
     try {
         $alboms = scandir($dir);
     } catch (\ErrorException $e) {
         return $e->getMessage();
     }
     if (is_array($alboms)) {
         $alboms = array_diff($alboms, array('.', '..'));
         if ($alboms) {
             foreach ($alboms as $albom) {
                 // return var_dump($albom);
                 $source = new Source();
                 $source->title = $albom;
                 if (Author::find()->where('name like "%' . addslashes($new_artist) . '%"')->one()) {
                     $source->author_id = Author::find()->where("name like '%" . addslashes($new_artist) . "%'")->one()->id;
                 } else {
                     return 'author error';
                 }
                 $source->status = 1;
                 $source->cat_id = 34;
                 if (!$source->save(false)) {
                     return 'source error';
                 } else {
                     echo $source->title . ' made' . PHP_EOL;
                 }
                 $path = $dir . '/' . $albom;
                 if (is_dir($path)) {
                     $songs = scandir($path);
                     $songs = array_diff($songs, array('.', '..'));
                     foreach ($songs as $song) {
                         $song_obj = new SongText();
                         try {
                             $song_obj->source_id = $source->id;
                         } catch (\ErrorException $e) {
                             echo $e->getMessage();
                             continue;
                         }
                         $song_path = $path . '/' . $song;
                         if (is_dir($song_path)) {
                             $sub_songs = scandir($song_path);
                             $sub_songs = array_diff($sub_songs, array('.', '..'));
                             foreach ($sub_songs as $sub_song) {
                                 if (preg_match('/(.+).mp3$/', $sub_song, $match)) {
                                     $song_obj->title = $sub_song;
                                 }
                                 $song_obj->link = substr($path . '/' . $song . '/' . $sub_song, 48);
                             }
                         } else {
                             if (preg_match('/(.+).mp3$/', $song, $match)) {
                                 $song_obj->title = $song;
                                 $song_obj->link = substr($path . '/' . $song, 48);
                             }
                         }
                         $song_obj->save(false);
                     }
                 } else {
                     echo $path . '-----no---dir--------------';
                 }
             }
         }
     }
 }