partial #2969 - put the notification inside the timeout
This commit is contained in:
parent
3587009ff9
commit
2f48c594a2
@ -7,7 +7,6 @@ class Cockpit_Driver_Notify extends Cana_Table {
|
|||||||
|
|
||||||
public function send( $id_admin, $message ){
|
public function send( $id_admin, $message ){
|
||||||
|
|
||||||
|
|
||||||
$driver = Crunchbutton_Admin::o( $id_admin );
|
$driver = Crunchbutton_Admin::o( $id_admin );
|
||||||
|
|
||||||
if( !$driver->id_admin ){
|
if( !$driver->id_admin ){
|
||||||
@ -39,9 +38,39 @@ class Cockpit_Driver_Notify extends Cana_Table {
|
|||||||
return [ 'error' => 'enter a message' ];
|
return [ 'error' => 'enter a message' ];
|
||||||
}
|
}
|
||||||
|
|
||||||
$env = c::getEnv();
|
$notification = new Cockpit_Driver_Notify;
|
||||||
|
$notification->id_admin = $driver->id_admin;
|
||||||
|
$notification->phone = $phone;
|
||||||
|
$notification->email = $driver->email;
|
||||||
|
$notification->message = $message;
|
||||||
|
|
||||||
//!todo: put this notifications at timeout
|
|
||||||
|
Cana::timeout( function() use( $notification ) {
|
||||||
|
$notification->notify();
|
||||||
|
} );
|
||||||
|
|
||||||
|
// log
|
||||||
|
$log = new Cockpit_Driver_Log();
|
||||||
|
$log->id_admin = $id_admin;
|
||||||
|
$log->action = Cockpit_Driver_Log::ACTION_NOTIFIED_SETUP;
|
||||||
|
$log->info = $phone . ' (' . $driver->email . ') ' . $message;
|
||||||
|
$log->datetime = date('Y-m-d H:i:s');
|
||||||
|
$log->save();
|
||||||
|
|
||||||
|
return [ 'success' => 'notification sent' ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function notify(){
|
||||||
|
|
||||||
|
$notification = $this;
|
||||||
|
|
||||||
|
$message = $notification->message;
|
||||||
|
$id_admin = $notification->id_admin;
|
||||||
|
$phone = $notification->phone;
|
||||||
|
$email = $notification->email;
|
||||||
|
|
||||||
|
$env = c::getEnv();
|
||||||
|
|
||||||
$twilio = new Twilio( c::config()->twilio->{$env}->sid, c::config()->twilio->{$env}->token );
|
$twilio = new Twilio( c::config()->twilio->{$env}->sid, c::config()->twilio->{$env}->token );
|
||||||
|
|
||||||
@ -62,33 +91,18 @@ class Cockpit_Driver_Notify extends Cana_Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send email
|
// Send email
|
||||||
if( $driver->email ){
|
if( $email ){
|
||||||
|
|
||||||
switch ( $message ) {
|
switch ( $message ) {
|
||||||
case Cockpit_Driver_Notify::TYPE_WELCOME:
|
case Cockpit_Driver_Notify::TYPE_WELCOME:
|
||||||
$mail = new Cockpit_Email_Driver_Welcome( [ 'id_admin' => $driver->id_admin ] );
|
$mail = new Cockpit_Email_Driver_Welcome( [ 'id_admin' => $id_admin ] );
|
||||||
// $mail->send();
|
$mail->send();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Cockpit_Driver_Notify::TYPE_SETUP:
|
case Cockpit_Driver_Notify::TYPE_SETUP:
|
||||||
$mail = new Cockpit_Email_Driver_Setup( [ 'id_admin' => $driver->id_admin ] );
|
$mail = new Cockpit_Email_Driver_Setup( [ 'id_admin' => $id_admin ] );
|
||||||
// $mail->send();
|
$mail->send();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $isOk ){
|
|
||||||
// log
|
|
||||||
$log = new Cockpit_Driver_Log();
|
|
||||||
$log->id_admin = $driver->id_admin;
|
|
||||||
$log->action = Cockpit_Driver_Log::ACTION_NOTIFIED_SETUP;
|
|
||||||
$log->info = $phone . ': ' . join( $message );
|
|
||||||
$log->datetime = date('Y-m-d H:i:s');
|
|
||||||
$log->save();
|
|
||||||
return [ 'success' => 'notification sent' ];
|
|
||||||
} else {
|
|
||||||
return [ 'error' => 'notification not sent' ];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user