Collections functions
General functions
Render functions
Theme permission functions
Resource functions

job_queue_add()

Description

Adds a job to the job_queue table.

Parameters

ColumnTypeDefaultDescription
$type string ""
$job_data array array
$user string ""
$time string ""
$success_text string ""
$failure_text string ""
$job_code string ""
$priority int NULL

Return

string|integer ID of newly created job or error text

Location

include/job_functions.php lines 19 to 47

Definition

 
function job_queue_add($type="",$job_data=array(),$user="",$time=""$success_text=""$failure_text=""$job_code="",$priority=NULL)
    {
    global 
$lang$userref;
    if(
$time==""){$time=date('Y-m-d H:i:s');}
    if(
$type==""){return false;}
    if(
$user==""){$user=isset($userref)?$userref:0;}
    
// Assign priority based on job type if not explicitly passed
    
if(!is_int_loose($priority))
        {
        
$priority get_job_type_priority($type);
        }

    
$job_data_json=json_encode($job_data,JSON_UNESCAPED_SLASHES); // JSON_UNESCAPED_SLASHES is needed so we can effectively compare jobs
    
    
if($job_code == "")
        {
        
// Generate a code based on job data to avoid incorrect duplicate job detection
        
$job_code $type "_" substr(md5(serialize($job_data)),10);
        }

    
// Check for existing job matching
    
$existing_user_jobs=job_queue_get_jobs($type,STATUS_ACTIVE,"",$job_code);
    if(
count($existing_user_jobs)>0)
            {
            return 
$lang["job_queue_duplicate_message"];
            }
    
ps_query("INSERT INTO job_queue (type,job_data,user,start_date,status,success_text,failure_text,job_code, priority) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", array("s",$type,"s",$job_data_json,"i",$user,"s",$time,"i",STATUS_ACTIVE,"s",$success_text,"s",$failure_text,"s",$job_code,"i",(int)$priority));
    return 
sql_insert_id();
    }

This article was last updated 24th May 2022 20:35 Europe/London time based on the source file dated 19th May 2022 17:05 Europe/London time.