public function up() { Schema::table('leancode_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(); }
/** * Binds all subscribers from the campaign groups to the message. */ public function bindGroupSubscribers($campaign, $test) { $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); } }
public function importData($results, $sessionKey = null) { if (!$results) { throw new ApplicationException('No import data received. Please check the format of the csv file and try again.'); } $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 */ $counter = 1; 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) { if (trim($value)) { $subscriber->{$attribute} = $value; } elseif (strpos(strtolower($attribute), "_at") !== false) { $subscriber->{$attribute} = Carbon::now(); //gmdate("Y-m-d H:i:s"); } elseif (strpos(strtolower($attribute), "ip_address") !== false) { $subscriber->{$attribute} = Request::ip(); } elseif (strpos(strtolower($attribute), "message_type") !== false) { $subscriber->{$attribute} = "html"; } else { $subscriber->{$attribute} = null; } } $subscriber->forceSave(); if ($listIds = $this->getListIdsForSubscriber($data)) { // $sql = "INSERT INTO leancode_campaign_lists_subscribers SET list_id = 1, subscriber_id=$subscriber->id ON DUPLICATE KEY UPDATE list_id=list_id"; // DB::statement( DB::raw($sql) ); } /* * Log results */ if ($subscriberExists) { $this->logUpdated(); } else { $this->logCreated(); } } catch (Exception $ex) { $this->logError($row, $ex->getMessage()); } } }
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, 'ok_company_name' => $user->ok_company_name, 'ok_sample_products' => $user->ok_sample_products, 'ok_company_products_count' => $user->ok_company_products_count]); CampaignManager::instance()->sendToSubscriber($model, $subscriber); Flash::success('The test mailing was successfully sent.'); } catch (Exception $ex) { Flash::error($ex->getMessage()); } }
/** * 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>Email verification successful</h1><p></p></body></html>'; }
/** * 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)); } }