<?php declare(strict_types=1);
namespace Compra\EsiSW6\Tasks;
use Compra\EsiSW6\Administration\Service\ConfigurationService;
use Compra\EsiSW6\Logging\Services\LoggingService;
use Compra\FoundationSW6\Core\Framework\AbstractScheduledTaskHandler;
use Exception;
use Monolog\Logger;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
/**
* @deprecated tag:v6.5.0 - change type of $scheduledTaskRepository to EntityRepository
*/
class EsiLoggingTaskHandler extends AbstractScheduledTaskHandler
{
/**
* @var EntityRepositoryInterface
*/
protected $scheduledTaskRepository;
protected ConfigurationService $configurationService;
protected LoggingService $loggingService;
public function __construct(
Logger $logger,
EntityRepositoryInterface $scheduledTaskRepository,
LoggingService $loggingService,
ConfigurationService $configurationService
)
{
$this->scheduledTaskRepository = $scheduledTaskRepository;
$this->loggingService = $loggingService;
$this->configurationService = $configurationService;
parent::__construct($logger, $scheduledTaskRepository);
}
public static function getHandledMessages(): iterable
{
return [EsiLoggingTask::class];
}
/**
* @throws Exception
* @throws \Doctrine\DBAL\Driver\Exception
*/
public function run(): void
{
echo "==Esi Logging Start==\n";
if ($this->configurationService->getConfigurationByName('logging_send_error')) {
//checks for weekend configuration
//returns weekend information if applicable
if ($this->loggingService->isTodayLoggingEnabled()) {
echo "ESI Logging skipped. Not configured to run on weekends.\n";
}
//checks for ESI runtime configuration
//returns runtime information if applicable
else if ($this->loggingService->isNowInRuntimePeriod()) {
echo "ESI Logging skipped. Outside of service time.\n";
}
else {
//checks for configured errors in previous import tasks and sends mail if applicable
$loggingErrors = null;
try {
$loggingErrors = $this->loggingService->processEsiLoggingTask();
if(count($loggingErrors) > 0) {
$this->loggingService->sendLoggingErrorMail($loggingErrors, 'ESI Logging Fehlerbericht');
}
} catch(\Exception $e) {
echo $e->getMessage();
}
echo sprintf("ESI Logging processed successfully with %s errors.\n", $loggingErrors ? (string) count($loggingErrors) : "");
}
}
echo "==Esi Logging Complete==\n";
}
}