Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| RestoreDeletedDataByCron | n/a |
0 / 0 |
n/a |
0 / 0 |
14 | n/a |
0 / 0 |
|||
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| startProcessing | n/a |
0 / 0 |
n/a |
0 / 0 |
5 | |||||
| removeProcess | n/a |
0 / 0 |
n/a |
0 / 0 |
3 | |||||
| deleteProcess | n/a |
0 / 0 |
n/a |
0 / 0 |
4 | |||||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb\Helper; |
| 4 | |
| 5 | /** |
| 6 | * @codeCoverageIgnore |
| 7 | */ |
| 8 | class RestoreDeletedDataByCron |
| 9 | { |
| 10 | protected $scopeList; |
| 11 | |
| 12 | protected $verbose = false; |
| 13 | |
| 14 | public function __construct($verbose = false) |
| 15 | { |
| 16 | if ($verbose) { |
| 17 | error_log("INFO: Restoring deleted appointments based on delay time"); |
| 18 | $this->verbose = true; |
| 19 | } |
| 20 | $this->scopeList = (new \BO\Zmsdb\Scope())->readList(); |
| 21 | } |
| 22 | |
| 23 | public function startProcessing($commit) |
| 24 | { |
| 25 | foreach ($this->scopeList as $scope) { |
| 26 | $time = new \DateTimeImmutable(); |
| 27 | $reservationDuration = $scope->toProperty()->preferences->appointment->reservationDuration->get(); |
| 28 | $time = $time->setTimestamp($time->getTimestamp() - ($reservationDuration * 60)); |
| 29 | $processList = (new \BO\Zmsdb\Process())->readExpiredReservationsList($time, $scope->id, 10000); |
| 30 | |
| 31 | foreach ($processList as $process) { |
| 32 | if ($this->verbose) { |
| 33 | error_log("INFO: Processing $process"); |
| 34 | } |
| 35 | if ($commit) { |
| 36 | $this->removeProcess($process); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | protected function removeProcess(\BO\Zmsentities\Process $process) |
| 43 | { |
| 44 | if ('reserved' == $process->status) { |
| 45 | $this->deleteProcess($process); |
| 46 | } elseif ($this->verbose) { |
| 47 | error_log("INFO: Keep process $process->id"); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | protected function deleteProcess(\BO\Zmsentities\Process $process) |
| 52 | { |
| 53 | $query = new \BO\Zmsdb\Process(); |
| 54 | if ($query->writeDeletedEntity($process->id) && $this->verbose) { |
| 55 | error_log("INFO: Process $process->id successfully removed"); |
| 56 | } elseif ($this->verbose) { |
| 57 | error_log("WARN: Could not remove process '$process->id'!"); |
| 58 | } |
| 59 | } |
| 60 | } |