Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

job_queue_get_jobs()

Description

Gets a list of offline jobs

Parameters

ColumnTypeDefaultDescription
$type string "" Job type
$status string -1 Job status - see definitions.php
$user int "" Job user
$job_code string "" Unique job code
$job_order_by string "priority"
$job_sort string "asc"
$find string ""
$returnsql bool false

Return

mixed Resulting array of requests or an SQL query object

Location

include/job_functions.php lines 124 to 218

Definition

 
function job_queue_get_jobs($type=""$status=-1$user=""$job_code=""$job_order_by="priority"$job_sort="asc"$find=""$returnsql=false)
    {
    global 
$userref;
    
$condition = array();
    
$parameters = array();
    if(
$type != "")
        {
        
$condition[] = " type = ? ";
        
$parameters array_merge($parameters,array("s",$type));
        }
    if(!
checkperm('a') && PHP_SAPI != 'cli')
        {
        
// Don't show certain jobs for normal users
        
$hiddentypes = array();
        
$hiddentypes[] = "delete_file";
        
$condition[] = " type NOT IN (" ps_param_insert(count($hiddentypes)) . ")";  
        
$parameters array_merge($parametersps_param_fill($hiddentypes,"s"));
        }
        
    if((int)
$status > -1)
        {
        
$condition[] =" status = ? ";
        
$parameters array_merge($parameters,array("i",(int)$status));
        }

    if((int)
$user 0)
        {
        
// Has user got access to see this user's jobs?
        
if($user == $userref || checkperm_user_edit($user))
            {             
            
$condition[] = " user = ?";
            
$parameters array_merge($parameters,array("i",(int)$user));
            }
        elseif(isset(
$userref))
            {
            
// Only show own jobs
            
$condition[] = " user = ?";
            
$parameters array_merge($parameters,array("i",(int)$userref));
            }
        else
            {
            
// No access - return empty array
            
return array();
            }
        }
    else
        {
        
// Requested jobs for all users - only possible for cron or system admin, set condition otherwise
        
if(PHP_SAPI != "cli" && !checkperm('a'))
            {
            if(isset(
$userref))
                {
                
// Only show own jobs
                
$condition[] = " user = ?";
                
$parameters array_merge($parameters,array("i",(int)$userref));
                }
            else
                {
                
// No access - return nothing
                
return array();
                }
            }
        }

    if(
$job_code!="")
        {
        
$condition[] =" job_code = ?";
        
$parameters array_merge($parameters,array("s",$job_code));
        }

    if(
$find!="")
        {
        
$find '%' $find '%';
        
$condition[] = " (j.ref LIKE ? OR j.job_data LIKE ? OR j.success_text LIKE ? OR j.failure_text LIKE ? OR j.user LIKE ? OR u.username LIKE ? OR u.fullname LIKE ?)";
        }

    
$conditional_sql="";
    if (
count($condition)>0){$conditional_sql=" where " implode(" and ",$condition);}
    
    
// Check order by value is valid
    
if (!in_array(strtolower($job_order_by), array("priority""ref""type""fullname""status""start_date")))
        {
        
$job_order_by "priority";
        }
    
    
// Check sort value is valid
    
if (!in_array(strtolower($job_sort), array("asc""desc")))
        {
        
$job_sort "asc";
        }

    
$sql "SELECT j.ref, j.type, replace(replace(j.job_data,'\r',' '),'\n',' ') as job_data, j.user, j.status, j.start_date, j.success_text, j.failure_text,j.job_code, j.priority, u.username, u.fullname FROM job_queue j LEFT JOIN user u ON u.ref = j.user " $conditional_sql " ORDER BY " $job_order_by " " $job_sort ",start_date ASC";
    if(
$returnsql){return new PreparedStatementQuery($sql$parameters);}
    return 
ps_query($sql$parameters);
    }

This article was last updated 19th March 2024 11:05 Europe/London time based on the source file dated 23rd February 2024 17:00 Europe/London time.