notify restaurant fix
This commit is contained in:
parent
25e00881c6
commit
124fc96812
@ -4,6 +4,8 @@ class Controller_api_test extends Cana_Controller {
|
||||
|
||||
public function init(){
|
||||
|
||||
$cron = new Crunchbutton_Cron_Job_RestaurantFixNotify;
|
||||
$cron->run();
|
||||
// Crunchbutton_Pexcard_Transaction::getOrderExpenses( '01/18/2015', '01/19/2015' );
|
||||
// Crunchbutton_Community_Shift::pexCardRemoveShiftFunds();
|
||||
// Crunchbutton_Community_Shift::pexCardRemoveShiftFunds();
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class Crunchbutton_Cron_Job_RestaurantFixNotify extends Crunchbutton_Cron_Log {
|
||||
|
||||
public function run(){
|
||||
|
||||
$orders = Order::q( 'SELECT * FROM `order` o
|
||||
INNER JOIN (
|
||||
SELECT DISTINCT( id_order ) FROM `order` o
|
||||
LEFT JOIN notification n ON n.id_restaurant = o.id_restaurant AND n.active = 1
|
||||
WHERE o.date > date_sub( now(), interval 10 minute ) ) filter ON filter.id_order = o.id_order' );
|
||||
|
||||
echo "start notification send fix";
|
||||
echo "<br>\n";
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$notifications = $order->restaurant()->notifications();
|
||||
foreach( $notifications as $notification ){
|
||||
// Check if the notification was sent
|
||||
$wasSent = Crunchbutton_Notification_Log::notificationOrder( $order->id_order, $notification->id_notification );
|
||||
if( !$wasSent ){
|
||||
echo "sending notification " . $notification->id_notification . " for order " . $order->id_order;
|
||||
$notification->send( $order );
|
||||
} else {
|
||||
echo "notification " . $notification->id_notification . " for order " . $order->id_order . " already sent";
|
||||
}
|
||||
echo "<br>\n";
|
||||
}
|
||||
}
|
||||
|
||||
// it always must call finished method at the end
|
||||
$this->finished();
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,10 @@ class Crunchbutton_Notification_Log extends Cana_Table {
|
||||
return Order::o($this->id_order);
|
||||
}
|
||||
|
||||
public function notificationOrder( $id_order, $id_notification ){
|
||||
return self::q('SELECT * FROM notification_log WHERE id_order = "' . $id_order . '" AND id_notification="' . $id_notification . '"')->count();
|
||||
}
|
||||
|
||||
public function tries() {
|
||||
return self::q('select * from notification_log where id_order="'.$this->id_order.'"')->count();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user