Lines
n/a
0 / 0
Methods
n/a
0 / 0
Classes
n/a
0 / 0
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | n/a | 0 / 0 | n/a | 0 / 0 | 3 | ||
| startProcessing | n/a | 0 / 0 | n/a | 0 / 0 | 7 | ||
| writeListToQueue | n/a | 0 / 0 | n/a | 0 / 0 | 2 | ||
| 8 | class QueueProcessListToScopeAdmin | |
| 9 | { | |
| 10 | protected $scopeList; | |
| 11 | ||
| 12 | protected $datetime; | |
| 13 | ||
| 14 | protected $verbose = false; | |
| 15 | ||
| 16 | public function __construct(bool $verbose = false, $scopeId = false) | |
| 17 | { | |
| 18 | $this->dateTime = new \DateTimeImmutable(); | |
| 19 | if ($verbose) { | |
| 20 | \App::$log->info('Queue process list of current day for scope admin'); | |
| 21 | $this->verbose = true; | |
| 22 | } | |
| 23 | if ($scopeId) { | |
| 24 | $scope = (new \BO\Zmsbackend\Scope\Service\Scope())->readEntity($scopeId); | |
| 25 | $this->scopeList = (new \BO\Zmsentities\Collection\ScopeList())->addEntity($scope); | |
| 26 | } else { | |
| 27 | $this->scopeList = (new \BO\Zmsbackend\Scope\Service\Scope())->readListWithScopeAdminEmail(1); | |
| 28 | } | |
| 29 | } | |
| 30 | ||
| 31 | public function startProcessing(bool $commit): void | |
| 32 | { | |
| 33 | foreach ($this->scopeList as $scope) { | |
| 34 | if ($this->verbose) { | |
| 35 | \App::$log->info('Processing scope', ['scope' => (string) $scope]); | |
| 36 | } | |
| 37 | if ($commit) { | |
| 38 | $processList = (new \BO\Zmsbackend\Process\Service\Process()) | |
| 39 | ->readProcessListByScopesAndTime([$scope->getId()], $this->dateTime, 1); | |
| 40 | $processList = $processList | |
| 41 | ->toQueueList($this->dateTime) | |
| 42 | ->withStatus(array('confirmed', 'queued', 'reserved')) | |
| 43 | ->withSortedArrival() | |
| 44 | ->toProcessList(); | |
| 45 | if ($processList->count() > 0) { | |
| 46 | if ($this->writeListToQueue($scope, $processList) && $this->verbose) { | |
| 47 | \App::$log->info('Queue processList for scope admin', [ | |
| 48 | 'email' => $scope->getContactEmail(), | |
| 49 | ]); | |
| 50 | } | |
| 51 | } else { | |
| 52 | \App::$log->warning('Processlist empty for scope', ['scopeId' => $scope->id]); | |
| 53 | } | |
| 54 | } | |
| 55 | } | |
| 56 | } | |
| 57 | ||
| 58 | protected function writeListToQueue( | |
| 59 | \BO\Zmsentities\Scope $scope, | |
| 60 | \BO\Zmsentities\Collection\ProcessList $processList | |
| 61 | ): void { | |
| 62 | $entity = (new \BO\Zmsentities\Mail())->toScopeAdminProcessList($processList, $scope, $this->dateTime); | |
| 63 | if (! (new \BO\Zmsbackend\Mail\Service\Mail())->writeInQueueWithDailyProcessList($scope, $entity)) { | |
| 64 | \App::$log->warning('Mail writing in queue not successful'); | |
| 65 | } | |
| 66 | } | |
| 67 | } |