diff --git a/Controller/VideoFilesController.php b/Controller/VideoFilesController.php index e19c3ba..a52a7d4 100644 --- a/Controller/VideoFilesController.php +++ b/Controller/VideoFilesController.php @@ -80,7 +80,23 @@ public function file() { // ダウンロード実行 if ($video) { - return $this->Download->doDownload($video['Video']['id']); + //NC2からNC3で移行するとサムネイルが移行されないため、サムネイル画像がないときはNoImageを表示させる + //@see https://github.com/NetCommons3/NetCommons3/issues/1617 + try { + $response = $this->Download->doDownload($video['Video']['id']); + } catch (Exception $ex) { + if (!empty($this->request->params['pass']) && + $this->request->params['pass'][0] === Video::THUMBNAIL_FIELD) { + //NoImageを表示する + $noimagePath = CakePlugin::path('Videos') . + 'webroot' . DS . 'img' . DS . 'thumbnail_noimage.png'; + $this->response->file($noimagePath, ['name' => 'No Image']); + $response = $this->response; + } else { + throw $ex; + } + } + return $response; } else { // 表示できないなら404 throw new NotFoundException(__d('videos', 'Invalid video entry')); diff --git a/Model/Behavior/VideoValidationBehavior.php b/Model/Behavior/VideoValidationBehavior.php index e5e15f9..83a3406 100644 --- a/Model/Behavior/VideoValidationBehavior.php +++ b/Model/Behavior/VideoValidationBehavior.php @@ -172,6 +172,14 @@ public function rules(Model $model, $options = array()) { ), ), )); + + //NC2からNC3で移行するとサムネイルが移行されないため、サムネイルのupload_idが空であれば、 + //エラーにならないようにunsetする。 + //@see https://github.com/NetCommons3/NetCommons3/issues/1617 + if (isset($model->data['UploadFile']['thumbnail']['id']) && + ! $model->data['UploadFile']['thumbnail']['id']) { + unset($model->data['UploadFile']['thumbnail']); + } } return $rules; diff --git a/webroot/img/thumbnail_noimage.png b/webroot/img/thumbnail_noimage.png new file mode 100644 index 0000000..6ef4242 Binary files /dev/null and b/webroot/img/thumbnail_noimage.png differ