protected function appendAnalyticsToUri($uri) { if ($this->isMailChimpUri($uri) === false) { $uri = parent::appendAnalyticsToUri($uri); } return $uri; }
protected function processDBData() { parent::processDBData(); $locale = SwatI18NLocale::get(); $relocate = true; $message = null; $delete_count = 0; $error_count = 0; $newsletters = $this->getNewsletters(); foreach ($newsletters as $newsletter) { // only allow deleting unsent newsletters. There is nothing // technically stopping us from deleting ones that have been sent, // but do this for the sake of stats until deleting sent newsletters // is required. if ($newsletter->isSent() == false) { $list = $this->getList($newsletter); $campaign_type = $newsletter->instance instanceof SiteInstance ? $newsletter->instance->shortname : null; $campaign = $newsletter->getCampaign($this->app, $campaign_type); $transaction = new SwatDBTransaction($this->app->db); try { // If not a draft, remove the resources. Don't delete draft // newsletter resources as they are shared across all // drafts. if ($newsletter->isScheduled()) { DeliveranceCampaign::removeResources($this->app, $campaign); } $list->deleteCampaign($campaign); $sql = 'delete from Newsletter where id = %s'; $sql = sprintf($sql, $this->app->db->quote($newsletter->id, 'integer')); $delete_count += SwatDB::exec($this->app->db, $sql); $transaction->commit(); } catch (DeliveranceAPIConnectionException $e) { $transaction->rollback(); $e->processAndContinue(); $error_count++; $relocate = false; } catch (Exception $e) { $transaction->rollback(); $e = new DeliveranceException($e); $e->processAndContinue(); $error_count++; $relocate = false; } } } if ($delete_count > 0) { $message = new SwatMessage(sprintf(Deliverance::ngettext('One newsletter has been deleted.', '%s newsletters have been deleted.', $delete_count), $locale->formatNumber($delete_count)), 'notice'); $this->app->messages->add($message); } if ($error_count > 0) { $message = new SwatMessage(Deliverance::_('There was an issue connecting to the email service ' . 'provider.'), 'error'); $message->content_type = 'text/xml'; $message->secondary_content = sprintf('<strong>%s</strong><br />%s', sprintf(Deliverance::ngettext('One newsletter has not been deleted.', '%s newsletters have not been deleted.', $error_count), $locale->formatNumber($error_count)), Deliverance::ngettext('Connection issues are typically short-lived and ' . 'attempting to delete the newsletter again after a ' . 'delay will usually be successful.', 'Connection issues are typically short-lived and ' . 'attempting to delete the newsletters again after a ' . 'delay will usually be successful.', $error_count)); } return $relocate; }
protected function saveDBData() { $campaign_type = $this->newsletter->instance instanceof SiteInstance ? $this->newsletter->instance->shortname : null; $campaign = $this->newsletter->getCampaign($this->app, $campaign_type); $message = null; $relocate = true; try { DeliveranceCampaign::removeResources($this->app, $campaign); $this->list->unscheduleCampaign($campaign); $this->newsletter->send_date = null; $this->newsletter->save(); $message = new SwatMessage(sprintf(Deliverance::_('The delivery of “%s” has been canceled.'), $this->newsletter->subject)); } catch (DeliveranceAPIConnectionException $e) { $relocate = false; // log api connection exceptions in the admin to keep a track of how // frequent they are. $e->processAndContinue(); $message = new SwatMessage(Deliverance::_('There was an issue connecting to the email ' . 'service provider.'), 'error'); $message->content_type = 'text/xml'; $message->secondary_content = sprintf('<strong>%s</strong><br />%s', sprintf(Deliverance::_('The delivery of “%s” has not been canceled.'), $this->newsletter->subject), Deliverance::_('Connection issues are typically short-lived ' . 'and attempting to cancel the newsletter again after a ' . 'delay will usually be successful.')); } catch (Exception $e) { $relocate = false; $e = new DeliveranceException($e); $e->processAndContinue(); $message = new SwatMessage(Deliverance::_('An error has occurred. The newsletter has not ' . 'been cancelled.'), 'system-error'); } if ($message !== null) { $this->app->messages->add($message); } return $relocate; }
protected function saveMailChimpCampaign() { $list = DeliveranceListFactory::get($this->app, 'default', DeliveranceNewsletter::getDefaultList($this->app, $this->newsletter->instance)); // Set a long timeout on mailchimp calls as we're in the admin & patient $list->setTimeout($this->app->config->deliverance->list_admin_connection_timeout); $lookup_id_by_title = false; if ($this->newsletter->id !== null && $this->newsletter->campaign_id === null) { // if the newsletter exists in the db, and doesn't have a campaign // id set try to look it up when saving. $lookup_id_by_title = true; } $campaign_type = $this->newsletter->instance instanceof SiteInstance ? $this->newsletter->instance->shortname : null; $campaign = $this->newsletter->getCampaign($this->app, $campaign_type); $campaign_id = $list->saveCampaign($campaign, $lookup_id_by_title); // save/update campaign resources. DeliveranceCampaign::uploadResources($this->app, $campaign); return $campaign_id; }
protected function saveDBData() { $schedule = true; $relocate = true; $message = null; // Note: DeliveranceMailChimpList expects campaign send dates to be in // local time. Send date must be set on the newsletter so that its // internal campaign can get the correct send_date. if ($this->ui->getWidget('send_date')->value instanceof SwatDate) { $message_text = Deliverance::ngettext('“%1$s” will be sent to one subscriber on %3$s at %4$s %5$s.', '“%1$s” will be sent to %2$s subscribers on %3$s at %4$s %5$s.', $this->send_count); // Preserve all the date fields $send_date = $this->ui->getWidget('send_date')->value; $send_date->setTZ($this->app->default_time_zone); } else { $schedule = false; $message_text = Deliverance::ngettext('“%1$s” was sent to one subscriber.', '“%1$s” was sent to %2$s subscribers.', $this->send_count); // Convert all the date fields to the timezone $send_date = new SwatDate(); $send_date->setTimezone($this->app->default_time_zone); } // build the success message before date conversion to prevent needing // to convert to UTC for saving and then back to local time for display. $locale = SwatI18NLocale::get(); $message = new SwatMessage(sprintf($message_text, $this->newsletter->subject, $locale->formatNumber($this->send_count), $send_date->formatLikeIntl(SwatDate::DF_DATE), $send_date->formatLikeIntl(SwatDate::DF_TIME), $send_date->formatTZ(SwatDate::TZ_CURRENT_SHORT))); $message->secondary_content = Deliverance::_('Subscriber counts are ' . 'estimates. Full statistics will be available once the newsletter ' . 'has been sent.'); $campaign_type = $this->newsletter->instance instanceof SiteInstance ? $this->newsletter->instance->shortname : null; // grab campaign with old send date to clear out the resources. $campaign = $this->newsletter->getCampaign($this->app, $campaign_type); // If not a draft, remove the resources first in case they came from an // old directory. Don't delete draft newsletter resources as they are // shared across all drafts. if ($this->newsletter->isScheduled()) { DeliveranceCampaign::removeResources($this->app, $campaign); } // Finally set the date with the local timezone. // As DeliveranceMailChimpList expects. $this->newsletter->send_date = $send_date; // re-grab the campaign with the new send_date; $campaign = $this->newsletter->getCampaign($this->app, $campaign_type); try { // resave campaign so that resource urls are rewritten. $this->list->saveCampaign($campaign, false); // save/update campaign resources. DeliveranceCampaign::uploadResources($this->app, $campaign); if ($schedule) { $this->list->scheduleCampaign($campaign); } else { $this->list->sendCampaign($campaign); } // Before we save the newsletter we need to convert it to UTC. $this->newsletter->send_date->toUTC(); $this->newsletter->save(); } catch (DeliveranceAPIConnectionException $e) { // send date needs to be reset to null so the page titles stay // correct. $this->newsletter->send_date = null; $relocate = false; // log api connection exceptions in the admin to keep a track of how // frequent they are. $e->processAndContinue(); $message = new SwatMessage(Deliverance::_('There was an issue connecting to the email ' . 'service provider.'), 'error'); $message->content_type = 'text/xml'; if ($schedule) { $message->secondary_content = sprintf('<strong>%s</strong><br />%s', sprintf(Deliverance::_('“%s” has not been scheduled.'), $this->newsletter->subject), Deliverance::_('Connection issues are typically ' . 'short-lived and attempting to schedule the ' . 'newsletter again after a delay will usually be ' . 'successful.')); } else { $message->secondary_content = sprintf('<strong>%s</strong><br />%s', sprintf(Deliverance::_('“%s” has not been sent.'), $this->newsletter->subject), Deliverance::_('Connection issues are typically ' . 'short-lived and attempting to send the newsletter ' . 'again after a delay will usually be successful.')); } } catch (Exception $e) { // send date needs to be reset to null so the page titles stay // correct. $this->newsletter->send_date = null; $relocate = false; $e = new DeliveranceException($e); $e->processAndContinue(); if ($schedule) { $message_text = Deliverance::_('An error has occurred. The ' . 'newsletter has not been scheduled.'); } else { $message_text = Deliverance::_('An error has occurred. The ' . 'newsletter has not been sent.'); } $message = new SwatMessage($message_text, 'system-error'); } if ($message !== null) { $this->app->messages->add($message); } return $relocate; }
protected function saveData() { $relocate = true; $message = null; $email = $this->ui->getWidget('email')->value; $campaign_type = $this->newsletter->instance instanceof SiteInstance ? $this->newsletter->instance->shortname : null; $campaign = $this->newsletter->getCampaign($this->app, $campaign_type); try { // re-save campaign, this makes life easier when testing template // changes $this->list->saveCampaign($campaign); // save/update campaign resources. DeliveranceCampaign::uploadResources($this->app, $campaign); $this->list->sendCampaignTest($campaign, array($email)); $message = new SwatMessage(sprintf(Deliverance::_('A preview of “%s” has been sent to %s.'), $this->newsletter->subject, $email)); } catch (DeliveranceAPIConnectionException $e) { $relocate = false; // log api connection exceptions in the admin to keep a track of how // frequent they are. $e->processAndContinue(); $message = new SwatMessage(Deliverance::_('There was an issue connecting to the email ' . 'service provider.'), 'error'); $message->content_type = 'text/xml'; $message->secondary_content = sprintf('<strong>%s</strong><br />%s', sprintf(Deliverance::_('The preview of “%s” has not been sent.'), $this->newsletter->subject), Deliverance::_('Connection issues are typically short-lived ' . 'and attempting to re-send the preview again after a ' . 'delay will usually be successful.')); } catch (Exception $e) { $relocate = false; $e = new DeliveranceException($e); $e->processAndContinue(); $message = new SwatMessage(Deliverance::_('An error has occurred. The newsletter preview ' . 'has not been sent.'), 'system-error'); } if ($message !== null) { $this->app->messages->add($message); } return $relocate; }
public function getCampaignId(DeliveranceCampaign $campaign) { $campaign_id = null; $parameters = array('filters' => array('list_id' => $this->shortname, 'title' => $campaign->getTitle(), 'exact' => true)); try { $campaigns = $this->callClientMethod('campaigns', $parameters); } catch (Exception $e) { throw new DeliveranceCampaignException($e); } if ($campaigns['total'] > 1) { throw new DeliveranceCampaignException(sprintf('Multiple campaigns exist with a title of ‘%s’', $campaign->getTitle())); } elseif ($campaigns['total'] == 1) { $campaign_id = $campaigns['data'][0]['id']; } return $campaign_id; }