2021-05-21 08:49:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Xentral\Modules\SubscriptionCycle\Scheduler;
|
|
|
|
|
|
|
|
|
|
|
|
use ApplicationCore;
|
|
|
|
use DateTimeImmutable;
|
|
|
|
use DateTimeInterface;
|
|
|
|
use Exception;
|
|
|
|
use Xentral\Components\Database\Database;
|
|
|
|
use Xentral\Modules\SubscriptionCycle\Service\SubscriptionCycleJobService;
|
|
|
|
use Xentral\Modules\SubscriptionCycle\SubscriptionCycleModuleInterface;
|
|
|
|
use Xentral\Modules\SubscriptionCycle\SubscriptionModuleInterface;
|
|
|
|
|
|
|
|
final class SubscriptionCycleManualJobTask
|
|
|
|
{
|
2022-10-18 13:41:34 +02:00
|
|
|
private ApplicationCore $app;
|
|
|
|
private Database $db;
|
|
|
|
private SubscriptionCycleJobService $cycleJobService;
|
|
|
|
private TaskMutexServiceInterface $taskMutexService;
|
|
|
|
private SubscriptionModuleInterface $subscriptionModule;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SubscriptionCycleManualJobTask constructor.
|
|
|
|
*
|
|
|
|
* @param ApplicationCore $app
|
|
|
|
* @param Database $db
|
|
|
|
* @param TaskMutexServiceInterface $taskMutexService
|
|
|
|
* @param SubscriptionCycleJobService $cycleJobService
|
|
|
|
* @param SubscriptionModuleInterface $subscriptionModule
|
|
|
|
*/
|
2021-05-21 08:49:41 +02:00
|
|
|
public function __construct(
|
|
|
|
ApplicationCore $app,
|
|
|
|
Database $db,
|
|
|
|
TaskMutexServiceInterface $taskMutexService,
|
|
|
|
SubscriptionCycleJobService $cycleJobService,
|
2022-12-27 21:38:48 +01:00
|
|
|
SubscriptionModuleInterface $subscriptionModule
|
2021-05-21 08:49:41 +02:00
|
|
|
) {
|
|
|
|
$this->app = $app;
|
|
|
|
$this->db = $db;
|
|
|
|
$this->taskMutexService = $taskMutexService;
|
|
|
|
$this->cycleJobService = $cycleJobService;
|
|
|
|
$this->subscriptionModule = $subscriptionModule;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(): void
|
|
|
|
{
|
|
|
|
if ($this->taskMutexService->isTaskInstanceRunning('rechnungslauf_manual')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->taskMutexService->setMutex('rechnungslauf_manual');
|
|
|
|
$jobs = $this->cycleJobService->listAll(100);
|
2022-10-18 13:41:34 +02:00
|
|
|
foreach ($jobs as $job) {
|
|
|
|
switch ($job['document_type']) {
|
|
|
|
case 'rechnung':
|
|
|
|
$this->subscriptionModule->CreateInvoice((int)$job['address_id']);
|
|
|
|
break;
|
|
|
|
case 'auftrag':
|
|
|
|
$this->subscriptionModule->CreateOrder((int)$job['address_id']);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$this->cycleJobService->delete((int)$job['id']);
|
2021-05-21 08:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function cleanup(): void
|
|
|
|
{
|
|
|
|
$this->taskMutexService->setMutex('rechnungslauf_manual', false);
|
|
|
|
}
|
|
|
|
}
|