return (object)array('output' => $output, 'exitcode' => (integer)$exitcode);
}
- public function bconsoleCommand($director, array $command, $ptype = null) {
+ public function bconsoleCommand($director, array $command, $ptype = null, $without_cmd = false) {
$result = null;
if (count($this->config) > 0 && $this->config['enabled'] !== '1') {
throw new BConsoleException(
$base_command = count($command) > 0 ? $command[0] : null;
if($this->isCommandValid($base_command) === true) {
$result = $this->execCommand($director, $command, $ptype);
+ if ($without_cmd) {
+ array_shift($result->output);
+ }
} else {
throw new BConsoleException(
BconsoleError::MSG_ERROR_INVALID_COMMAND,
return $dbsize;
}
- public static function getWhere(array $params) {
+ public static function getWhere(array $params, $without_where = false) {
$where = '';
$parameters = array();
if (count($params) > 0) {
$parameters[$pkey] = $pval;
}
}
- $where = ' WHERE (' . implode(') AND (' , $condition) . ')';
+ if (count($condition) > 0) {
+ $where = ' (' . implode(') AND (' , $condition) . ')';
+ if ($without_where === false) {
+ $where = ' WHERE ' . $where;
+ }
+ }
}
return array('where' => $where, 'params' => $parameters);
}
* @return array jobs for specific client
*/
public function getJobsForClient($clientid, $allowed_jobs = array()) {
- $jobs_criteria = '';
+ $where = '';
if (count($allowed_jobs) > 0) {
- $jobs_sql = implode("', '", $allowed_jobs);
- $jobs_criteria = " AND Job.Name IN ('" . $jobs_sql . "')";
+ $criteria = [
+ 'Job.Name' => [
+ 'vals' => $allowed_jobs,
+ 'operator' => 'OR'
+ ]
+ ];
+ $where = Database::getWhere($criteria, true);
+ $wh = '';
+ if (count($where['params']) > 0) {
+ $wh = ' AND ' . $where['where'];
+ }
}
$sql = "SELECT DISTINCT Job.*,
Client.Name as client,
LEFT JOIN Client USING (ClientId)
LEFT JOIN Pool USING (PoolId)
LEFT JOIN FileSet USING (FilesetId)
-WHERE Client.ClientId='$clientid' $jobs_criteria";
- return JobRecord::finder()->findAllBySql($sql);
+WHERE Client.ClientId='$clientid' $wh";
+ return JobRecord::finder()->findAllBySql($sql, $where['params']);
}
/**
$jobid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.jobs')
+ ['.jobs'],
+ null,
+ true
);
if ($result->exitcode === 0) {
- array_shift($result->output);
$job = $this->getModule('job')->getJobById($jobid);
if (is_object($job) && in_array($job->name, $result->output)) {
$this->output = $job;
$jobid = intval($id);
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.jobs')
+ ['.jobs'],
+ null,
+ true
);
if ($result->exitcode === 0) {
- array_shift($result->output);
$job = $this->getModule('job')->getJobById($jobid);
if(is_object($job) && in_array($job->name, $result->output)) {
$result = $this->getModule('bconsole')->bconsoleCommand(
}
$jobid = null;
- $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
+ $result = $this->getModule('bconsole')->bconsoleCommand(
+ $this->director,
+ ['.jobs'],
+ null,
+ true
+ );
if ($result->exitcode === 0) {
- array_shift($result->output);
if(is_object($job) && in_array($job->name, $result->output)) {
$jobid = $job->jobid;
}
class JobEstimate extends BaculumAPIServer {
public function get() {
- $output = array();
+ $output = [];
$misc = $this->getModule('misc');
if ($this->Request->contains('out_id') && $misc->isValidAlphaNumeric($this->Request->itemAt('out_id'))) {
$out_id = $this->Request->itemAt('out_id');
$this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
return;
} else {
- $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
+ $result = $this->getModule('bconsole')->bconsoleCommand(
+ $this->director,
+ ['.jobs'],
+ null,
+ true
+ );
if ($result->exitcode === 0) {
- array_shift($result->output);
if (!in_array($job, $result->output)) {
$this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
$this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.jobs')
+ ['.jobs'],
+ null,
+ true
);
if ($result->exitcode === 0) {
- array_shift($result->output);
- $job = $this->getModule('job')->getJobsByFilename($clientid, $filename, $strict_mode, $result->output);
- $this->output = $job;
- $this->error = JobError::ERROR_NO_ERRORS;
+ if (count($result->output) == 0) {
+ // no allowed jobs means that user has no job resource assigned.
+ $this->output = [];
+ $this->error = JobError::ERROR_NO_ERRORS;
+ } else {
+ $job = $this->getModule('job')->getJobsByFilename($clientid, $filename, $strict_mode, $result->output);
+ $this->output = $job;
+ $this->error = JobError::ERROR_NO_ERRORS;
+ }
} else {
$result = is_array($result->output) ? implode('', $result->output) : $result->output;
$this->output = JobError::MSG_ERROR_WRONG_EXITCODE . $result;
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.jobs')
+ ['.jobs'],
+ null,
+ true
);
if ($result->exitcode === 0) {
- array_shift($result->output);
$job = $this->getModule('job')->getJobById($jobid);
if (is_object($job) && in_array($job->name, $result->output)) {
if ($details) {
}
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.jobs')
+ ['.jobs'],
+ null,
+ true
);
if ($result->exitcode === 0) {
- array_shift($result->output);
$job = $this->getModule('job')->getJobById($jobid);
if (is_object($job) && in_array($job->name, $result->output)) {
$log = $this->getModule('joblog')->getLogByJobId($job->jobid, $show_time);
class JobResNames extends BaculumAPIServer {
public function get() {
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
- $jobs_cmd = array('.jobs');
+ $jobs_cmd = ['.jobs'];
$types = $this->getModule('misc')->job_types;
if ($this->Request->contains('type') && key_exists($this->Request['type'], $types)) {
array_push($jobs_cmd, 'type="' . $this->Request['type']. '"');
$this->error = $directors->exitcode;
return;
}
- $jobs = array();
+ $jobs = [];
$error = false;
$error_obj = null;
for ($i = 0; $i < count($directors->output); $i++) {
- $job_list = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], $jobs_cmd);
+ $job_list = $this->getModule('bconsole')->bconsoleCommand(
+ $directors->output[$i],
+ $jobs_cmd,
+ null,
+ true
+ );
if ($job_list->exitcode != 0) {
$error_obj = $job_list;
$error = true;
break;
}
- // shift command
- array_shift($job_list->output);
- $jobs[$directors->output[$i]] = array();
+ $jobs[$directors->output[$i]] = [];
for ($j = 0; $j < count($job_list->output); $j++) {
$jobs[$directors->output[$i]][] = $job_list->output[$j];
$this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
return;
} else {
- $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
+ $result = $this->getModule('bconsole')->bconsoleCommand(
+ $this->director,
+ ['.jobs'],
+ null,
+ true
+ );
if ($result->exitcode === 0) {
- array_shift($result->output);
if (!in_array($job, $result->output)) {
$this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
$this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
$jobid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.jobs')
+ ['.jobs'],
+ null,
+ true
);
if ($result->exitcode === 0) {
- array_shift($result->output);
$job = $this->getModule('job')->getJobById($jobid);
if (is_object($job) && in_array($job->name, $result->output)) {
$result = $this->getModule('bconsole')->bconsoleCommand(
class JobTotals extends BaculumAPIServer {
public function get() {
$error = false;
- $allowed = array();
- $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
+ $allowed = [];
+ $result = $this->getModule('bconsole')->bconsoleCommand(
+ $this->director,
+ ['.jobs'],
+ null,
+ true
+ );
if ($result->exitcode === 0) {
- array_shift($result->output);
$allowed = $result->output;
+ if (count($allowed) == 0) {
+ // no $allowed means that user has no job resource assigned.
+ $error = true;
+ $this->output = [];
+ $this->error = JobError::ERROR_NO_ERRORS;
+ }
} else {
$error = true;
$this->output = $result->output;
return;
}
- $params = array();
+ $params = [];
$jobstatuses = array_keys($misc->getJobState());
$sts = str_split($jobstatus);
for ($i = 0; $i < count($sts); $i++) {
$params['Job.Type']['operator'] = '';
$params['Job.Type']['vals'] = $type;
}
- $allowed = array();
- $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
+ $allowed = [];
+ $result = $this->getModule('bconsole')->bconsoleCommand(
+ $this->director,
+ ['.jobs'],
+ null,
+ true
+ );
if ($result->exitcode === 0) {
- array_shift($result->output);
- $vals = array();
+ $vals = [];
if (!empty($jobname) && in_array($jobname, $result->output)) {
- $vals = array($jobname);
+ $vals = [$jobname];
} else {
$vals = $result->output;
}
+ if (count($vals) == 0) {
+ // no $vals criteria means that user has no job resources assigned.
+ $this->output = [];
+ $this->error = JobError::ERROR_NO_ERRORS;
+ return;
+ }
+
$params['Job.Name']['operator'] = 'OR';
$params['Job.Name']['vals'] = $vals;
}
if (is_object($cli) && in_array($cli->name, $result->output)) {
$params['Job.ClientId']['operator'] = 'AND';
- $params['Job.ClientId']['vals'] = array($cli->clientid);
+ $params['Job.ClientId']['vals'] = [$cli->clientid];
} else {
$error = true;
$this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
$allowed_jobs = array();
$clientid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
$error = false;
- $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
+ $result = $this->getModule('bconsole')->bconsoleCommand(
+ $this->director,
+ ['.jobs'],
+ null,
+ true
+ );
if ($result->exitcode === 0) {
- array_shift($result->output);
$allowed_jobs = $result->output;
+ if (count($allowed_jobs) == 0) {
+ // no $allowed_jobs means that user has no job resources assigned.
+ $error = true;
+ $this->output = [];
+ $this->error = JobError::ERROR_NO_ERRORS;
+ }
} else {
$error = true;
$this->output = $result->output;
$error = false;
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.jobs')
+ ['.jobs'],
+ null,
+ true
);
if ($result->exitcode === 0) {
- array_shift($result->output);
$allowed = $result->output;
+ if (count($allowed) == 0) {
+ // no $allowed means that user has no job resources assigned.
+ $error = true;
+ $this->output = [];
+ $this->error = JobError::ERROR_NO_ERRORS;
+ }
} else {
$error = true;
$this->output = $result->output;
$this->output = FileSetError::MSG_ERROR_FILESET_DOES_NOT_EXISTS;
$this->error = FileSetError::ERROR_FILESET_DOES_NOT_EXISTS;
} else {
- $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
+ $result = $this->getModule('bconsole')->bconsoleCommand(
+ $this->director,
+ ['.jobs'],
+ null,
+ true
+ );
if ($result->exitcode === 0) {
- array_shift($result->output);
if (in_array($jobname, $result->output)) {
$jobs = $this->getModule('job')->getRecentJobids($jobname, $clientid, $filesetid, $inc_copy_job);
if (is_array($jobs)) {
public function get() {
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.jobs')
+ ['.jobs'],
+ null,
+ true
);
$job = null;
if ($result->exitcode === 0) {
- array_shift($result->output);
if ($this->Request->contains('name')) {
if (in_array($this->Request['name'], $result->output)) {
$job = $this->Request['name'];
$poolid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.pool')
+ ['.pool'],
+ null,
+ true
);
if ($result->exitcode === 0) {
- array_shift($result->output);
$pool = $this->getModule('pool')->getPoolById($poolid);
if(!is_null($pool) && in_array($pool->name, $result->output)) {
$this->output = $pool;
public function get() {
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
$pools = $this->getModule('pool')->getPools($limit);
- $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool'));
+ $result = $this->getModule('bconsole')->bconsoleCommand(
+ $this->director,
+ ['.pool'],
+ null,
+ true
+ );
if ($result->exitcode === 0) {
- array_shift($result->output);
if (is_array($pools) && count($pools) > 0) {
$pools_output = array();
foreach($pools as $pool) {
$fileid = $this->Request->contains('fileid') ? intval($this->Request['fileid']) : 0;
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
- array('.jobs')
+ ['.jobs'],
+ null,
+ true
);
if ($result->exitcode === 0) {
- array_shift($result->output);
$job = $this->getModule('job')->getJobById($jobid);
if(is_object($job) && in_array($job->name, $result->output)) {
$volumes = $this->getModule('volume')->getVolumesForJob($jobid, $fileid);