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; }
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; }