Extend advanced_mailer module to log and test Push Notifications

This commit is contained in:
Kijin Sung 2020-06-24 20:13:46 +09:00
parent 04da475562
commit 4271bb9862
20 changed files with 540 additions and 16 deletions

View file

@ -17,6 +17,9 @@ class Push
protected $click_action = '';
protected $data = [];
protected $errors = array();
protected $success_tokens = array();
protected $deleted_tokens = array();
protected $updated_tokens = array();
protected $sent = false;
/**
@ -284,12 +287,14 @@ class Push
try
{
$tokens = $this->_getDeviceTokens();
$output = null;
// Android FCM
if(count($tokens->android))
{
$fcm_driver = $this->getDriver('fcm');
$output = $fcm_driver->send($this, $tokens->android);
$this->sent = $output->invalid ? false : true;
$this->sent = count($output->success) ? true : false;
$this->_deleteInvalidTokens($output->invalid);
$this->_updateDeviceTokens($output->needUpdate);
}
@ -299,10 +304,14 @@ class Push
{
$apns_driver =$this->getDriver('apns');
$output = $apns_driver->send($this, $tokens->ios);
$this->sent = $output->invalid ? false : true;
$this->sent = count($output->success) ? true : false;
$this->_deleteInvalidTokens($output->invalid);
$this->_updateDeviceTokens($output->needUpdate);
}
$this->success_tokens = $output ? $output->success : [];
$this->deleted_tokens = $output ? $output->invalid : [];
$this->updated_tokens = $output ? $output->needUpdate : [];
}
catch(\Exception $e)
{
@ -428,6 +437,36 @@ class Push
return $this->errors;
}
/**
* Get success tokens.
*
* @return array
*/
public function getSuccessTokens(): array
{
return $this->success_tokens;
}
/**
* Get deleted tokens.
*
* @return array
*/
public function getDeletedTokens(): array
{
return $this->deleted_tokens;
}
/**
* Get updated tokens.
*
* @return array
*/
public function getUpdatedTokens(): array
{
return $this->updated_tokens;
}
/**
* Add an error message.
*