/** * Delete Video * @author Oleg D. */ function delete($id = null) { //Configure::write('debug', '1'); $userID = $this->getUserID(); $video = $this->Video->read(null, $id); $this->Access->checkAccess('Video', 'd', $video['Video']['user_id']); if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']) { $back_url = $_SERVER['HTTP_REFERER']; } else { $back_url = '/'; } if ($this->Video->find('count', array('conditions' => array('id' => $id, 'is_deleted' => 0)))) { $this->Video->delete($id); $video = $this->Video->read(null, $id); $albumID = $video['Video']['model_id']; $this->Video->Album->changeFilesNum($albumID, -1); if ($video['Video']['is_file']) { App::import('Vendor', 'YouTube', array('file' => 'class.YouTube.php')); $VideoTube = new YouTube(); $result = $VideoTube->deleteVideo($video['Video']['youtube_id']); } // if is album cover delete it from album cover $albumCoverID = $this->Video->Album->field('cover_video_id', array('id' => $video['Video']['model_id'])); if ($albumCoverID == $id) { $newCoverID = intval($this->Video->field('id', array('model' => 'Album', 'model_id' => $video['Video']['model_id'], 'is_deleted' => 0))); $this->Video->Album->save(array('cover_video_id' => $newCoverID, 'id' => $video['Video']['model_id'])); } Cache::delete('last_videos'); $this->Session->setFlash('Video has been deleted', 'flash_success'); if ($video['Video']['model_id']) { return $this->redirect('/Albums/show_video/' . $video['Video']['model_id']); } } else { $this->Session->setFlash(__('There is no such video'), 'flash_error'); } $this->goHome(); exit; }