/**
  * This will launch pending campaigns if there launch date has
  * passed.
  */
 public function processPendingMessages($test = false)
 {
     $now = new Carbon();
     $this->launchedCampaign = false;
     $pendingId = MessageStatus::getPendingStatus()->id;
     $campaign = Message::where('status_id', $pendingId)->get()->filter(function ($message) use($now) {
         return $message->launch_at <= $now;
     })->shift();
     if ($campaign) {
         $this->campaignManager->launchCampaign($campaign, $test);
         $this->logActivity(sprintf('Launched campaign "%s" with %s subscriber(s) queued.', $campaign->name, $campaign->count_subscriber));
         $this->launchedCampaign = true;
     }
 }
 public function repeatCampaign($campaign)
 {
     $duplicate = $campaign->duplicateCampaign();
     $duplicate->is_delayed = true;
     $now = $campaign->freshTimestamp();
     switch ($campaign->repeat_frequency) {
         case 'daily':
             $now = $now->addDay();
             break;
         case 'weekly':
             $now = $now->addWeek();
             break;
         case 'monthly':
             $now = $now->addMonth();
             break;
         case 'yearly':
             $now = $now->addYear();
             break;
         default:
             $now = $now->addYears(5);
             break;
     }
     $duplicate->launch_at = $now;
     $duplicate->status = MessageStatus::getPendingStatus();
     $duplicate->count_repeat++;
     $duplicate->save();
     return $duplicate;
 }