示例#1
0
 protected function initNewsletter()
 {
     if ($this->id == '') {
         $this->relocate('Newsletter');
     }
     $class_name = SwatDBClassMap::get('DeliveranceNewsletter');
     $this->newsletter = new $class_name();
     $this->newsletter->setDatabase($this->app->db);
     if (!$this->newsletter->load($this->id)) {
         throw new AdminNotFoundException(sprintf('A newsletter with the id of ‘%s’ does not exist', $this->id));
     }
     // Can't cancel a newsletter that has not been scheduled.
     if (!$this->newsletter->isScheduled()) {
         $this->relocate();
     }
     // Can't cancel a newsletter that has been sent.
     if ($this->newsletter->isSent()) {
         $this->relocate();
     }
 }
示例#2
0
 protected function buildToolbars()
 {
     $toolbars = $this->ui->getRoot()->getDescendants('SwatToolbar');
     foreach ($toolbars as $toolbar) {
         $toolbar->setToolLinkValues($this->newsletter->id);
     }
     // Preview link can be unavailable if the database save was successful,
     // but the mailing list call failed.
     $preview_link = $this->ui->getWidget('preview_link');
     if ($this->newsletter->campaign_id === null) {
         $preview_link->sensitive = false;
         $preview_link->tooltip = Deliverance::_('This newsletter’s preview is not available due to connection ' . 'issues with the email service provider. Edit the newsletter ' . 'to enable the preview.');
     } else {
         $campaign_type = $this->newsletter->instance instanceof SiteInstance ? $this->newsletter->instance->shortname : null;
         $campaign_class = DeliveranceCampaignFactory::get($this->app, $campaign_type);
         $this->ui->getWidget('preview_link')->link = call_user_func_array(array($campaign_class, 'getPreviewUrl'), array($this->app, $this->newsletter->campaign_id));
     }
     if ($this->newsletter->isSent()) {
         $preview_link->title = Deliverance::_('View Email');
         $this->ui->getWidget('edit_link')->visible = false;
         $this->ui->getWidget('delete_link')->visible = false;
         $this->ui->getWidget('cancel_link')->visible = false;
         $this->ui->getWidget('schedule_link')->visible = false;
         $this->ui->getWidget('send_preview_link')->visible = false;
         // reports may not exist yet if the newsletter was recently sent.
         $stats_link = $this->ui->getWidget('stats_link');
         if ($this->newsletter->campaign_report_url === null) {
             $stats_link->sensitive = false;
             $stats_link->tooltip = Deliverance::_('This newletter’s status report will become available ' . 'shortly after the newsletter has been sent.');
         } else {
             $stats_link->link = $this->newsletter->campaign_report_url;
         }
     } elseif ($this->newsletter->isScheduled()) {
         $this->ui->getWidget('edit_link')->visible = false;
         $this->ui->getWidget('stats_link')->visible = false;
         $this->ui->getWidget('delete_link')->visible = false;
         $this->ui->getWidget('send_preview_link')->visible = false;
         $this->ui->getWidget('schedule_link')->title = Deliverance::_('Reschedule Delivery');
     } else {
         $this->ui->getWidget('stats_link')->visible = false;
         $this->ui->getWidget('cancel_link')->visible = false;
     }
 }
示例#3
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;
 }