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 ){
|
||||
|
||||
|
||||
$driver = Crunchbutton_Admin::o( $id_admin );
|
||||
|
||||
if( !$driver->id_admin ){
|
||||
@ -38,10 +37,40 @@ class Cockpit_Driver_Notify extends Cana_Table {
|
||||
if( trim( $message ) == '' ){
|
||||
return [ 'error' => 'enter a message' ];
|
||||
}
|
||||
|
||||
$env = c::getEnv();
|
||||
|
||||
//!todo: put this notifications at timeout
|
||||
$notification = new Cockpit_Driver_Notify;
|
||||
$notification->id_admin = $driver->id_admin;
|
||||
$notification->phone = $phone;
|
||||
$notification->email = $driver->email;
|
||||
$notification->message = $message;
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
@ -62,33 +91,18 @@ class Cockpit_Driver_Notify extends Cana_Table {
|
||||
}
|
||||
|
||||
// Send email
|
||||
if( $driver->email ){
|
||||
|
||||
if( $email ){
|
||||
switch ( $message ) {
|
||||
case Cockpit_Driver_Notify::TYPE_WELCOME:
|
||||
$mail = new Cockpit_Email_Driver_Welcome( [ 'id_admin' => $driver->id_admin ] );
|
||||
// $mail->send();
|
||||
$mail = new Cockpit_Email_Driver_Welcome( [ 'id_admin' => $id_admin ] );
|
||||
$mail->send();
|
||||
break;
|
||||
|
||||
case Cockpit_Driver_Notify::TYPE_SETUP:
|
||||
$mail = new Cockpit_Email_Driver_Setup( [ 'id_admin' => $driver->id_admin ] );
|
||||
// $mail->send();
|
||||
$mail = new Cockpit_Email_Driver_Setup( [ 'id_admin' => $id_admin ] );
|
||||
$mail->send();
|
||||
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