Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 17th November 2024 15:35 Europe/London time based on the source file dated 18th October 2024 11:40 Europe/London time.