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_get_jobs()

Description

Gets a list of offline jobs

Parameters

ColumnTypeDefaultDescription
$type string "" Job type, can be a comma separated list of job types
$status string -1 Job status - see definitions.php
$user int "" Job user
$job_code string "" Unique job code
$job_order_by string "priority" Column to order by - default is priority
$job_sort string "asc" Sort order - ASC or DESC
$find string "" Search jobs for this string
$returnsql bool false Return raw SQL
$maxjobs int 0 Maximum number of jobs to return
$overdue bool false Only return overdue jobs?

Return

mixed Resulting array of requests or an SQL query object

Location

include/job_functions.php lines 126 to 216

Definition

 
function job_queue_get_jobs($type=""$status=-1$user=""$job_code=""$job_order_by="priority"$job_sort="asc"$find=""$returnsql=false,int $maxjobs 0bool $overdue false)
    {
    global 
$userref;
    
$condition = array();
    
$parameters = array();
    if (
$type != "") {
        
$types explode(","$type);
        
$condition[] = " type IN (" ps_param_insert(count($types)). ")";
        
$parameters array_merge($parameters,ps_param_fill($types"s"));
    }
    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 (
$overdue) {
        
$condition[] =" start_date <= ? ";
        
$parameters array_merge($parameters,array("s",date('Y-m-d H:i:s')));
    }

    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";
    }

    
$limit "";
    if (
$maxjobs 0) {
        
$limit " LIMIT ?";
        
$parameters array_merge($parameters,["i",$maxjobs]);
    }
    
$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 " $job_sort $limit;
    if (
$returnsql) {
        return new 
PreparedStatementQuery($sql$parameters);
    }
    return 
ps_query($sql$parameters);
    }

This article was last updated 15th December 2024 08:35 Europe/London time based on the source file dated 18th October 2024 11:40 Europe/London time.