/** * @Given /^I add the "([^"]*)" mailinglist to the "([^"]*)" page$/ */ public function iAddTheMailinglistToThePage($mailinglistTitle, $pageUrl) { $mailinglist = \MailingList::get()->filter('Title', $mailinglistTitle)->First(); assertNotNull($mailinglist, 'Could not find MailingList with ' . $mailinglistTitle); $page = \SubscriptionPage::get()->filter('URLSegment', $pageUrl)->First(); assertNotNull($page); $lists = $page->MailingLists ? explode(',', $page->MailingLists) : array(); $lists[] = $mailinglist->ID; $page->MailingLists = implode(',', $lists); $page->write(); $page->publish('Stage', 'Live'); }
public function delete_trunk($offset) { set_time_limit(18000); ini_set('memory_limit', '512M'); $days = SubscriptionPage::get_days_verification_link_alive(); $objects = DataList::create('Recipient')->where("\"Recipient\".\"Verified\" = 0 AND \"Recipient\".\"Created\" < NOW() - INTERVAL {$days} DAY")->limit(self::$trunk_length, $offset); $count = $objects->count(); if ($count) { foreach ($objects as $object) { if ($object->canDelete()) { $object->delete(); } } } return $count; }
public function subscribeverify() { if ($hash = $this->urlParams['ID']) { $recipient = DataObject::get_one("Recipient", "\"ValidateHash\" = '" . Convert::raw2sql($hash) . "'"); if ($recipient && $recipient->exists()) { $now = date('Y-m-d H:i:s'); if ($now <= $recipient->ValidateHashExpired) { $recipient->Verified = true; // extends the ValidateHashExpired so the a unsubscirbe link will stay alive in that peroid by law $days = UnsubscribeController::get_days_unsubscribe_link_alive(); $recipient->ValidateHashExpired = date('Y-m-d H:i:s', time() + 86400 * $days); $recipient->write(); $mailingLists = $recipient->MailingLists(); $ids = implode(",", $mailingLists->getIDList()); $templateData = array('FirstName' => $recipient->FirstName, 'MailingLists' => $mailingLists, 'UnsubscribeLink' => Director::BaseURL() . "unsubscribe/index/" . $recipient->ValidateHash . "/" . $ids, 'HashText' => $recipient->getHashText(), 'SiteConfig' => $this->SiteConfig()); //send notification email if ($this->SendNotification) { $email = new Email(); $email->setTo($recipient->Email); $from = $this->NotificationEmailFrom ? $this->NotificationEmailFrom : Email::getAdminEmail(); $email->setFrom($from); $email->setTemplate('SubscriptionConfirmationEmail'); $email->setSubject(_t('Newsletter.ConfirmSubject', "Confirmation of your subscription to our mailing lists")); $email->populateTemplate($templateData); $email->send(); } $url = $this->Link('completed') . "/" . $recipient->ID; $this->redirect($url); } } if ($recipient && $recipient->exists()) { $recipientData = $recipient->toMap(); } else { $recipientData = array(); } $daysExpired = SubscriptionPage::get_days_verification_link_alive(); $recipientData['VerificationExpiredContent1'] = sprintf(_t('Newsletter.VerificationExpiredContent1', 'The verification link is only validate for %s days.'), $daysExpired); return $this->customise(array('Title' => _t('Newsletter.VerificationExpired', 'The verification link has been expired'), 'Content' => $this->customise($recipientData)->renderWith('VerificationExpired')))->renderWith('Page'); } }