60 $dbManager = $container->get(
'db.manager');
62 if (empty($userId) || empty($job_name) || empty($filename) ||
63 empty($UploadMode) || empty($folder_pk)) {
67 $row = $dbManager->getSingleRow(
"INSERT INTO upload
68 (upload_desc,upload_filename,user_fk,upload_mode,upload_origin,public_perm) VALUES ($1,$2,$3,$4,$5,$6) RETURNING upload_pk",
69 array($desc,$job_name,$userId,$UploadMode,$filename, $public_perm),__METHOD__.
'.insert.upload');
70 $uploadId = $row[
'upload_pk'];
72 $dbManager->getSingleRow(
"INSERT INTO foldercontents (parent_fk,foldercontents_mode,child_id) VALUES ($1,$2,$3)",
73 array($folder_pk,FolderDao::MODE_UPLOAD,$uploadId),
'insert.foldercontents');
76 if ($setGlobal != 1) {
80 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
81 $uploadDao->getGlobalDecisionSettingsFromInfo($uploadId, $setGlobal);
86 if (empty($groupId)) {
87 $usersRow = $dbManager->getSingleRow(
'SELECT * FROM users WHERE user_pk=$1',
88 array($userId), __METHOD__.
'.select.user');
89 $groupId = $usersRow[
'group_fk'];
93 $dbManager->getSingleRow(
"INSERT INTO perm_upload (perm, upload_fk, group_fk) VALUES ($1,$2,$3)",
94 array($perm_admin, $uploadId, $groupId),
'insert.perm_upload');
111 function JobAddJob($userId, $groupId, $job_name, $upload_pk=0, $priority=0)
116 $dbManager = $container->get(
'db.manager');
118 $upload_pk_val = empty($upload_pk) ? null : $upload_pk;
120 $params = array($userId, $priority, $job_name, $upload_pk_val);
121 $stmtName = __METHOD__;
122 if (empty($groupId)) {
123 $stmtName .=
"noGrp";
124 $groupPkVal =
"(SELECT group_fk FROM users WHERE user_pk = $1)";
126 $params[] = $groupId;
127 $groupPkVal =
"$". count($params);
130 $row = $dbManager->getSingleRow(
132 (job_user_fk,job_group_fk,job_queued,job_priority,job_name,job_upload_fk) VALUES
133 ($1,$groupPkVal,now(),$2,$3,$4) RETURNING job_pk",
138 return intval($row[
'job_pk']);
157 function JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host = NULL, $jq_cmd_args=NULL)
160 $jq_args = pg_escape_string($jq_args);
161 $jq_cmd_args = pg_escape_string($jq_cmd_args);
164 if (is_array($Depends)) {
165 foreach ($Depends as $Dependency) {
166 if (empty($Dependency)) {
170 $sql =
"SELECT jq_pk FROM jobqueue WHERE jq_pk = '$Dependency'";
173 $MissingDep = (pg_num_rows($result) == 0);
174 pg_free_result($result);
183 $result = pg_query(
$PG_CONN, $sqlBegin);
185 pg_free_result($result);
188 $sql =
"INSERT INTO jobqueue ";
189 $sql.=
"(jq_job_fk,jq_type,jq_args,jq_runonpfile,jq_starttime,jq_endtime,jq_end_bits,jq_host,jq_cmd_args) VALUES ";
190 $sql.=
"('$job_pk','$jq_type','$jq_args',";
191 $sql .= (empty($jq_runonpfile)) ?
"NULL" :
"'$jq_runonpfile'";
192 $sql.=
",NULL,NULL,0,";
193 $sql .= $host ?
"'$host'," :
"NULL,";
194 $sql .= $jq_cmd_args ?
"'$jq_cmd_args')" :
"NULL)";
198 pg_free_result($result);
201 $jq_pk =
GetLastSeq(
"jobqueue_jq_pk_seq",
"jobqueue");
206 pg_free_result($result);
211 if (is_array($Depends)) {
212 foreach ($Depends as $Dependency) {
213 if (empty($Dependency)) {
216 $sql =
"INSERT INTO jobdepends (jdep_jq_fk,jdep_jq_depends_fk) VALUES ('$jq_pk','$Dependency')";
219 pg_free_result($result);
227 pg_free_result($result);
248 if (empty($status)) {
251 $sql =
"SELECT jq_pk FROM jobqueue WHERE jq_endtext like '%$status%' order by jq_pk;";
254 $job_array = pg_fetch_all_columns($result, 0);
255 pg_free_result($result);
274 $user_pk = Auth::getUserId();
275 $group_pk = Auth::getGroupId();
277 if (empty($upload_pk_list)) {
281 $agent_count = count($agent_list);
282 foreach (explode(
",", $upload_pk_list) as $upload_pk) {
283 if (empty($upload_pk)) {
288 $where =
"where upload_pk ='$upload_pk'";
290 if (empty($UploadRec)) {
291 echo
"ERROR: unknown upload_pk: $upload_pk\n";
295 $ShortName = $UploadRec[
'upload_filename'];
298 $job_pk = JobAddJob($user_pk, $group_pk, $ShortName, $upload_pk);
302 for ($ac = 0; $ac < $agent_count; $ac ++) {
303 $agentname = $agent_list[$ac]->URI;
304 if (! empty($agentname)) {
305 $Agent = & $Plugins[plugin_find_id($agentname)];
307 $ErrorMsg =
"already queued!";
308 $agent_jq_pk = $Agent->AgentAdd($job_pk, $upload_pk, $ErrorMsg,
310 if ($agent_jq_pk <= 0) {
311 echo
"WARNING: Scheduling failed for Agent $agentname, upload_pk is: $upload_pk, job_pk is:$job_pk\n";
312 echo
"WARNING message: $ErrorMsg\n";
313 }
else if ($Verbose) {
314 $SQL =
"SELECT upload_filename FROM upload where upload_pk = $upload_pk";
317 $row = pg_fetch_assoc($result);
318 pg_free_result($result);
320 "$agentname is queued to run on $upload_pk:$row[upload_filename].\n";
336 $user_pk = Auth::getUserId();
337 $group_pk = Auth::getGroupId();
339 if (! empty($upload_pk_list)) {
340 foreach (explode(
",", $upload_pk_list) as $upload_pk) {
341 if (empty($upload_pk)) {
346 $jobpk = JobAddJob($user_pk, $group_pk,
"Delete", $upload_pk);
347 if (empty($jobpk) || ($jobpk < 0)) {
348 echo
"WARNING: Failed to schedule Delagent for Upload $upload_pk";
350 $jqargs =
"DELETE UPLOAD $upload_pk";
351 $jobqueuepk =
JobQueueAdd($jobpk,
"delagent", $jqargs, NULL, NULL);
352 if (empty($jobqueuepk)) {
353 echo
"WARNING: Failed to schedule Delagent for Upload $upload_pk";
355 print
"Delagent is queued to run on Upload: $upload_pk.\n";
361 echo $error_msg .
"\n" . $output;
391 if ($AgentName ==
"ununpack" || $AgentName ==
"adj2nest") {
392 $sql =
"SELECT jq_pk FROM jobqueue, job where job_pk=jq_job_fk " .
393 "AND jq_type='$AgentName' and job_upload_fk = $upload_pk";
396 $sql =
"SELECT jq_pk FROM jobqueue, job where job_pk=jq_job_fk AND jq_type='$AgentName' and job_pk=$job_pk";
400 if (pg_num_rows($result) > 0) {
401 $row = pg_fetch_assoc($result);
402 $jq_pk = $row[
"jq_pk"];
404 pg_free_result($result);
433 function CommonAgentAdd($plugin, $job_pk, $upload_pk, &$ErrorMsg, $Dependencies, $jqargs =
"", $jq_cmd_args = NULL)
437 $DependsEmpty = array();
440 if ($plugin->AgentHasResults($upload_pk) == 1) {
450 foreach ($Dependencies as $Dependency) {
451 if (is_array($Dependency)) {
452 $PluginName = $Dependency[
'name'];
453 $DepArgs = $Dependency[
'args'];
455 $PluginName = $Dependency;
459 if ($DepPlugin ===
null) {
460 $ErrorMsg =
"Invalid plugin name: $PluginName, (CommonAgentAdd())";
463 if (($Deps[] = $DepPlugin->AgentAdd($job_pk, $upload_pk, $ErrorMsg, $DependsEmpty, $DepArgs)) == - 1) {
468 if (empty($jqargs)) {
469 $jqargs = $upload_pk;
471 $jq_pk =
JobQueueAdd($job_pk, $plugin->AgentName, $jqargs,
"", $Deps, NULL,
475 "Failed to insert agent $plugin->AgentName into job queue. jqargs: $jqargs");
481 $ErrorMsg = $error_msg .
"\n" . $output;
504 $sql =
"SELECT jq_pk FROM jobqueue INNER JOIN job ON job_pk = jq_job_fk "
505 .
"WHERE jq_type='$agentName' AND job_upload_fk = $upload_pk "
506 .
"AND jq_end_bits = 0";
509 if (pg_num_rows($result) > 0) {
510 $row = pg_fetch_assoc($result);
511 $jq_pk = $row[
"jq_pk"];
513 pg_free_result($result);
514 return intval($jq_pk);
Contains the constants and helpers for authentication of user.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
GetLastSeq($seqname, $tablename)
Get last sequence number.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
isAlreadyRunning($agentName, $upload_pk)
Check if an agent is already running in a job.
CommonAgentAdd($plugin, $job_pk, $upload_pk, &$ErrorMsg, $Dependencies, $jqargs="", $jq_cmd_args=NULL)
Queue an agent. This is a simple version of AgentAdd() that can be used by multiple plugins that only...
QueueUploadsOnDelagents($upload_pk_list)
Schedule delagent on upload ids.
QueueUploadsOnAgents($upload_pk_list, $agent_list, $Verbose)
Schedule agent tasks on upload ids.
GetJobList($status)
Gets the list of jobqueue records with the requested $status.
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
JobAddUpload($userId, $groupId, $job_name, $filename, $desc, $UploadMode, $folder_pk, $public_perm=Auth::PERM_NONE, $setGlobal=0)
Insert a new upload record, and update the foldercontents table.
IsAlreadyScheduled($job_pk, $AgentName, $upload_pk)
Check if an agent is already scheduled in a job.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
#define PERM_ADMIN
Administrator.
#define PERM_NONE
User has no permission (not logged in)
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN