Exemple #1
0
 /**
  * @param MailingSystemEvent $event
  */
 public function update(MailingSystemEvent $event)
 {
     if ($event->getEnabled()) {
         ConfigQuery::enableSmtp();
     } else {
         ConfigQuery::disableSmtp();
     }
     ConfigQuery::setSmtpHost($event->getHost());
     ConfigQuery::setSmtpPort($event->getPort());
     ConfigQuery::setSmtpEncryption($event->getEncryption());
     ConfigQuery::setSmtpUsername($event->getUsername());
     ConfigQuery::setSmtpPassword($event->getPassword());
     ConfigQuery::setSmtpAuthMode($event->getAuthMode());
     ConfigQuery::setSmtpTimeout($event->getTimeout());
     ConfigQuery::setSmtpSourceIp($event->getSourceIp());
 }
 public function updateAction()
 {
     // Check current user authorization
     if (null !== ($response = $this->checkAuth(self::RESOURCE_CODE, array(), AccessManager::UPDATE))) {
         return $response;
     }
     $error_msg = false;
     // Create the form from the request
     $form = new MailingSystemModificationForm($this->getRequest());
     try {
         // Check the form against constraints violations
         $formData = $this->validateForm($form, "POST");
         // Get the form field values
         $event = new MailingSystemEvent();
         $event->setEnabled($formData->get('enabled')->getData());
         $event->setHost($formData->get('host')->getData());
         $event->setPort($formData->get('port')->getData());
         $event->setEncryption($formData->get('encryption')->getData());
         $event->setUsername($formData->get('username')->getData());
         $event->setPassword($formData->get('password')->getData());
         $event->setAuthMode($formData->get('authmode')->getData());
         $event->setTimeout($formData->get('timeout')->getData());
         $event->setSourceIp($formData->get('sourceip')->getData());
         $this->dispatch(TheliaEvents::MAILING_SYSTEM_UPDATE, $event);
         // Redirect to the success URL
         $response = $this->generateRedirectFromRoute("admin.configuration.mailing-system.view");
     } catch (FormValidationException $ex) {
         // Form cannot be validated
         $error_msg = $this->createStandardFormValidationErrorMessage($ex);
     } catch (\Exception $ex) {
         // Any other error
         $error_msg = $ex->getMessage();
     }
     if (false !== $error_msg) {
         $this->setupFormErrorContext($this->getTranslator()->trans("mailing system modification", array()), $error_msg, $form, $ex);
         // At this point, the form has errors, and should be redisplayed.
         $response = $this->render('mailing-system');
     }
     return $response;
 }