vendor/pimcore/data-hub-file-export/src/EventSubscriber/AdminSubscriber.php line 84

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\DataHubFileExportBundle\EventSubscriber;
  12. use Pimcore\Bundle\DataHubFileExportBundle\Event\Admin\ResetConfigEvent;
  13. use Pimcore\Bundle\DataHubFileExportBundle\Event\Admin\ValidateConfigEvent;
  14. use Pimcore\Bundle\DataHubFileExportBundle\Helper;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class AdminSubscriber implements EventSubscriberInterface
  17. {
  18.     public static function getSubscribedEvents()
  19.     {
  20.         return [
  21.             ValidateConfigEvent::class => 'isValidConfig',
  22.             ResetConfigEvent::class => 'resetConfig',
  23.         ];
  24.     }
  25.     public function resetConfig(ResetConfigEvent $e)
  26.     {
  27.         $config $e->getConfig();
  28.         $exporter Helper::getExporterService($config);
  29.         $exporter->resetData();
  30.     }
  31.     protected function getConfigErrors($config)
  32.     {
  33.         $errors = [];
  34.         if ($config['general']['active']) {
  35.             if (!$config['schema']['classId']) {
  36.                 $errors[] = 'Please define a Data Class in the Schema definition';
  37.             }
  38.             if (!$config['schema']['config']) {
  39.                 $errors[] = 'Please define a schema for the export';
  40.             }
  41.             if ($deliveryDestination = ($config['deliveryDestination'] ?? null)) {
  42.                 if (!$config['deliveryDestination']['filename']) {
  43.                     $errors[] = 'Please define a filename in Delivery destination';
  44.                 }
  45.                 if ($deliveryDestination['transmitter'] == 'localDirectory') {
  46.                     if (!$deliveryDestination['transmitter_localDirectory']['directory']) {
  47.                         $errors[] = 'Please provide a "Directory" in "Delivery destination"';
  48.                     }
  49.                 }
  50.                 if ($deliveryDestination['transmitter'] == 'sftp') {
  51.                     $settings $deliveryDestination['transmitter_sftp'];
  52.                     foreach (['host''port''username'] as $key) {
  53.                         if (!$settings[$key]) {
  54.                             $errors[] = 'Please provide "'.$key.'" in the SFTP settings';
  55.                         }
  56.                     }
  57.                 }
  58.                 if ($deliveryDestination['transmitter'] == 'http') {
  59.                     $settings $deliveryDestination['transmitter_http'];
  60.                     foreach (['method''url'] as $key) {
  61.                         if (!$settings[$key]) {
  62.                             $errors[] = 'Please provide "'.$key.'" in the HTTP settings';
  63.                         }
  64.                     }
  65.                 }
  66.             }
  67.         }
  68.         return $errors;
  69.     }
  70.     public function isValidConfig(ValidateConfigEvent $e)
  71.     {
  72.         $config $e->getConfigData();
  73.         $errors $this->getConfigErrors($config);
  74.         if ($errors) {
  75.             throw new \Exception(implode("\n"$errors));
  76.         }
  77.         return $errors;
  78.     }
  79. }