Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| SendProcessListToScopeAdmin | n/a |
0 / 0 |
n/a |
0 / 0 |
12 | n/a |
0 / 0 |
|||
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
3 | |||||
| startProcessing | n/a |
0 / 0 |
n/a |
0 / 0 |
7 | |||||
| sendListToQueue | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb\Helper; |
| 4 | |
| 5 | /** |
| 6 | * @codeCoverageIgnore |
| 7 | */ |
| 8 | class SendProcessListToScopeAdmin |
| 9 | { |
| 10 | protected $scopeList; |
| 11 | |
| 12 | protected $datetime; |
| 13 | |
| 14 | protected $verbose = false; |
| 15 | |
| 16 | public function __construct($verbose = false, $scopeId = false) |
| 17 | { |
| 18 | $this->dateTime = new \DateTimeImmutable(); |
| 19 | if ($verbose) { |
| 20 | \App::$log->info('Send process list of current day to scope admin'); |
| 21 | $this->verbose = true; |
| 22 | } |
| 23 | if ($scopeId) { |
| 24 | $scope = (new \BO\Zmsdb\Scope())->readEntity($scopeId); |
| 25 | $this->scopeList = (new \BO\Zmsentities\Collection\ScopeList())->addEntity($scope); |
| 26 | } else { |
| 27 | $this->scopeList = (new \BO\Zmsdb\Scope())->readListWithScopeAdminEmail(1); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | public function startProcessing($commit) |
| 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\Zmsdb\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->sendListToQueue($scope, $processList) && $this->verbose) { |
| 47 | \App::$log->info('Send processList to 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 sendListToQueue($scope, $processList) |
| 59 | { |
| 60 | $entity = (new \BO\Zmsentities\Mail())->toScopeAdminProcessList($processList, $scope, $this->dateTime); |
| 61 | if (! (new \BO\Zmsdb\Mail())->writeInQueueWithDailyProcessList($scope, $entity)) { |
| 62 | \App::$log->warning('Mail writing in queue not successful'); |
| 63 | } |
| 64 | } |
| 65 | } |