/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if (!DebugHelpers::shouldSiteBeLive()) {
         $this->info('Not running because site should not be live at the moment.');
         return;
     }
     $this->info('Looking for media items that are starting in 15 minutes.');
     $fifteenMinsAhead = Carbon::now()->addMinutes(15);
     $lowerBound = (new Carbon($fifteenMinsAhead))->subSeconds(90);
     $upperBound = new Carbon($fifteenMinsAhead);
     // media items which have a live stream going live in 15 minutes.
     $mediaItemsStartingInFifteen = DB::transaction(function () use(&$lowerBound, &$upperBound) {
         $mediaItemsStartingInFifteen = MediaItem::accessible()->whereHas("liveStreamItem", function ($q) {
             $q->accessible()->notLive();
         })->whereHas("emailTasksMediaItem", function ($q2) {
             $q2->where("message_type_id", EmailHelpers::getMessageTypeIds()['liveInFifteen'])->where("created_at", ">=", Carbon::now()->subMinutes(40));
         }, "=", 0)->where("email_notifications_enabled", true)->where("scheduled_publish_time", ">=", $lowerBound)->where("scheduled_publish_time", "<", $upperBound)->orderBy("scheduled_publish_time", "desc")->lockForUpdate()->get();
         foreach ($mediaItemsStartingInFifteen as $a) {
             $emailTask = new EmailTasksMediaItem(array("message_type_id" => EmailHelpers::getMessageTypeIds()['liveInFifteen']));
             // create an entry in the tasks table for the emails that are going to be sent
             $a->emailTasksMediaItem()->save($emailTask);
         }
         return $mediaItemsStartingInFifteen;
     });
     foreach ($mediaItemsStartingInFifteen as $a) {
         $this->info("Building and sending email for media item with id " . $a->id . " and name \"" . $a->name . "\" which is starting in 15 minutes.");
         EmailHelpers::sendMediaItemEmail($a, 'LA1:TV Live Shortly With "{title}"', "Live shortly!", "We will be streaming live in less than 15 minutes!");
         $this->info("Sent email to users.");
     }
     $this->info("Finished.");
 }
Ejemplo n.º 2
0
 public function fire($job, $data)
 {
     if (!DebugHelpers::shouldSiteBeLive()) {
         $job->release();
         // put the job back on the queue
         return;
     }
     // remove the job from the queue to make sure it only runs once even if an exception is thrown
     $job->delete();
     $mediaItemId = $data['mediaItemId'];
     Log::info("Starting job to send email for media item with id " . $mediaItemId . " which has gone live.");
     // retrieve the media item
     $mediaItem = DB::transaction(function () use(&$mediaItemId) {
         $mediaItem = MediaItem::accessible()->whereHas("liveStreamItem", function ($q) {
             $q->accessible()->live();
         })->whereHas("emailTasksMediaItem", function ($q2) {
             $q2->where("message_type_id", EmailHelpers::getMessageTypeIds()['liveNow'])->where("created_at", ">=", Carbon::now()->subMinutes(40));
         }, "=", 0)->where("email_notifications_enabled", true)->where("id", $mediaItemId)->lockForUpdate()->first();
         if (!is_null($mediaItem)) {
             $emailTask = new EmailTasksMediaItem(array("message_type_id" => EmailHelpers::getMessageTypeIds()['liveNow']));
             // create an entry in the tasks table for the emails that are going to be sent
             $mediaItem->emailTasksMediaItem()->save($emailTask);
         }
         return $mediaItem;
     });
     if (!is_null($mediaItem)) {
         EmailHelpers::sendMediaItemEmail($mediaItem, 'LA1:TV Live Now With "{title}"', "Live now!", "We are streaming live right now!");
     }
     Log::info("Finished job to send email for media item with id " . $mediaItemId . " which has gone live.");
 }
Ejemplo n.º 3
0
 public function getComingUpMediaItem()
 {
     return MediaItem::accessible()->whereHas("liveStreamItem", function ($q) {
         $q->accessible()->notLive()->whereHas("livestream", function ($q2) {
             // the live stream doesn't actually have to be accessible right now
             // the assumption is that it will be at the time this is due to go live
             $q2->where("id", intval($this->id));
         });
     })->orderBy("scheduled_publish_time", "desc")->first();
 }
 public function generateMediaItemPlaylistsResponseData($mediaItemId)
 {
     $mediaItem = MediaItem::accessible()->find(intval($mediaItemId));
     if (is_null($mediaItem)) {
         return $this->generateNotFound();
     }
     $playlists = $mediaItem->playlists()->orderBy("id", "asc")->get()->all();
     $data = $this->playlistTransformer->transformCollection($playlists);
     return new ApiResponseData($data);
 }
Ejemplo n.º 5
0
 public function postDeleteComment($mediaItemId)
 {
     $mediaItem = MediaItem::accessible()->find($mediaItemId);
     if (is_null($mediaItem)) {
         App::abort(404);
     }
     // true if a user is logged into the cms and has permission to manage comments and post as station.
     $userHasCommentsPermission = Auth::isLoggedIn() && Auth::getUser()->hasPermission(Config::get("permissions.siteComments"), 0);
     if ((!Facebook::isLoggedIn() || Facebook::getUserState() !== 0) && !$userHasCommentsPermission) {
         App::abort(403);
     }
     $id = FormHelpers::getValue("id");
     if (is_null($id)) {
         throw new Exception("Id must be supplied.");
     }
     $id = intval($id);
     $comment = $mediaItem->comments()->find($id);
     if (is_null($comment)) {
         throw new Exception("Comment could not be found.");
     }
     if (!$userHasCommentsPermission && intval($comment->siteUser->id) !== intval(Facebook::getUser()->id)) {
         App::abort(403);
     }
     $comment->delete();
     return Response::json(array("success" => true));
 }