Example #1
0
 protected static function boot()
 {
     parent::boot();
     self::saving(function ($model) {
         $sourceFileForeignKey = $model->sourceFile()->getForeignKey();
         $uploadPointForeignKey = $model->uploadPoint()->getForeignKey();
         if ($model->exists && $model->original["in_use"] && !$model->in_use && !$model->ready_for_delete) {
             throw new Exception("The file can only be marked in_use once.");
         } else {
             if ($model->exists && $model->original["ready_for_delete"]) {
                 throw new Exception("This file is pending deletion and can no longer be modified.");
             } else {
                 if (!$model->in_use && (!EloquentHelpers::getIsForeignNull($model->mediaItemVideoWithFile()) || !EloquentHelpers::getIsForeignNull($model->mediaItemWithCover()) || !EloquentHelpers::getIsForeignNull($model->mediaItemWithBanner()) || !EloquentHelpers::getIsForeignNull($model->mediaItemWithCoverArt()) || !EloquentHelpers::getIsForeignNull($model->playlistWithCover()) || !EloquentHelpers::getIsForeignNull($model->playlistWithBanner()) || !EloquentHelpers::getIsForeignNull($model->playlistWithCoverArt()))) {
                     throw new Exception("File must be marked as in use before it can belong to anything.");
                 } else {
                     if ($model->exists && $model->original[$sourceFileForeignKey] !== $model->{$sourceFileForeignKey} || !$model->exists && !is_null($model->{$sourceFileForeignKey})) {
                         throw new Exception("The source file should only be set externally.");
                     } else {
                         if ($model->exists && $model->original[$uploadPointForeignKey] !== $model->{$uploadPointForeignKey}) {
                             throw new Exception("The upload point can only be set on creation.");
                         }
                     }
                 }
             }
         }
         return true;
     });
 }
Example #2
0
 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();
     });
 }
Example #3
0
 protected static function boot()
 {
     parent::boot();
     self::saving(function ($model) {
         // 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 = Show::with("playlists", "playlists.mediaItems")->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;
             // also force all playlists liked to this and media items in them to be reindexed
             // because media items and playlists contain show information in their indexes
             foreach ($a->playlists as $playlist) {
                 $playlist->pending_search_index_version += 1;
                 $playlist->save();
                 foreach ($playlist->mediaItems as $mediaItem) {
                     $mediaItem->pending_search_index_version += 1;
                     $mediaItem->save();
                 }
             }
         }
         return true;
     });
     self::saved(function ($model) {
         DB::commit();
     });
 }
 protected static function boot()
 {
     parent::boot();
     self::saving(function ($model) {
         // transaction committed in saved event
         // transaction important because entries created/removed in dvr_live_stream_uris
         // depending on stream state so must always change in sync with stream state.
         DB::beginTransaction();
         if ($model->hasJustLeftLive() && $model->hasJustBecomeStreamOver()) {
             // send command to DVR Bridge Service servers to stop recording stream
             // if this fails the dvr link will be removed
             $model->stopDvrs();
             // record the time that the stream is being marked as over
             $model->end_time = Carbon::now();
         }
         if ($model->hasJustBecomeStreamOver() && ($model->hasJustLeftLive() || $model->hasJustLeftNotLive())) {
             // run these once the response has been sent to the user just before the script ends
             // this makes sure if this is currently in a transaction the transaction will have ended
             Event::listen('app.finish', function () use(&$model) {
                 Event::fire('mediaItemLiveStream.showOver', array($model));
             });
         }
         if ($model->hasJustBecomeNotLive() && ($model->hasJustLeftLive() || $model->hasJustLeftStreamOver())) {
             // send command to DVR Bridge Service servers to stop recording stream
             // and inform it that the recording can be deleted.
             // entry will be removed from dvr_stream_uris table
             $model->removeDvrs();
             // run these once the response has been sent to the user just before the script ends
             // this makes sure if this is currently in a transaction the transaction will have ended
             Event::listen('app.finish', function () use(&$model) {
                 Event::fire('mediaItemLiveStream.notLive', array($model));
             });
         }
         if ($model->liveStreamHasChanged()) {
             // if the live stream attached to this media item live stream has just been changed
             // then remove any dvr links as they will be to the previous live stream
             $model->removeDvrs();
         }
         return true;
     });
     self::saved(function ($model) {
         // this can't be in the saving callback because this needs to have an id so it can be associated with a MediaItemLiveStream,
         // and if this is the first ever save because the model is being created it won't have an id yet.
         if ($model->hasJustBecomeLive()) {
             // send command to DVR Bridge Service servers to start recording stream
             // and create entry in dvr_stream_uris table
             $model->startDvrs();
         }
         // transaction starts in save event
         DB::commit();
         if ($model->hasJustBecomeLive()) {
             // run these once the response has been sent to the user just before the script ends
             // this makes sure if this is currently in a transaction the transaction will have ended
             Event::listen('app.finish', function () use(&$model) {
                 Event::fire('mediaItemLiveStream.live', array($model));
                 Queue::push("uk\\co\\la1tv\\website\\jobs\\MediaItemLiveEmailsJob", array("mediaItemId" => intval($model->mediaItem->id)));
             });
         }
     });
 }
Example #5
0
 protected static function boot()
 {
     parent::boot();
     self::saving(function ($model) {
         if ($model->dvr_bridge_service_uri && !is_null($model->has_dvr)) {
             throw new Exception("has_dvr must be null if it's a dvr bridge service uri.");
         } else {
             if (!$model->dvr_bridge_service_uri && is_null($model->has_dvr)) {
                 throw new Exception("has_dvr must not be null if it's not a dvr bridge service uri.");
             }
         }
         return true;
     });
 }
Example #6
0
 protected static function boot()
 {
     parent::boot();
     self::creating(function ($model) {
         $model->original_session_id = $model->session_id;
         return true;
     });
     self::saving(function ($model) {
         if ($model->type !== "vod" && $model->type !== "live") {
             throw new Exception("Invalid type.");
         }
         return true;
     });
 }
Example #7
0
 protected static function boot()
 {
     parent::boot();
     self::saving(function ($model) {
         if ($model->resultsInNoAccessibleAdminLogin()) {
             throw new Exception("Cannot save this user as it would result in there being no admin with access to the system.");
         }
         return true;
     });
     self::deleting(function ($model) {
         if ($model->resultsInNoAccessibleAdminLogin(true)) {
             throw new Exception("Cannot delete this user as it would result in there being no admin with access to the system.");
         }
         return true;
     });
 }
Example #8
0
 protected static function boot()
 {
     parent::boot();
     self::saving(function ($model) {
         if ($model->enabled && is_null($model->scheduled_publish_time)) {
             throw new Exception("A Playlist which is enabled must have a scheduled publish time.");
         } else {
             if ($model->show_id === NULL) {
                 if ($model->name === NULL) {
                     throw new Exception("A name must be specified.");
                 } else {
                     if ($model->series_no !== NULL) {
                         throw new Exception("A standard playlist cannot have a series number.");
                     }
                 }
             } else {
                 if ($model->series_no === NULL) {
                     throw new Exception("Series number required.");
                 }
             }
         }
         // 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 = Playlist::with("mediaItems")->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;
             // also force reindex of all items that are currently in the playlist
             foreach ($a->mediaItems as $mediaItem) {
                 $mediaItem->touch();
             }
         }
         return true;
     });
     self::saved(function ($model) {
         DB::commit();
     });
 }
Example #9
0
 protected static function boot()
 {
     parent::boot();
     self::saving(function ($model) {
         // transaction committed in saved event
         // transaction important because entries removed in dvr_live_stream_uris
         // depending if vod is available. both the vod going live and dvr entries
         // being removed must succeed
         DB::beginTransaction();
     });
     self::saved(function ($model) {
         if ($model->getIsLive()) {
             // remove any dvr recordings from the stream belonging to this media item
             // if there are any
             $liveStreamItem = $model->mediaItem->liveStreamItem;
             if (!is_null($liveStreamItem)) {
                 $liveStreamItem->removeDvrs();
             }
         }
         // transaction starts in save event
         DB::commit();
     });
 }