app = $app; $this->db = $db; $this->taskMutexService = $taskMutexService; $this->subscriptionModule = $subscriptionModule; $this->cycleJobService = $cycleJobService; $this->isOrdersActive = $isOrdersActive; $this->isInvoiceActive = $isInvoiceActive; $this->printerId = $printerId; $this->mailPrinter = $mailPrinter; } public function execute(): void { if ($this->taskMutexService->isTaskInstanceRunning('rechnungslauf')) { return; } $this->taskMutexService->setMutex('rechnungslauf'); if (empty($this->isOrdersActive) && empty($this->isInvoiceActive)) { return; } if ($this->isOrdersActive) { $orderAddresses = array_map( 'intval', array_keys((array)$this->subscriptionModule->GetRechnungsArray('auftrag')) ); $addressIdsInJobs = $this->cycleJobService->getAddressIdsByDocumentType('auftrag'); $orderAddresses = array_diff($orderAddresses, $addressIdsInJobs); foreach ($orderAddresses as $addressToAdd) { $this->cycleJobService->create($addressToAdd, 'auftrag', $this->mailPrinter, $this->printerId); } unset($orderAddresses); } if ($this->isInvoiceActive) { $invoiceAddresses = array_map( 'intval', array_keys((array)$this->subscriptionModule->GetRechnungsArray('rechnung')) ); $addressIdsInJobs = $this->cycleJobService->getAddressIdsByDocumentType('rechnung'); $invoiceAddresses = array_diff($invoiceAddresses, $addressIdsInJobs); foreach ($invoiceAddresses as $addressToAdd) { $this->cycleJobService->create($addressToAdd, 'rechnung', $this->mailPrinter, $this->printerId); } } if (empty($this->isInvoiceActive)) { return; } } public function cleanup(): void { $this->taskMutexService->setMutex('rechnungslauf', false); } }