コード例 #1
0
ファイル: MediaItem.php プロジェクト: joshhodgson/Website
 protected static function boot()
 {
     parent::boot();
     self::saving(function ($model) {
         if ($model->enabled && is_null($model->scheduled_publish_time)) {
             throw new Exception("A MediaItem which is enabled must have a scheduled publish time.");
         }
         // transaction ended in "saved" event
         // needed to make sure if search index version number is incremented it
         // takes effect at the same time that the rest of the media item is updated
         DB::beginTransaction();
         // assume that something has changed and force ths item to be reindexed
         $a = MediaItem::find(intval($model->id));
         // $a may be null if this item is currently being created
         // when the item is being created pending_search_index_version defaults to 1
         // meaning the item will be indexed
         if (!is_null($a)) {
             // make sure get latest version number. The version in $model might have changed before the transaction started
             $currentPendingIndexVersion = intval($a->pending_search_index_version);
             $model->pending_search_index_version = $currentPendingIndexVersion + 1;
         }
         return true;
     });
     self::saved(function ($model) {
         DB::commit();
     });
 }
コード例 #2
0
 public function handleMediaItemRequest($mediaItemId)
 {
     $mediaItem = MediaItem::find($mediaItemId);
     if (is_null($mediaItem) || !$mediaItem->getIsAccessible()) {
         $this->do404Response();
         return;
     }
     $playlist = $mediaItem->getDefaultPlaylist();
     if (is_null($playlist)) {
         $this->do404Response();
         return;
     }
     $this->prepareResponse($playlist, $mediaItem);
 }
コード例 #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // presumes that media items already exist and ids from autoincrement
     DB::transaction(function () {
         $playlist = new Playlist(array("name" => "Roses 2014!", "enabled" => true, "description" => "Description about roses 2014 series.", "series_no" => 1, "scheduled_publish_time" => Carbon::now()));
         $playlist->show()->associate(Show::find(1));
         $playlist->save();
         $playlist->mediaItems()->attach(MediaItem::find(1), array("position" => 0));
         $playlist->mediaItems()->attach(MediaItem::find(2), array("position" => 1));
     });
     DB::transaction(function () {
         $playlist = Playlist::create(array("name" => "Top Shows", "enabled" => true, "description" => "LA1:TV's top shows for 2014.", "scheduled_publish_time" => Carbon::now()));
         $playlist->mediaItems()->attach(MediaItem::find(2), array("position" => 0));
     });
     $this->command->info('Playlists created and media items added!');
 }
コード例 #4
0
 public function postDelete()
 {
     Auth::getUser()->hasPermissionOr401(Config::get("permissions.mediaItems"), 1);
     $resp = array("success" => false);
     if (FormHelpers::hasPost("id")) {
         $id = intval($_POST["id"], 10);
         DB::transaction(function () use(&$id, &$resp) {
             $mediaItem = MediaItem::find($id);
             if (!is_null($mediaItem)) {
                 if ($mediaItem->isDeletable()) {
                     // mark any related files as no longer in use (so they will be removed)
                     Upload::delete(array($mediaItem->sideBannerFile, $mediaItem->sideBannerFillFile, $mediaItem->coverFile, ObjectHelpers::getProp(null, $mediaItem->videoItem, "sourceFile"), ObjectHelpers::getProp(null, $mediaItem->videoItem, "coverArtFile")));
                     if ($mediaItem->delete() === false) {
                         throw new Exception("Error deleting MediaItem.");
                     }
                     $resp['success'] = true;
                 } else {
                     $resp['msg'] = "This media item cannot be deleted at the moment as it is being used in other places.";
                 }
             }
         });
     }
     return Response::json($resp);
 }