... | ... |
@@ -38,6 +38,14 @@ services: |
38 | 38 |
- "@database_connection" |
39 | 39 |
- "@logger" |
40 | 40 |
|
41 |
+ vonrotenberg.cron.wa_auto_checkin: |
|
42 |
+ class: vonRotenberg\WeinanlieferungBundle\Cron\AutoCheckInJob |
|
43 |
+ public: true |
|
44 |
+ arguments: |
|
45 |
+ - "@database_connection" |
|
46 |
+ - "@logger" |
|
47 |
+ - "@event_dispatcher" |
|
48 |
+ |
|
41 | 49 |
vonrotenberg.wa.slot_checker: |
42 | 50 |
class: vonRotenberg\WeinanlieferungBundle\SlotChecker |
43 | 51 |
public: true |
44 | 52 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,55 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+declare(strict_types=1); |
|
4 |
+ |
|
5 |
+/* |
|
6 |
+ * This file is part of eSales Media SinglereisenBundle |
|
7 |
+ * |
|
8 |
+ * (c) Benjamin Roth |
|
9 |
+ * |
|
10 |
+ * @license proprietary |
|
11 |
+ */ |
|
12 |
+ |
|
13 |
+namespace vonRotenberg\WeinanlieferungBundle\Command; |
|
14 |
+ |
|
15 |
+use Contao\CoreBundle\Framework\ContaoFramework; |
|
16 |
+use Contao\System; |
|
17 |
+use Symfony\Component\Console\Command\Command; |
|
18 |
+use Symfony\Component\Console\Input\InputInterface; |
|
19 |
+use Symfony\Component\Console\Output\OutputInterface; |
|
20 |
+use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
21 |
+use vonRotenberg\WeinanlieferungBundle\Cron\AutoCheckInJob; |
|
22 |
+ |
|
23 |
+class AutoCheckInCommand extends Command |
|
24 |
+{ |
|
25 |
+ private $framework; |
|
26 |
+ private $eventDispatcher; |
|
27 |
+ |
|
28 |
+ public function __construct(ContaoFramework $framework, EventDispatcherInterface $eventDispatcher) |
|
29 |
+ { |
|
30 |
+ $this->framework = $framework; |
|
31 |
+ $this->eventDispatcher = $eventDispatcher; |
|
32 |
+ |
|
33 |
+ parent::__construct(); |
|
34 |
+ } |
|
35 |
+ |
|
36 |
+ protected function configure(): void |
|
37 |
+ { |
|
38 |
+ $this |
|
39 |
+ ->setName('luumicore:autoCheckIn') |
|
40 |
+ ->setDescription('Automatically check in all open bookings within a defined time threshold before the slot time.') |
|
41 |
+ ; |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ protected function execute(InputInterface $input, OutputInterface $output): int |
|
45 |
+ { |
|
46 |
+ $this->framework->initialize(); |
|
47 |
+ |
|
48 |
+ /** @var AutoCheckInJob $wa_service */ |
|
49 |
+ $wa_service = System::getContainer()->get("vonrotenberg.cron.wa_auto_checkin"); |
|
50 |
+ |
|
51 |
+ $wa_service('cli'); |
|
52 |
+ |
|
53 |
+ return 0; |
|
54 |
+ } |
|
55 |
+} |
0 | 56 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,94 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+declare(strict_types=1); |
|
4 |
+ |
|
5 |
+/* |
|
6 |
+* This file is part of contao-weinanlieferung-bundle. |
|
7 |
+* |
|
8 |
+* (c) vonRotenberg |
|
9 |
+* |
|
10 |
+* @license commercial |
|
11 |
+*/ |
|
12 |
+ |
|
13 |
+namespace vonRotenberg\WeinanlieferungBundle\Cron; |
|
14 |
+ |
|
15 |
+use Contao\CoreBundle\Monolog\ContaoContext; |
|
16 |
+use Contao\CoreBundle\ServiceAnnotation\CronJob; |
|
17 |
+use Contao\MemberModel; |
|
18 |
+use Doctrine\DBAL\Connection; |
|
19 |
+use Psr\Log\LoggerInterface; |
|
20 |
+use Psr\Log\LogLevel; |
|
21 |
+use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
22 |
+use vonRotenberg\WeinanlieferungBundle\Event\CheckInCompletedEvent; |
|
23 |
+use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungReservationModel; |
|
24 |
+ |
|
25 |
+/** |
|
26 |
+ * @CronJob("* * * * *") |
|
27 |
+ */ |
|
28 |
+class AutoCheckInJob |
|
29 |
+{ |
|
30 |
+ /** @var LoggerInterface */ |
|
31 |
+ private $logger; |
|
32 |
+ |
|
33 |
+ /** @var Connection */ |
|
34 |
+ private $db; |
|
35 |
+ |
|
36 |
+ private $eventDispatcher; |
|
37 |
+ |
|
38 |
+ |
|
39 |
+ public function __construct(Connection $db, LoggerInterface $logger, EventDispatcherInterface $eventDispatcher) |
|
40 |
+ { |
|
41 |
+ $this->logger = $logger; |
|
42 |
+ $this->db = $db; |
|
43 |
+ $this->eventDispatcher = $eventDispatcher; |
|
44 |
+ } |
|
45 |
+ |
|
46 |
+ public function __invoke(string $scope) |
|
47 |
+ { |
|
48 |
+ $intThreshold = strtotime('+5 minutes'); |
|
49 |
+ $strDefaultNumber = '9999'; |
|
50 |
+ |
|
51 |
+ $Reservations = WeinanlieferungReservationModel::findFutureBy([ |
|
52 |
+ "approved = '1'", |
|
53 |
+ "checked_in = ''", |
|
54 |
+ "? >= (SELECT tl_vr_wa_slot.time FROM tl_vr_wa_slot WHERE tl_vr_wa_slot.id=tl_vr_wa_reservation.pid)" |
|
55 |
+ ],[$intThreshold]); |
|
56 |
+ |
|
57 |
+ if ($Reservations === null) { |
|
58 |
+ return; |
|
59 |
+ } |
|
60 |
+ |
|
61 |
+ foreach ($Reservations as $reservation) { |
|
62 |
+ $reservation = $reservation->current(); |
|
63 |
+ |
|
64 |
+ $memberModel = MemberModel::findById($reservation->uid); |
|
65 |
+ |
|
66 |
+ if (null === $memberModel) { |
|
67 |
+ $this->logger->log( |
|
68 |
+ LogLevel::ERROR, |
|
69 |
+ sprintf('Could not find member with ID: %s', $reservation->uid), |
|
70 |
+ ['contao' => new ContaoContext(__METHOD__, 'AUTO_CHECK_IN')] |
|
71 |
+ ); |
|
72 |
+ continue; |
|
73 |
+ } |
|
74 |
+ |
|
75 |
+ $time = time(); |
|
76 |
+ $reservation->checked_in = '1'; |
|
77 |
+ $reservation->checked_in_on = $time; |
|
78 |
+ |
|
79 |
+ $arrBehaelterNumbers = []; |
|
80 |
+ for ($i = 1; $i <= $reservation->behaelter; $i++) { |
|
81 |
+ $arrBehaelterNumbers[] = [ |
|
82 |
+ 'behaelter' => $strDefaultNumber, |
|
83 |
+ 'member' => $memberModel->memberno |
|
84 |
+ ]; |
|
85 |
+ } |
|
86 |
+ |
|
87 |
+ $reservation->behaelter_numbers = json_encode($arrBehaelterNumbers); |
|
88 |
+ $reservation->save(); |
|
89 |
+ |
|
90 |
+ $event = new CheckInCompletedEvent($reservation->row(), $reservation); |
|
91 |
+ $this->eventDispatcher->dispatch($event, CheckInCompletedEvent::NAME); |
|
92 |
+ } |
|
93 |
+ } |
|
94 |
+} |