core/lib/Thelia/Action/MailingSystem.php line 29

  1. <?php
  2. /*
  3.  * This file is part of the Thelia package.
  4.  * http://www.thelia.net
  5.  *
  6.  * (c) OpenStudio <info@thelia.net>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Thelia\Action;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  14. use Thelia\Core\Event\Cache\CacheEvent;
  15. use Thelia\Core\Event\MailingSystem\MailingSystemEvent;
  16. use Thelia\Core\Event\TheliaEvents;
  17. use Thelia\Core\Service\ConfigCacheService;
  18. use Thelia\Model\ConfigQuery;
  19. class MailingSystem extends BaseAction implements EventSubscriberInterface
  20. {
  21.     public function __construct(private ConfigCacheService $configCache, private EventDispatcherInterface $dispatcher, private $kernelCacheDir)
  22.     {
  23.     }
  24.     public function update(MailingSystemEvent $event): void
  25.     {
  26.         if ($event->getEnabled()) {
  27.             ConfigQuery::enableSmtp();
  28.         } else {
  29.             ConfigQuery::disableSmtp();
  30.         }
  31.         ConfigQuery::setSmtpHost($event->getHost());
  32.         ConfigQuery::setSmtpPort($event->getPort());
  33.         ConfigQuery::setSmtpEncryption($event->getEncryption());
  34.         ConfigQuery::setSmtpUsername($event->getUsername());
  35.         ConfigQuery::setSmtpPassword($event->getPassword());
  36.         ConfigQuery::setSmtpAuthMode($event->getAuthMode());
  37.         ConfigQuery::setSmtpTimeout($event->getTimeout());
  38.         ConfigQuery::setSmtpSourceIp($event->getSourceIp());
  39.         $cacheEvent = new CacheEvent($this->kernelCacheDir);
  40.         $this->dispatcher->dispatch($cacheEventTheliaEvents::CACHE_CLEAR);
  41.         $this->configCache->initCacheConfigs(true);
  42.     }
  43.     /**
  44.      * {@inheritDoc}
  45.      */
  46.     public static function getSubscribedEvents()
  47.     {
  48.         return [
  49.             TheliaEvents::MAILING_SYSTEM_UPDATE => ['update'128],
  50.         ];
  51.     }
  52. }