FEAT_MAIL SENT HISTORY ADDED
This commit is contained in:
parent
b12aff24d9
commit
01b30e4360
1
Job_Queue.txt
Executable file
1
Job_Queue.txt
Executable file
@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
@ -30,6 +30,8 @@ use App\Models\StateModel;
|
|||||||
use App\Models\PolicyTypeModel;
|
use App\Models\PolicyTypeModel;
|
||||||
use App\Models\CDMasterModel;
|
use App\Models\CDMasterModel;
|
||||||
use App\Models\ClientDepositModel;
|
use App\Models\ClientDepositModel;
|
||||||
|
use App\Models\EmployeePolicyModel;
|
||||||
|
use App\Models\FileModel;
|
||||||
use App\Models\InsurerExcelExportTemplateModel;
|
use App\Models\InsurerExcelExportTemplateModel;
|
||||||
use App\Models\SettingsModel;
|
use App\Models\SettingsModel;
|
||||||
use App\Models\VehicleModel;
|
use App\Models\VehicleModel;
|
||||||
@ -1574,7 +1576,7 @@ class MasterController extends AdminController
|
|||||||
$to = $this->request->getPost('to');
|
$to = $this->request->getPost('to');
|
||||||
$subject = $this->request->getPost('subject');
|
$subject = $this->request->getPost('subject');
|
||||||
$mail_content = $this->request->getPost('content');
|
$mail_content = $this->request->getPost('content');
|
||||||
|
$common = ['mail_type'=>'test_mail_ui'];
|
||||||
/*****CHOOSE ANY ONE AT A TIME, COMMENT ANOTHER ONE******/
|
/*****CHOOSE ANY ONE AT A TIME, COMMENT ANOTHER ONE******/
|
||||||
|
|
||||||
/*****CALLING DIRECLT USING LIB******/
|
/*****CALLING DIRECLT USING LIB******/
|
||||||
@ -1591,7 +1593,7 @@ class MasterController extends AdminController
|
|||||||
/*****CALLING DIRECLT USING LIB******/
|
/*****CALLING DIRECLT USING LIB******/
|
||||||
|
|
||||||
/*****CALLING VIA MAIL HELPER******/
|
/*****CALLING VIA MAIL HELPER******/
|
||||||
$res = MailHelper::send_email(['mail' => $to, 'subject' => $subject, 'message' => $mail_content]);
|
$res = MailHelper::send_email(['mail' => $to, 'subject' => $subject,'common'=>$common ,'message' => $mail_content]);
|
||||||
return $this->respond(['status' => 'success','code' => 200,'data' => $res],200);
|
return $this->respond(['status' => 'success','code' => 200,'data' => $res],200);
|
||||||
/*****CALLING VIA MAIL HELPER******/
|
/*****CALLING VIA MAIL HELPER******/
|
||||||
|
|
||||||
@ -1623,10 +1625,10 @@ class MasterController extends AdminController
|
|||||||
["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"],
|
["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"],
|
||||||
["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"]
|
["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"]
|
||||||
];
|
];
|
||||||
|
$common = ['mail_type'=>'test_mail_cli'];
|
||||||
|
|
||||||
$email_id = CLI::getOption('to') ? CLI::getOption('to') : $email_id;
|
$email_id = CLI::getOption('to') ? CLI::getOption('to') : $email_id;
|
||||||
$res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments]);
|
$res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments,'common'=>$common]);
|
||||||
|
echo "Inside the master controller";
|
||||||
print_r($res);
|
print_r($res);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
94
app/Helpers/GmailResponseHandler.php
Normal file
94
app/Helpers/GmailResponseHandler.php
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Models\GmailSentHistoryModel;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class GmailResponseHandler{
|
||||||
|
|
||||||
|
|
||||||
|
public function receive_and_distribute_param_to_functions($params)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
|
||||||
|
$this->store_gmail_response_data($params);
|
||||||
|
$this->gmail_response_logger($params);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
|
||||||
|
$error = $e->getMessage();
|
||||||
|
echo "An Error Occured" . $error;
|
||||||
|
log_message('error',$error);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function store_gmail_response_data($params){
|
||||||
|
// foreach ($params as $key => $value){
|
||||||
|
// $prepare_data = [
|
||||||
|
// $key => $value
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
// $data = [
|
||||||
|
// 'email' => isset($params['params']['mail']) ? $params['params']['mail'] : null,
|
||||||
|
// 'bcc' => isset($params['params']['bcc']) ? json_encode($params['params']['bcc']) : null,
|
||||||
|
// 'cc' => isset($params['params']['cc']) ? json_encode($params['params']['cc']) : null,
|
||||||
|
// 'message' => isset($params['params']['message']) ? $params['params']['message'] : null,
|
||||||
|
// 'attachments' => isset($params['params']['attachments']) ? json_encode($params['params']['attachments']) : null,
|
||||||
|
// 'client_id' => isset($params['params']['common']['client_id']) ? $params['params']['common']['client_id'] : null,
|
||||||
|
// 'client_branch_id' => isset($params['params']['common']['client_branch_id']) ? $params['params']['common']['client_branch_id'] : null,
|
||||||
|
// 'client_policy_id' => isset($params['params']['common']['client_policy_id']) ? $params['params']['common']['client_policy_id'] : null,
|
||||||
|
// 'employee_policy_id' => isset($params['params']['common']['employee_policy_id']) ? $params['params']['common']['employee_policy_id'] : null,
|
||||||
|
// 'employee_id' => isset($params['params']['common']['employee_id']) ? $params['params']['common']['employee_id'] : null,
|
||||||
|
// 'mail_type' => isset($params['params']['common']['mail_type']) ? $params['params']['common']['mail_type'] : null,
|
||||||
|
// 'gmail_api_status' => isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null,
|
||||||
|
// 'gmail_api_id' => isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null
|
||||||
|
// ];
|
||||||
|
// Initialize data array
|
||||||
|
$data = [];
|
||||||
|
// print_r($params['params']['common']);die();
|
||||||
|
if (isset($params['params']['common'])) {
|
||||||
|
foreach ($params['params']['common'] as $key => $value) {
|
||||||
|
$data[$key] = isset($value) ? $value : null;
|
||||||
|
}
|
||||||
|
unset($params['params']['common']);
|
||||||
|
}
|
||||||
|
if (isset($params['params'])){
|
||||||
|
foreach($params['params'] as $key => $value){
|
||||||
|
$arr = ['bcc','cc','attachments'];
|
||||||
|
if(in_array($key,$arr)){
|
||||||
|
$data[$key] = isset($value)?json_encode($value):null;
|
||||||
|
}else{
|
||||||
|
$data[$key] = isset($value)?$value:null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == 1 ){
|
||||||
|
$data['gmail_api_status'] = isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null;
|
||||||
|
$data['gmail_api_id'] = isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null;
|
||||||
|
$data['received_message'] = isset($params['gmail_api']['data']['labelIds']) ? json_encode($params['gmail_api']['data']['labelIds']) : null;
|
||||||
|
|
||||||
|
}
|
||||||
|
elseif(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == false ){
|
||||||
|
$data['gmail_api_status'] = $params['gmail_api']['status'];
|
||||||
|
if(isset($params['gmail_api']['data'])){
|
||||||
|
$data['received_message'] = json_encode($params['gmail_api']['data']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$gmailModel = new GmailSentHistoryModel();
|
||||||
|
$save_status = $gmailModel->insert($data);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function gmail_response_logger($params){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -11,7 +11,7 @@ use Firebase\JWT\SignatureInvalidException;
|
|||||||
// use Psr\Http\Message\RequestInterface;
|
// use Psr\Http\Message\RequestInterface;
|
||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
|
use Exception;
|
||||||
use App\Models\EmployeeModel;
|
use App\Models\EmployeeModel;
|
||||||
use App\Models\LevelContactModel;
|
use App\Models\LevelContactModel;
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,6 @@ use PHPMailer\PHPMailer\Exception;
|
|||||||
|
|
||||||
use App\Models\JobModel;
|
use App\Models\JobModel;
|
||||||
|
|
||||||
|
|
||||||
class MailHelper
|
class MailHelper
|
||||||
{
|
{
|
||||||
public static function send_email_smtp($params)
|
public static function send_email_smtp($params)
|
||||||
@ -94,7 +93,7 @@ class MailHelper
|
|||||||
$subject = $params['subject'];
|
$subject = $params['subject'];
|
||||||
$message = $params['message'];
|
$message = $params['message'];
|
||||||
$attachments = isset($params['attachments']) && count($params['attachments']) ? $params['attachments'] : [];
|
$attachments = isset($params['attachments']) && count($params['attachments']) ? $params['attachments'] : [];
|
||||||
|
$common = isset($params['common'])?$params['common']:'';
|
||||||
//check BCC mail
|
//check BCC mail
|
||||||
if (isset($params['bcc'])) {
|
if (isset($params['bcc'])) {
|
||||||
$bcc = $params['bcc'];
|
$bcc = $params['bcc'];
|
||||||
@ -118,26 +117,36 @@ class MailHelper
|
|||||||
if(isset($params['reply_to']) && !empty($params['reply_to'])){
|
if(isset($params['reply_to']) && !empty($params['reply_to'])){
|
||||||
$reply_to = $params['reply_to'];
|
$reply_to = $params['reply_to'];
|
||||||
}
|
}
|
||||||
|
$MailDataHelper = new GmailResponseHandler();
|
||||||
|
|
||||||
|
$res['params'] = $params;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$res = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments);
|
$res['gmail_api'] = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments);
|
||||||
|
if($res['gmail_api']['status'])
|
||||||
if($res['status'])
|
|
||||||
{
|
{
|
||||||
|
$response = $res;
|
||||||
|
// $MailDataHelper->receive_and_distribute_param_to_functions($response);
|
||||||
return json_encode(['status' => 'success','code' => 200, 'message'=>('Email Sent Successfully...'.$emaill),'data' => $res,],200);
|
return json_encode(['status' => 'success','code' => 200, 'message'=>('Email Sent Successfully...'.$emaill),'data' => $res,],200);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$myLogger->logme('error', "mail sent failed - $emaill");
|
$myLogger->logme('error', "mail sent failed - $emaill");
|
||||||
|
$response = $res;
|
||||||
|
// $MailDataHelper->receive_and_distribute_param_to_functions($response);
|
||||||
return json_encode(['status' => 'failed','code' => 404,'message'=>( 'Email Sent Failed...' . $emaill ),'data' => $res ],404);
|
return json_encode(['status' => 'failed','code' => 404,'message'=>( 'Email Sent Failed...' . $emaill ),'data' => $res ],404);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$msg = $e->getMessage();
|
$msg['error'] = $e->getMessage();
|
||||||
|
$msg['params'] = $params;
|
||||||
$myLogger->logme('error', "mail sent failed - $msg");
|
$myLogger->logme('error', "mail sent failed - $msg");
|
||||||
|
$response = $msg;
|
||||||
|
// $MailDataHelper->receive_and_distribute_param_to_functions($response);
|
||||||
return json_encode(['status' => 'failed','code' => 500,'data' => $msg],500);
|
return json_encode(['status' => 'failed','code' => 500,'data' => $msg],500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
app/Models/GmailSentHistoryModel.php
Normal file
11
app/Models/GmailSentHistoryModel.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class GmailSentHistoryModel extends Model{
|
||||||
|
protected $table = 'gmail_sent_history';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $allowedFields = ["id", "mail", "bcc", "cc", "message", "attachments", "client_id", "client_branch_id", "client_policy_id", "employee_policy_id", "employee_id", "mail_type", "gmail_api_status", "gmail_api_id", "created_by", "created_at", "updated_by", "updated_at", "isactive","received_message"];
|
||||||
|
}
|
||||||
42
phpqueue.bat
Normal file
42
phpqueue.bat
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
|
REM Get the directory of the current script
|
||||||
|
set "ROOT_DIR=%~dp0"
|
||||||
|
set "JOB_QUEUE_FILE=%ROOT_DIR%job_queue"
|
||||||
|
set "PID_FILE=%ROOT_DIR%phpqueue.pid"
|
||||||
|
|
||||||
|
REM Check if the script is already running
|
||||||
|
if exist "%PID_FILE%" (
|
||||||
|
for /f "tokens=*" %%i in (%PID_FILE%) do set PID=%%i
|
||||||
|
tasklist /fi "PID eq !PID!" | findstr /i "!PID!" >nul
|
||||||
|
if not errorlevel 1 (
|
||||||
|
echo phpqueue.bat is already running. Exiting.
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Write the current process ID (PID) to the PID file
|
||||||
|
echo %PROCESS_ID% > "%PID_FILE%"
|
||||||
|
|
||||||
|
REM Main loop
|
||||||
|
:loop
|
||||||
|
REM Check if the Job_Queue file exists
|
||||||
|
if not exist "%JOB_QUEUE_FILE%" (
|
||||||
|
echo Job Queue file not found.
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Read the value of Job_Queue from the file
|
||||||
|
set /p Job_Queue=<%JOB_QUEUE_FILE%
|
||||||
|
|
||||||
|
if "%Job_Queue%"=="1" (
|
||||||
|
REM Run PHP job processing
|
||||||
|
php "%ROOT_DIR%htdocs/nhance/public/index.php" cli/processjob
|
||||||
|
) else (
|
||||||
|
echo No job to process.
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Sleep for 1 second before the next iteration
|
||||||
|
timeout /T 1 >nul
|
||||||
|
goto loop
|
||||||
1
phpqueue.pid
Normal file
1
phpqueue.pid
Normal file
@ -0,0 +1 @@
|
|||||||
|
575
|
||||||
56
phpqueue.sh
Executable file
56
phpqueue.sh
Executable file
@ -0,0 +1,56 @@
|
|||||||
|
!/bin/bash
|
||||||
|
while true; do
|
||||||
|
echo "Running job at $(date)"
|
||||||
|
/usr/bin/php /opt/lampp/htdocs/nhance/public/index.php cli/processjob
|
||||||
|
!/bin/bash
|
||||||
|
!/bin/bash
|
||||||
|
|
||||||
|
# Read the Job_Queue variable from the temporary file
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Define the root directory for the project and PID file path
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Define paths
|
||||||
|
# ROOT_DIR=$(dirname "$(realpath "$0")")
|
||||||
|
# JOB_QUEUE_FILE="$ROOT_DIR/job_queue"
|
||||||
|
# PID_FILE="$ROOT_DIR/phpqueue.pid"
|
||||||
|
|
||||||
|
|
||||||
|
# # Check if the script is already running
|
||||||
|
# if [[ -f "$PID_FILE" ]] && kill -0 "$(cat $PID_FILE)" 2>/dev/null; then
|
||||||
|
# echo "phpqueue.sh is already running. Exiting."
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# # Write the current process ID (PID) to the PID file
|
||||||
|
# echo $$ > "$PID_FILE"
|
||||||
|
|
||||||
|
# # Ensure the PID file is removed on script exit
|
||||||
|
# trap "rm -f $PID_FILE" EXIT
|
||||||
|
|
||||||
|
# # Main loop
|
||||||
|
# while true; do
|
||||||
|
# # Check if the Job_Queue file exists
|
||||||
|
# if [[ ! -f "$JOB_QUEUE_FILE" ]]; then
|
||||||
|
# echo "Job Queue file not found."
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# # Read the value of Job_Queue from the file
|
||||||
|
# Job_Queue=$(cat "$JOB_QUEUE_FILE")
|
||||||
|
|
||||||
|
# if [[ "$Job_Queue" -eq 1 ]]; then
|
||||||
|
# /usr/bin/php /opt/lampp/htdocs/nhance/public/index.php cli/processjob
|
||||||
|
# else
|
||||||
|
# echo "No job to process."
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# # Sleep for 1 second before the next iteration
|
||||||
|
# sleep 1
|
||||||
|
# done
|
||||||
|
|
||||||
13
phpsetvariable.sh
Executable file
13
phpsetvariable.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Validate input argument
|
||||||
|
# if [[ "$1" == "1" ]]; then
|
||||||
|
# echo "1" > /opt/lampp/htdocs/nhance/Job_Queue
|
||||||
|
# echo "Job Queue variable has been set to: 1"
|
||||||
|
# elif [[ "$1" == "0" ]]; then
|
||||||
|
# echo "0" > /opt/lampp/htdocs/nhance/Job_Queue
|
||||||
|
# echo "Job Queue variable has been set to: 0"
|
||||||
|
# else
|
||||||
|
# echo "Invalid argument. Use 1 to enable the queue or 0 to disable it."
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
Loading…
Reference in New Issue
Block a user