protected function updateSegment(DeliveranceList $list, DeliveranceCampaignSegment $segment)
 {
     if ($list->isAvailable()) {
         $this->debug(sprintf(Deliverance::_('Updating ‘%s’... '), $segment->title));
         try {
             $size = $list->getSegmentSize($segment->getSegmentOptions());
             $segment->cached_segment_size = $size;
             $segment->save();
             $locale = SwatI18NLocale::get();
             $this->debug(sprintf(Deliverance::_('found %s subscribers.') . "\n", $locale->formatNumber($size)));
         } catch (DeliveranceApiConnectionException $e) {
             // ignore these exceptions. segment sizes will be updated next
             // time around.
             $this->debug(sprintf(Deliverance::_('list unavailable. Segment ‘%s’ was not updated.') . "\n", $segment->title));
         } catch (Exception $e) {
             $e = new DeliveranceException($e);
             $e->processAndContinue();
             $this->debug(sprintf(Deliverance::_('Update error. Segment ‘%s’ was not updated.') . "\n", $segment->title));
         }
     } else {
         $this->debug(sprintf(Deliverance::_('Mailing list unavailable. Segment ‘%s’ was not updated.') . "\n", $segment->title));
     }
 }
예제 #2
0
 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;
 }
예제 #3
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;
 }
예제 #4
0
 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;
 }
예제 #5
0
 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;
 }
예제 #6
0
 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 getMemberInfo($address)
 {
     $member_info = null;
     if ($this->isAvailable()) {
         $parameters = array($this->shortname, $address);
         try {
             $result = $this->callClientMethod('listMemberInfo', $parameters);
             // Since we're only checking a single address, success count
             // should be one, and the first array in data should have a
             // member info for the email address
             if ($result['success'] == 1) {
                 $member_info = $result['data'][0];
             }
         } catch (DeliveranceAPIConnectionException $e) {
             // consider the address not subscribed.
         } catch (DeliveranceException $e) {
             // if it fails for any reason, just consider the address as not
             // subscribed. Log for now out of curiosity.
             $e->processAndContinue();
         } catch (Exception $e) {
             // log these for the time being to see if anything outside of
             // expected DeliveranceException's crop up.
             $e = new DeliveranceException();
             $e->processAndContinue();
         }
     }
     return $member_info;
 }