/**
  * This will send messages subscribers of active campaigns.
  */
 public function processActiveMessages()
 {
     $hourAgo = new Carbon();
     $hourAgo = $hourAgo->subMinutes(15);
     $activeId = MessageStatus::getActiveStatus()->id;
     $campaign = Message::where('status_id', $activeId)->get()->filter(function ($message) use($hourAgo) {
         return !$message->processed_at || $message->processed_at <= $hourAgo;
     })->shift();
     if ($campaign) {
         $subscribers = $campaign->subscribers()->whereNull('sent_at');
         if (($staggerCount = $campaign->getStaggerCount()) !== -1) {
             $subscribers->limit($staggerCount);
         }
         $subscribers = $subscribers->get();
         $countSent = 0;
         foreach ($subscribers as $subscriber) {
             if (!$subscriber->confirmed_at || $subscriber->unsubscribed_at) {
                 $campaign->subscribers()->remove($subscriber);
                 continue;
             }
             $this->campaignManager->sendToSubscriber($campaign, $subscriber);
             $subscriber->pivot->sent_at = $subscriber->freshTimestamp();
             $subscriber->pivot->save();
             $campaign->count_sent++;
             $countSent++;
         }
         if ($campaign->count_sent >= $campaign->count_subscriber) {
             $campaign->status = MessageStatus::getSentStatus();
         }
         $campaign->rebuildStats();
         $campaign->processed_at = $campaign->freshTimestamp();
         $campaign->save();
         $this->logActivity(sprintf('Sent campaign "%s" to %s subscriber(s).', $campaign->name, $countSent));
     }
 }
 public function up()
 {
     Schema::table('responsiv_campaign_messages', function ($table) {
         $table->string('stagger_type')->nullable();
         $table->integer('stagger_count')->nullable();
     });
     MessageModel::where('is_staggered', true)->update(['stagger_type' => 'time']);
 }
Example #3
0
 protected function handleUnsubscribe()
 {
     if (!isset($this->subscriber->pivot)) {
         return 'You are already unsubscribed from our mailing list!';
     }
     $pivot = $this->subscriber->pivot;
     if ($pivot->stop_at) {
         return 'You are already unsubscribed from our mailing list!';
     }
     $pivot->stop_at = $this->campaign->freshTimestamp();
     $pivot->read_at = $this->campaign->freshTimestamp();
     $pivot->save();
     $this->campaign->count_read++;
     $this->campaign->count_stop++;
     $this->campaign->save();
     $this->subscriber->confirmed_at = null;
     $this->subscriber->unsubscribed_at = $this->subscriber->freshTimestamp();
     $this->subscriber->save();
     // @todo Template + Language
     return '<html><head><title>Unsubscribe successful</title></head><body><h1>Unsubscribe successful</h1><p>Your email has been successfully unsubscribed from this list!</p></body></html>';
 }
Example #4
0
 protected function validateCampaignCode($code)
 {
     if (ends_with($code, '.png')) {
         $this->trackingMode = true;
         $code = substr($code, 0, -4);
     }
     $parts = explode('!', base64_decode($code));
     if (count($parts) < 3) {
         throw new ApplicationException('Invalid code');
     }
     list($campaignId, $subscriberId, $hash) = $parts;
     /*
      * Render unique content for the subscriber
      */
     $this->campaign = Message::find((int) $campaignId);
     $this->subscriber = $this->campaign->subscribers()->where('id', (int) $subscriberId)->first();
     if (!$this->subscriber) {
         $this->subscriber = Subscriber::find((int) $subscriberId);
     }
     if (!$this->campaign || !$this->subscriber) {
         throw new ApplicationException('Invalid code');
     }
     /*
      * Verify unique hash
      */
     $verifyValue = $campaignId . '!' . $subscriberId;
     $verifyHash = md5($verifyValue . '!' . $this->subscriber->email);
     if ($hash != $verifyHash) {
         throw new ApplicationException('Invalid hash');
     }
 }
Example #5
0
 public function update($recordId = null, $context = null)
 {
     if ($context == 'send') {
         $this->pageTitle = 'Send campaign message';
     }
     $this->bodyClass = 'compact-container';
     $this->vars['availableTags'] = Message::getAvailableTags();
     return $this->asExtension('FormController')->update($recordId, $context);
 }