/** * Handle the event. * * @param \CachetHQ\Cachet\Bus\Events\Incident\IncidentHasReportedEvent $event * * @return void */ public function handle(IncidentWasReportedEvent $event) { if (!$event->incident->notify) { return false; } $incident = AutoPresenter::decorate($event->incident); $component = AutoPresenter::decorate($event->incident->component); // Only send emails for public incidents. if ($event->incident->visible === 1) { foreach ($this->subscriber->isVerified()->get() as $subscriber) { $mail = ['email' => $subscriber->email, 'subject' => 'New incident reported.', 'has_component' => $event->incident->component ? true : false, 'component_name' => $component ? $component->name : null, 'status' => $incident->human_status, 'html_content' => $incident->formattedMessage, 'text_content' => $incident->message, 'token' => $subscriber->token, 'manage_link' => route('subscribe.manage', ['code' => $subscriber->verify_code]), 'unsubscribe_link' => route('subscribe.unsubscribe', ['code' => $subscriber->verify_code])]; $this->mailer->queue(['html' => 'emails.incidents.new-html', 'text' => 'emails.incidents.new-text'], $mail, function (Message $message) use($mail) { $message->to($mail['email'])->subject($mail['subject']); }); } } }
/** * Handle the event. * * @param \CachetHQ\Cachet\Bus\Events\Incident\IncidentWasReportedEvent $event * * @return void */ public function handle(IncidentWasReportedEvent $event) { if (!$event->incident->notify) { return false; } // Only send emails for public incidents. if ($event->incident->visible === 0) { return; } // First notify all global subscribers. $globalSubscribers = $this->subscriber->isVerified()->isGlobal()->get(); foreach ($globalSubscribers as $subscriber) { $this->notify($event, $subscriber); } if (!$event->incident->component) { return; } $notified = $globalSubscribers->pluck('id')->all(); // Notify the remaining component specific subscribers. $componentSubscribers = $this->subscriber->isVerified()->forComponent($event->incident->component->id)->get()->reject(function ($subscriber) use($notified) { return in_array($subscriber->id, $notified); }); foreach ($componentSubscribers as $subscriber) { $this->notify($event, $subscriber); } }
/** * Handle the event. * * @param \CachetHQ\Cachet\Events\MaintenanceHasScheduledEvent $event */ public function handle(MaintenanceHasScheduledEvent $event) { $data = $this->presenter->decorate($event->incident); foreach ($this->subscriber->all() as $subscriber) { $mail = ['email' => $subscriber->email, 'subject' => 'Scheduled maintenance.', 'status' => $data->humanStatus, 'htmlContent' => $data->formattedMessage, 'textContent' => $data->message, 'token' => $subscriber->token, 'unsubscribeLink' => route('unsubscribe', ['code' => $subscriber->token]), 'appUrl' => env('APP_URL')]; $this->mailer->queue(['html' => 'emails.incidents.maintenance-html', 'text' => 'emails.incidents.maintenance-text'], $mail, function (Message $message) use($mail) { $message->to($mail['email'])->subject($mail['subject']); }); } }
/** * Handle the event. * * @param \CachetHQ\Cachet\Events\IncidentHasReportedEvent $event */ public function handle(IncidentHasReportedEvent $event) { $data = $this->presenter->decorate($event->incident); // Only send emails for public incidents. if ($event->incident->visible === 1) { foreach ($this->subscriber->all() as $subscriber) { $mail = ['email' => $subscriber->email, 'subject' => 'New incident reported.', 'status' => $data->humanStatus, 'htmlContent' => $data->formattedMessage, 'textContent' => $data->message, 'token' => $subscriber->token, 'unsubscribeLink' => route('unsubscribe', ['code' => $subscriber->verify_code]), 'appUrl' => env('APP_URL')]; $this->mailer->queue(['html' => 'emails.incidents.new-html', 'text' => 'emails.incidents.new-text'], $mail, function (Message $message) use($mail) { $message->to($mail['email'])->subject($mail['subject']); }); } } }
/** * Handle the event. * * @param \CachetHQ\Cachet\Events\MaintenanceHasScheduledEvent $event * * @return void */ public function handle(MaintenanceWasScheduledEvent $event) { if (!$event->incident->notify) { return false; } $data = AutoPresenter::decorate($event->incident); foreach ($this->subscriber->all() as $subscriber) { $mail = ['email' => $subscriber->email, 'subject' => 'Scheduled maintenance.', 'status' => $data->humanStatus, 'html_content' => $data->formattedMessage, 'text_content' => $data->message, 'scheduled_at' => $data->scheduled_at_formatted, 'token' => $subscriber->token, 'unsubscribe_link' => route('subscribe.unsubscribe', ['code' => $subscriber->verify_code]), 'app_url' => env('APP_URL')]; $this->mailer->queue(['html' => 'emails.incidents.maintenance-html', 'text' => 'emails.incidents.maintenance-text'], $mail, function (Message $message) use($mail) { $message->to($mail['email'])->subject($mail['subject']); }); } }
/** * Handle the event. * * @param \CachetHQ\Cachet\Events\Incident\IncidentHasReportedEvent $event * * @return void */ public function handle(IncidentWasReportedEvent $event) { $incident = $this->presenter->decorate($event->incident); $component = $this->presenter->decorate($event->incident->component); // Only send emails for public incidents. if ($event->incident->visible === 1) { foreach ($this->subscriber->all() as $subscriber) { $mail = ['email' => $subscriber->email, 'subject' => 'New incident reported.', 'has_component' => $event->incident->component ? true : false, 'component_name' => $component ? $component->name : null, 'status' => $incident->humanStatus, 'html_content' => $incident->formattedMessage, 'text_content' => $incident->message, 'token' => $subscriber->token, 'unsubscribe_link' => route('subscribe.unsubscribe', ['code' => $subscriber->verify_code]), 'app_url' => env('APP_URL')]; $this->mailer->queue(['html' => 'emails.incidents.new-html', 'text' => 'emails.incidents.new-text'], $mail, function (Message $message) use($mail) { $message->to($mail['email'])->subject($mail['subject']); }); } } }
/** * Bind data to the view. * * @param \Illuminate\Contracts\View\View $view * * @return void */ public function compose(View $view) { $view->withIncidentCount(Incident::notScheduled()->count()); $view->withIncidentTemplateCount(IncidentTemplate::count()); $view->withComponentCount(Component::all()->count()); $view->withSubscriberCount(Subscriber::isVerified()->count()); }
/** * Handle the event. * * @param \CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent $event * * @return void */ public function handle(ComponentWasUpdatedEvent $event) { $component = $event->component; // First notify all global subscribers. $globalSubscribers = $this->subscriber->isVerified()->isGlobal()->get(); foreach ($globalSubscribers as $subscriber) { $this->notify($component, $subscriber); } $notified = $globalSubscribers->pluck('id')->all(); // Notify the remaining component specific subscribers. $componentSubscribers = $this->subscriber->isVerified()->forComponent($component->id)->get()->reject(function ($subscriber) use($notified) { return in_array($subscriber->id, $notified); }); foreach ($componentSubscribers as $subscriber) { $this->notify($component, $subscriber); } }
/** * Handle the subscribe subscriber command. * * @param \CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand $command * * @return \CachetHQ\Cachet\Models\Subscriber */ public function handle(SubscribeSubscriberCommand $command) { $subscriber = Subscriber::create(['email' => $command->email]); if ($command->verified) { $this->dispatch(new VerifySubscriberCommand($subscriber)); } else { event(new SubscriberHasSubscribedEvent($subscriber)); } return $subscriber; }
/** * Handle the unsubscribe. * * @param string|null $code * * @return \Illuminate\View\View */ public function getUnsubscribe($code = null) { if (is_null($code)) { throw new NotFoundHttpException(); } $subscriber = Subscriber::where('verify_code', '=', $code)->first(); if (!$subscriber || !$subscriber->verified()) { return Redirect::route('status-page'); } $subscriber->delete(); return Redirect::route('status-page')->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.unsuscribed'))); }
/** * Handle the unsubscribe. * * @param string|null $code * * @return \Illuminate\View\View */ public function getUnsubscribe($code = null) { if ($code === null) { throw new NotFoundHttpException(); } $subscriber = Subscriber::where('verify_code', '=', $code)->first(); if (!$subscriber || !$subscriber->is_verified) { throw new BadRequestHttpException(); } dispatch(new UnsubscribeSubscriberCommand($subscriber)); return Redirect::route('status-page')->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.unsubscribed'))); }
/** * Handle the subscribe subscriber command. * * @param \CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand $command * * @throws \CachetHQ\Cachet\Exceptions\AlreadySubscribedException * * @return \CachetHQ\Cachet\Models\Subscriber */ public function handle(SubscribeSubscriberCommand $command) { if (Subscriber::where('email', $command->email)->first()) { throw new AlreadySubscribedException("Cannot subscribe {$command->email} because they're already subscribed."); } $subscriber = Subscriber::create(['email' => $command->email]); if ($command->verified) { $this->dispatch(new VerifySubscriberCommand($subscriber)); } else { event(new SubscriberHasSubscribedEvent($subscriber)); } return $subscriber; }
/** * Handle the subscribe subscriber command. * * @param \CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand $command * * @return \CachetHQ\Cachet\Models\Subscriber */ public function handle(SubscribeSubscriberCommand $command) { if ($subscriber = Subscriber::where('email', $command->email)->first()) { return $subscriber; } $subscriber = Subscriber::firstOrCreate(['email' => $command->email]); // Decide what to subscribe the subscriber to. if ($subscriptions = $command->subscriptions) { $subscriptions = Component::whereIn('id', $subscriptions); } else { $subscriptions = Component::all(); } foreach ($subscriptions as $component) { Subscription::create(['subscriber_id' => $subscriber->id, 'component_id' => $component->id]); } if ($command->verified) { dispatch(new VerifySubscriberCommand($subscriber)); } else { event(new SubscriberHasSubscribedEvent($subscriber)); } return $subscriber; }
/** * Handle the subscribe subscriber command. * * @param \CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand $command * * @throws \CachetHQ\Cachet\Exceptions\AlreadySubscribedException * * @return \CachetHQ\Cachet\Models\Subscriber */ public function handle(SubscribeSubscriberCommand $command) { if (Subscriber::where('email', $command->email)->first() && $command->subscriptions === null) { throw new AlreadySubscribedException("Cannot subscribe {$command->email} because they're already subscribed."); } $subscriber = Subscriber::firstOrCreate(['email' => $command->email]); if ($subscriptions = $command->subscriptions) { foreach ($subscriptions as $subscription => $subscriptionValue) { Subscription::firstOrCreate(['subscriber_id' => $subscriber->id, $subscription => $subscriptionValue]); } } if ($subscriber->is_verified === false) { if ($command->verified) { dispatch(new VerifySubscriberCommand($subscriber)); } else { event(new SubscriberHasSubscribedEvent($subscriber)); } } else { event(new SubscriberHasUpdatedSubscriptionsEvent($subscriber)); } return $subscriber; }
/** * Get all subscribers. * * @return \Illuminate\Http\JsonResponse */ public function getSubscribers() { $subscribers = Subscriber::paginate(Binput::get('per_page', 20)); return $this->paginator($subscribers, Request::instance()); }
/** * Updates the subscription manager for a subscriber. * * @param string|null $code * * @return \Illuminate\View\View */ public function postManage($code = null) { if ($code === null) { throw new NotFoundHttpException(); } $subscriber = Subscriber::where('verify_code', '=', $code)->first(); if (!$subscriber) { throw new BadRequestHttpException(); } try { dispatch(new UpdateSubscriberSubscriptionCommand($subscriber, Binput::get('subscriptions'))); } catch (ValidationException $e) { dd($e->getMessageBag()); return Redirect::route('subscribe.manage', $subscriber->verify_code)->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('cachet.subscriber.email.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('subscribe.manage', $subscriber->verify_code)->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.subscribed'))); }
/** * Deletes a subscriber. * * @param \CachetHQ\Cachet\Models\Subscriber $subscriber * * @throws \Exception * * @return \Illuminate\Http\RedirectResponse */ public function deleteSubscriberAction(Subscriber $subscriber) { $subscriber->delete(); return Redirect::route('dashboard.subscribers.index'); }
/** * Shows the subscribers view. * * @return \Illuminate\View\View */ public function showSubscribers() { return View::make('dashboard.subscribers.index')->withPageTitle(trans('dashboard.subscribers.subscribers') . ' - ' . trans('dashboard.dashboard'))->withSubscribers(Subscriber::all()); }
/** * Shows the subscription manager page. * * @param string|null $code * * @return \Illuminate\View\View */ public function showManage($code = null) { if ($code === null) { throw new NotFoundHttpException(); } $subscriber = Subscriber::where('verify_code', '=', $code)->first(); if (!$subscriber || !$subscriber->is_verified) { throw new BadRequestHttpException(); } return View::make('subscribe.manage')->withSubscriber($subscriber); }
/** * Get all subscribers. * * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Illuminate\Http\JsonResponse */ public function getSubscribers(Request $request) { $subscribers = Subscriber::paginate(Binput::get('per_page', 20)); return $this->paginator($subscribers, $request); }
/** * Seed the subscribers. * * @return void */ protected function seedSubscribers() { Subscriber::truncate(); }
/** * Delete a subscriber. * * @param \CachetHQ\Cachet\Models\Subscriber $subscriber * * @return \Illuminate\Http\JsonResponse */ public function deleteSubscriber(Subscriber $subscriber) { $subscriber->delete(); return $this->noContent(); }
/** * Deletes a subscriber. * * @param \CachetHQ\Cachet\Models\Subscriber $subscriber * * @throws \Exception * * @return \Illuminate\Http\RedirectResponse */ public function deleteSubscriberAction(Subscriber $subscriber) { segment_track('Dashboard', ['event' => 'Deleted Subscriber']); $subscriber->delete(); return Redirect::back(); }
/** * Deletes a subscriber. * * @param \CachetHQ\Cachet\Models\Subscriber $subscriber * * @throws \Exception * * @return \Illuminate\Http\RedirectResponse */ public function deleteSubscriberAction(Subscriber $subscriber) { $subscriber->delete(); return Redirect::back(); }
/** * Fetches all of the subscribers over the last 30 days. * * @return \Illuminate\Support\Collection */ protected function getSubscribers() { $allSubscribers = Subscriber::whereBetween('created_at', [$this->startDate->copy()->subDays(30)->format('Y-m-d') . ' 00:00:00', $this->startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('created_at', 'desc')->get()->groupBy(function (Subscriber $incident) { return (new Date($incident->created_at))->setTimezone($this->dateTimeZone)->toDateString(); }); // Add in days that have no incidents foreach (range(0, 30) as $i) { $date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i); if (!isset($allSubscribers[$date->toDateString()])) { $allSubscribers[$date->toDateString()] = []; } } // Sort the array so it takes into account the added days $allSubscribers = $allSubscribers->sortBy(function ($value, $key) { return strtotime($key); }, SORT_REGULAR, false); return $allSubscribers; }