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

View File

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