public function up() { Schema::table('responsiv_campaign_subscribers', function ($table) { $table->string('created_ip_address')->nullable(); $table->string('confirmed_ip_address')->nullable(); $table->timestamp('confirmed_at')->nullable(); $table->string('message_type')->nullable()->default('html'); }); SubscriberModel::whereNull('confirmed_at')->update(['confirmed_at' => new Carbon()]); }
public function index_onDelete() { if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { foreach ($checkedIds as $recordId) { if (!($record = Subscriber::find($recordId))) { continue; } $record->delete(); } Flash::success(Lang::get('backend::lang.list.delete_selected_success')); } else { Flash::error(Lang::get('backend::lang.list.delete_selected_empty')); } return $this->listRefresh(); }
public function importData($results, $sessionKey = null) { $firstRow = reset($results); /* * Validation */ if ($this->auto_create_lists && !array_key_exists('lists', $firstRow)) { throw new ApplicationException('Please specify a match for the Lists column.'); } /* * Import */ foreach ($results as $row => $data) { try { if (!($email = array_get($data, 'email'))) { $this->logSkipped($row, 'Missing email address'); continue; } /* * Find or create */ $subscriber = Subscriber::firstOrNew(['email' => $email]); $subscriberExists = $subscriber->exists; /* * Set attributes */ $except = ['lists']; foreach (array_except($data, $except) as $attribute => $value) { $subscriber->{$attribute} = $value ?: null; } $subscriber->forceSave(); if ($listIds = $this->getListIdsForSubscriber($data)) { $subscriber->subscriber_lists()->sync($listIds, false); } /* * Log results */ if ($subscriberExists) { $this->logUpdated(); } else { $this->logCreated(); } } catch (Exception $ex) { $this->logError($row, $ex->getMessage()); } } }
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>'; }
/** * Binds all subscribers from the campaign groups to the message. */ public function bindGroupSubscribers($campaign) { $groups = $campaign->groups; if (!is_array($groups)) { return; } /* * Get all group subscriber emails and info */ $groupSubscribers = []; foreach ($groups as $groupType) { $groupSubscribers = $groupSubscribers + $this->getGroupRecipientsData($groupType); } /* * Pair them to existing subscribers, or create them */ $allSubscribers = Subscriber::lists('id', 'email'); $ids = []; foreach ($groupSubscribers as $email => $info) { /* * New subscriber */ if (!isset($allSubscribers[$email])) { $info['email'] = $email; $subscriber = new Subscriber(); $subscriber->forceFill($info); $subscriber->confirmed_at = Carbon::now(); $subscriber->save(); $ids[] = $subscriber->id; } else { $ids[] = $allSubscribers[$email]; } } /* * Sync to the campaign */ if (count($ids) > 0) { $campaign->subscribers()->sync($ids, false); } }
/** * Returns true if user is throttled. */ protected function checkThrottle() { return Subscriber::checkThrottle(Request::ip()); }
protected function handleVerify($code) { $parts = explode('!', base64_decode($code)); if (count($parts) < 2) { throw new ApplicationException('Invalid code'); } list($subscriberId, $hash) = $parts; $subscriber = Subscriber::find((int) $subscriberId); if (!$subscriber) { throw new ApplicationException('Invalid code'); } $verifyCode = $subscriber->getUniqueCode(); if ($code != $verifyCode) { throw new ApplicationException('Invalid hash'); } $subscriber->confirmed_ip_address = Request::ip(); $subscriber->confirmed_at = $subscriber->freshTimestamp(); $subscriber->unsubscribed_at = null; $subscriber->save(); // @todo Template + Language return '<html><head><title>Verification successful</title></head><body><h1>Verification successful</h1><p>Your email has been successfully added to this list!</p></body></html>'; }
public function preview_onTest($recordId = null) { try { $model = $this->formFindModelObject($recordId); $user = $this->user; /* * Subscribe the tester */ $subscriber = Subscriber::signup(['email' => $user->email, 'first_name' => $user->first_name, 'last_name' => $user->last_name]); CampaignManager::instance()->sendToSubscriber($model, $subscriber); Flash::success('The test message has been successfully sent.'); } catch (Exception $ex) { Flash::error($ex->getMessage()); } }
/** * This will find subscribers who are unsubscribed for longer * than 14 days and delete their account. */ public function processUnsubscribedSubscribers() { $endDate = new Carbon(); $endDate = $endDate->subDays(14); $subscriber = Subscriber::whereNotNull('unsubscribed_at')->get()->filter(function ($subscriber) use($endDate) { return $subscriber->unsubscribed_at <= $endDate; })->shift(); if ($subscriber) { $subscriber->delete(); $this->logActivity(sprintf('Deleted subscriber "%s" who opted out 14 days ago.', $subscriber->email)); } }