custom/plugins/CompraEsiSW6/src/Tasks/EsiLoggingTaskHandler.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Compra\EsiSW6\Tasks;
  3. use Compra\EsiSW6\Administration\Service\ConfigurationService;
  4. use Compra\EsiSW6\Logging\Services\LoggingService;
  5. use Compra\FoundationSW6\Core\Framework\AbstractScheduledTaskHandler;
  6. use Exception;
  7. use Monolog\Logger;
  8. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  9. /**
  10.  * @deprecated tag:v6.5.0 - change type of $scheduledTaskRepository to EntityRepository
  11.  */
  12. class EsiLoggingTaskHandler extends AbstractScheduledTaskHandler
  13. {
  14.     /**
  15.      * @var EntityRepositoryInterface
  16.      */
  17.     protected $scheduledTaskRepository;
  18.     protected ConfigurationService $configurationService;
  19.     protected LoggingService $loggingService;
  20.     public function __construct(
  21.         Logger $logger,
  22.         EntityRepositoryInterface $scheduledTaskRepository,
  23.         LoggingService $loggingService,
  24.         ConfigurationService $configurationService
  25.     )
  26.     {
  27.         $this->scheduledTaskRepository $scheduledTaskRepository;
  28.         $this->loggingService $loggingService;
  29.         $this->configurationService $configurationService;
  30.         parent::__construct($logger$scheduledTaskRepository);
  31.     }
  32.     public static function getHandledMessages(): iterable
  33.     {
  34.         return [EsiLoggingTask::class];
  35.     }
  36.     /**
  37.      * @throws Exception
  38.      * @throws \Doctrine\DBAL\Driver\Exception
  39.      */
  40.     public function run(): void
  41.     {
  42.         echo "==Esi Logging Start==\n";
  43.         if ($this->configurationService->getConfigurationByName('logging_send_error')) {
  44.             //checks for weekend configuration
  45.             //returns weekend information if applicable
  46.             if ($this->loggingService->isTodayLoggingEnabled()) {
  47.                 echo "ESI Logging skipped. Not configured to run on weekends.\n";
  48.             }
  49.             //checks for ESI runtime configuration
  50.             //returns runtime information if applicable
  51.             else if ($this->loggingService->isNowInRuntimePeriod()) {
  52.                 echo "ESI Logging skipped. Outside of service time.\n";
  53.             }
  54.             else {
  55.                 //checks for configured errors in previous import tasks and sends mail if applicable
  56.                 $loggingErrors null;
  57.                 try {
  58.                     $loggingErrors $this->loggingService->processEsiLoggingTask();
  59.                     if(count($loggingErrors) > 0) {
  60.                         $this->loggingService->sendLoggingErrorMail($loggingErrors'ESI Logging Fehlerbericht');
  61.                     }
  62.                 } catch(\Exception $e) {
  63.                     echo $e->getMessage();
  64.                 }
  65.                 echo sprintf("ESI Logging processed successfully with %s errors.\n"$loggingErrors ? (string) count($loggingErrors) : "");
  66.             }
  67.         }
  68.         echo "==Esi Logging Complete==\n";
  69.     }
  70. }