-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cron job for processing pre order bookings
- Loading branch information
1 parent
723601e
commit 7918672
Showing
4 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 2024 Jaap Jansma ([email protected]) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Krabo\IsotopeStockBundle\Cron; | ||
|
||
use Contao\CoreBundle\ServiceAnnotation\CronJob; | ||
use Contao\CoreBundle\Framework\ContaoFramework; | ||
use Contao\Database; | ||
use Contao\System; | ||
use Isotope\Model\Product; | ||
use Krabo\IsotopeStockBundle\Event\Events; | ||
use Krabo\IsotopeStockBundle\Event\ManualBookingEvent; | ||
use Krabo\IsotopeStockBundle\Helper\BookingHelper; | ||
use Krabo\IsotopeStockBundle\Model\BookingModel; | ||
|
||
/** | ||
* @CronJob("minutely") | ||
*/ | ||
class CheckBookingEvents | ||
{ | ||
|
||
/** | ||
* @param \Contao\CoreBundle\Framework\ContaoFramework $contaoFramework | ||
*/ | ||
public function __construct(ContaoFramework $contaoFramework) | ||
{ | ||
$contaoFramework->initialize(); | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
$config = System::getContainer()->getParameter('jvh.jvh_isotope_stock.config'); | ||
/** @var Database $db */ | ||
$db = System::importStatic('Database'); | ||
$objResult = $db->execute("SELECT * FROM `tl_isotope_stock_booking_event` LIMIT 0, 1"); | ||
$ids = []; | ||
while($objResult->next()) { | ||
$ids[] = $objResult->id; | ||
$booking = BookingModel::findByPk($objResult->booking_id); | ||
BookingHelper::updateBalanceStatusForBooking($booking->id); | ||
$event = new ManualBookingEvent($booking); | ||
System::getContainer() | ||
->get('event_dispatcher') | ||
->dispatch($event, Events::MANUAL_BOOKING_EVENT); | ||
} | ||
if (count($ids)) { | ||
$sql = "DELETE FROM `tl_isotope_stock_booking_event` WHERE `id` IN (" . implode(", ", $ids) . ")"; | ||
$db->execute($sql); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Resources/contao/dca/tl_isotope_stock_booking_event.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 2022 Jaap Jansma ([email protected]) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
$GLOBALS['TL_DCA']['tl_isotope_stock_booking_event'] = array | ||
( | ||
// Config | ||
'config' => array | ||
( | ||
'dataContainer' => 'Table', | ||
'switchToEdit' => true, | ||
'sql' => array | ||
( | ||
'keys' => array | ||
( | ||
'id' => 'primary' | ||
) | ||
), | ||
), | ||
|
||
// Fields | ||
'fields' => array | ||
( | ||
'id' => array | ||
( | ||
'sql' => "int(10) unsigned NOT NULL auto_increment" | ||
), | ||
'tstamp' => array | ||
( | ||
'sql' => "int(10) unsigned NOT NULL default 0" | ||
), | ||
'booking_id' => array | ||
( | ||
'sql' => "int(10) unsigned NOT NULL default 0" | ||
), | ||
) | ||
); |