示例#1
0
 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;
 }
示例#2
0
 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;
 }