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 updateNewsletterStats() { // the url for stats can only be generated once the campaign has sent. // It may not be immediately available, so try to grab it if we've sent // the campaign but it hasn't been saved yet. if ($this->newsletter->isSent() && $this->newsletter->campaign_report_url === null) { $list = DeliveranceListFactory::get($this->app, 'default', DeliveranceNewsletter::getDefaultList($this->app, $this->newsletter->instance)); $list->setTimeout($this->app->config->deliverance->list_admin_connection_timeout); try { $this->newsletter->campaign_report_url = $list->getCampaignReportUrl($this->newsletter->campaign_id); $this->newsletter->save(); } catch (Exception $e) { $e = new SiteException($e); $e->processAndContinue(); } } }
protected function saveDBData() { $relocate = true; $save = true; $message = null; try { if ($this->app->isMultipleInstanceAdmin() && $this->newsletter->id !== null) { // List, campaign_type, old_instance and old_campaign all have // to happen before we modify the newsletter dataobject so they // correctly use the old values. $list = DeliveranceListFactory::get($this->app, 'default', DeliveranceNewsletter::getDefaultList($this->app, $this->newsletter->instance)); $campaign_type = $this->newsletter->instance instanceof SiteInstance ? $this->newsletter->instance->shortname : null; $old_instance = $this->newsletter->getInternalValue('instance'); $old_campaign = $this->newsletter->getCampaign($this->app, $campaign_type); } $this->updateNewsletter(); // if instance has changed, delete the old campaign details. if ($this->app->isMultipleInstanceAdmin() && $this->newsletter->id !== null && $old_instance != $this->newsletter->getInternalValue('instance')) { // If not a draft, remove the resources. Don't delete draft // newsletter resources as they are shared across all drafts. if ($this->newsletter->isScheduled()) { DeliveranceCampaign::removeResources($this->app, $old_campaign); } $list->deleteCampaign($old_campaign); $this->newsletter->campaign_id = null; } // save/update on MailChimp. $campaign_id = $this->saveMailChimpCampaign(); } catch (DeliveranceAPIConnectionException $e) { $relocate = true; $save = true; // 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'); // Note: the text about having to re-save before sending isn't true // as the schedule/send tools re-save the newsletter to the mailing // list before they send. But it is a good situation to instill // THE FEAR in users. $message->content_type = 'text/xml'; $message->secondary_content = sprintf('<strong>%s</strong><br />%s', sprintf(Deliverance::_('“%s” has been saved locally so that your work is not ' . 'lost. You must edit the newsletter again before ' . 'sending to have your changes reflected in the sent ' . 'newsletter.'), $this->newsletter->subject), Deliverance::_('Connection issues are typically short-lived ' . 'and editing the newsletter again after a delay will ' . 'usually be successful.')); } catch (Exception $e) { $relocate = false; $save = false; $e = new DeliveranceException($e); $e->processAndContinue(); $message = new SwatMessage(Deliverance::_('An error has occurred. The newsletter has not been saved.'), 'system-error'); } if ($save) { if ($this->newsletter->campaign_id === null) { $this->newsletter->campaign_id = $campaign_id; } if ($this->newsletter->id === null) { $this->newsletter->createdate = new SwatDate(); $this->newsletter->createdate->toUTC(); } $this->newsletter->save(); // if we don't already have a message, do a normal saved message if ($message == null) { $message = new SwatMessage(sprintf(Deliverance::_('“%s” has been saved.'), $this->newsletter->getCampaignTitle())); } } if ($message !== null) { $this->app->messages->add($message); } return $relocate; }