/**
  * Handle the event.
  *
  * @param \CachetHQ\Cachet\Bus\Events\Component\ComponentWasRemovedEvent $event
  *
  * @return void
  */
 public function handle(ComponentWasRemovedEvent $event)
 {
     $component = $event->component;
     $subscription = Subscription::forComponent($component->id);
     // Cleanup the subscriptions.
     $subscription->delete();
 }
 /**
  * Handle the event.
  *
  * @param \CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent $event
  *
  * @return void
  */
 public function handle(ComponentWasUpdatedEvent $event)
 {
     $component = AutoPresenter::decorate($event->component);
     $mail = ['subject' => trans('cachet.subscriber.email.component.subject'), 'component_name' => $component->name, 'component_human_status' => $component->human_status];
     foreach (Subscription::isVerifiedForComponent($component->id)->with('subscriber')->get() as $subscription) {
         $subscriber = $subscription->subscriber;
         $mail['email'] = $subscriber->email;
         $mail['unsubscribe_link'] = route('subscribe.unsubscribe', ['code' => $subscriber->verify_code, 'subscription' => $subscription->id]);
         $this->mailer->queue(['html' => 'emails.components.update-html', 'text' => 'emails.components.update-text'], $mail, function (Message $message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
     }
 }
 /**
  * Handle the subscribe subscriber command.
  *
  * @param \CachetHQ\Cachet\Bus\Commands\Subscriber\UpdateSubscriberSubscriptionCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Subscriber
  */
 public function handle(UpdateSubscriberSubscriptionCommand $command)
 {
     $subscriber = $command->subscriber;
     $subscriptions = $command->subscriptions ?: [];
     $components = Component::all();
     $updateSubscriptions = $components->filter(function ($item) use($subscriptions) {
         return in_array($item->id, $subscriptions);
     });
     $subscriber->global = $updateSubscriptions->count() === $components->count();
     $subscriber->subscriptions()->delete();
     if (!$updateSubscriptions->isEmpty()) {
         foreach ($updateSubscriptions as $subscription) {
             Subscription::firstOrCreate(['subscriber_id' => $subscriber->id, 'component_id' => $subscription->id]);
         }
     }
     $subscriber->save();
     event(new SubscriberHasUpdatedSubscriptionsEvent($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;
 }
Ejemplo n.º 6
0
 /**
  * Handle the unsubscribe.
  *
  * @param string|null $code
  * @param int|null    $subscription
  *
  * @return \Illuminate\View\View
  */
 public function getUnsubscribe($code = null, $subscription = null)
 {
     if ($code === null) {
         throw new NotFoundHttpException();
     }
     $subscriber = Subscriber::where('verify_code', '=', $code)->first();
     if (!$subscriber || !$subscriber->is_verified) {
         throw new BadRequestHttpException();
     }
     if ($subscription) {
         dispatch(new UnsubscribeSubscriptionCommand(Subscription::forSubscriber($subscriber->id)->firstOrFail()));
     } else {
         dispatch(new UnsubscribeSubscriberCommand($subscriber, $subscription));
     }
     return Redirect::route('status-page')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.unsubscribed')));
 }