133 lines
4.5 KiB
PHP
Executable File
133 lines
4.5 KiB
PHP
Executable File
<?php declare(strict_types=1); namespace IR\App\Webservices; if (!defined('IR_START')) exit('<pre>No direct script access allowed</pre>');
|
|
|
|
# core
|
|
use IR\Core\Base as Base;
|
|
use IR\Core\Application as Application;
|
|
|
|
# helpers
|
|
use IR\App\Helpers\Authentication as Authentication;
|
|
use IR\App\Helpers\Page as Page;
|
|
use IR\App\Helpers\Api as Api;
|
|
|
|
# models
|
|
use IR\App\Models\Production\MtaProcess as MtaProcess;
|
|
use IR\App\Models\Production\SmtpProcess as SmtpProcess;
|
|
use IR\App\Models\Admin\User as User;
|
|
|
|
|
|
# orm
|
|
use IR\Orm\Table as Table;
|
|
use IR\Orm\Sequence as Sequence;
|
|
|
|
# http
|
|
use IR\Http\Client as Client;
|
|
|
|
/**
|
|
* @name Tracking
|
|
* @description Tracking WebService
|
|
*/
|
|
class ScheduledDrops extends Base
|
|
{
|
|
/**
|
|
* @app
|
|
* @readwrite
|
|
*/
|
|
protected $app;
|
|
|
|
/**
|
|
* @name init
|
|
* @description initializing process before the action method executed
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function init()
|
|
{
|
|
# set the current application to a local variable
|
|
$this->app = Application::getCurrent();
|
|
|
|
# get api authenticated user
|
|
$this->authenticatedUser = new User([
|
|
'id' => 5,
|
|
'production_id' => 1,
|
|
'master_access' => 'Enabled',
|
|
'status' => 'Activated',
|
|
'first_name' => 'Khalid',
|
|
'last_name' => 'Tracking User',
|
|
'email' => 'nanocellule@gmail.com',
|
|
'is_tracking_user' => true
|
|
]);
|
|
|
|
# store api authenticated user
|
|
Authentication::registerUser($this->authenticatedUser);
|
|
|
|
# check users roles
|
|
// Authentication::checkUserRoles();
|
|
}
|
|
|
|
/**
|
|
* @name getLink
|
|
* @description get offer link action
|
|
* @before init
|
|
*/
|
|
public function scheckScheduledDrops($parameters = [])
|
|
{
|
|
# check for authentication
|
|
if(!Authentication::isUserAuthenticated())
|
|
{
|
|
Page::printApiResults(401,'Only logged-in access allowed !');
|
|
}
|
|
|
|
$methods = array("mta", "smtp");
|
|
|
|
// Loop through the array using foreach
|
|
foreach ($methods as $method) {
|
|
|
|
$processSchedule = $method == 'mta' ? MtaProcess::all(MtaProcess::FETCH_ARRAY,['status = ?','Scheduled'],['id','process_id','process_type','start_time'],'id','DESC')
|
|
: SmtpProcess::all(SmtpProcess::FETCH_ARRAY,['status = ?','Scheduled'],['id','process_type','start_time'],'id','DESC');
|
|
|
|
if(count($processSchedule)>0)
|
|
{
|
|
$existProcess=false;
|
|
foreach ($processSchedule as $process)
|
|
{
|
|
|
|
$processId=$process['id'];
|
|
$startTime=$process['start_time'];
|
|
$processType=$process['process_type'];
|
|
|
|
$currentTime = date('Y-m-d H:i:s');
|
|
|
|
// Check if the current time is before the start time
|
|
if (strtotime($currentTime) >= strtotime($startTime)) {
|
|
|
|
//Current datetime is before the start time.
|
|
$controller = $method == 'mta' ? 'MtaProcesses' : 'SmtpProcesses';
|
|
$action = $processType == 'drop' ? 'proceedDrop' : 'proceedTest';
|
|
|
|
|
|
# save the process into the database
|
|
$process = $method == 'mta' ? new MtaProcess(['id' => $processId]) : new SmtpProcess(['id' => $processId]);
|
|
|
|
$process->load();
|
|
$process->setStatus('In Progress');
|
|
$process->setStartTime(date('Y-m-d H:i:s'));
|
|
$process->update();
|
|
|
|
# call iresponse api
|
|
Api::call($controller,$action,['process-id' => $processId],true);
|
|
// $existProcess=true;
|
|
|
|
}/*else{
|
|
echo "currentTime: ".strtotime($currentTime)."\n";
|
|
echo "startTime: ".strtotime($startTime)."\n";
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
Page::printApiResults(200,'Your process Scheduled has been started !');
|
|
|
|
}
|
|
|
|
} |