FIX_BULK_MAIL_ISSUE : RV

This commit is contained in:
VENKATESHWARAN 2024-11-28 10:10:26 +05:30
parent b0a869f1fc
commit 8128a95c66
2 changed files with 48 additions and 15 deletions

View File

@ -695,6 +695,7 @@ class EmployeeRestController extends AdminController
$decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true);
// get the employee id from token
$employee_id = $decodedPayload['id'];
// $employee_id = 1;
$client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->where('client_branch_id', $client_branch_id)->first();
if ($client_policy) {
$policy = $this->policesModel->where('id', $client_policy['policy_id'])->first();
@ -875,7 +876,10 @@ class EmployeeRestController extends AdminController
$basic_cover_si[]= $basic_cover_si_value;
}
}
$count = 0;
$wholeData=[];// Initialize an empty array to store employee email.
for ($a=0; $a <count($dataToInsert) ; $a++)
{
$date_coverage = $dataToInsert[$a]['date_coverage'];
@ -949,7 +953,7 @@ class EmployeeRestController extends AdminController
if (isset($notification) && $notification['enabled'] == 1 && !empty($notification['mail_content'])) {
//trigger
$wholeData=[];
// $wholeData=[];
if ($dataToInsert[$a]['relationship'] == 'Self' && isset($dataToInsert[$a]['email_corporate']) && !empty($dataToInsert[$a]['email_corporate'])) {
$params['dataToInsert'] = $dataToInsert[$a];
@ -959,20 +963,33 @@ class EmployeeRestController extends AdminController
$wholeData[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params);
$count++;
}
if($count == 20 || $a == count($dataToInsert)-1){
if (count($wholeData) > 0) {
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]);
$wholeData = [];
$count = 0;
}
}
// if($count == 20 || $a == count($dataToInsert)-1){
// if (count($wholeData) > 0) {
// $job_details = new Jobs();
// $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]);
// $wholeData = [];
// $count = 0;
// }
// }
// if ($dataToInsert[$a]['email_corporate'] != null || $dataToInsert[$a]['email_corporate'] != '' && $dataToInsert[$a]['relationship'] == 'Self') {
}
}
// for bulk mail queue job push
if (!empty($wholeData) && count($wholeData) > 0) {
$wholeData = array_chunk($wholeData, 20);
foreach ($wholeData as $key => $value) {
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]);
}
}
$this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => '','error_data' => ''])->update();
return $this->respond(['status' => 'success', 'code' => 200, 'message' => "Success" ], 200);
}else{

View File

@ -1979,6 +1979,9 @@ public function employeesEnrollmentInsert($params)
// dd($notification);
$client_details = $this->clientModel->where('id', $file['client_id'])->first();
$emp_emails = []; // Initialize an empty array to store employee email.
foreach ($excel_data as $key => $row)
{
// dd($key.'-'.count($excel_data));
@ -2095,17 +2098,30 @@ public function employeesEnrollmentInsert($params)
// Kint::dump($emp_emails);
// Kint::dump($key.'-'.count($excel_data));
// if mail count is 20 send bulk mail and reset emp_emails variable
if (count($emp_emails) == 20 || $key == count($excel_data) ) {
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $emp_emails]);
// echo 'Mail triggered';
$emp_emails = [];
}
// if (count($emp_emails) == 20 || $key == count($excel_data) ) {
// $job_details = new Jobs();
// $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $emp_emails]);
// // echo 'Mail triggered';
// $emp_emails = [];
// }
}
}
} //end of for loop
// for bulk mail queue job push
if (!empty($emp_emails) && count($emp_emails) > 0) {
$emp_emails = array_chunk($emp_emails, 20);
foreach ($emp_emails as $key => $value) {
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]);
}
}
$this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update();
$this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]);