12 define(
"TITLE_ui_reunpack", _(
"Schedule an Reunpack"));
20 public $Name =
"ui_reunpack";
21 public $Title = TITLE_ui_reunpack;
23 public $Version =
"1.2";
24 public $Dependency = array();
33 if ($this->
State != PLUGIN_STATE_READY) {
return; }
36 switch($this->OutputType)
43 if (!empty($uploadpk))
45 $P = &$Plugins[plugin_find_id(
"agent_unpack")];
46 $rc = $P->AgentAdd($uploadpk);
50 $text = _(
"Unpack added to job queue");
55 $text = _(
"Unpack of Upload failed");
61 if (empty($GetURL)) { $GetURL=
'http://'; }
71 if (!$this->OutputToStdout) {
return($V); }
92 $SQLcheck =
"SELECT jq_pk,jq_starttime,jq_endtime,jq_end_bits FROM jobqueue
93 LEFT OUTER JOIN job ON jobqueue.jq_job_fk = job.job_pk
94 WHERE job.job_upload_fk = '$uploadpk'
95 AND job.job_name = '$job_name'
96 AND jobqueue.jq_type = '$jobqueue_type' ORDER BY jq_pk DESC;";
97 $result = pg_query(
$PG_CONN, $SQLcheck);
101 while ($Row = pg_fetch_assoc($result)) {
102 if ($Row[
'jq_end_bits'] == 2) {
106 if (!empty($Row[
'jq_starttime'])) {
107 if (!empty($Row[
'jq_endtime'])) {
121 pg_free_result($result);
135 function AgentAdd ($uploadpk, $Depends=NULL, $priority=0)
138 $Job_name = str_replace(
"'",
"''",
"reunpack");
141 $UploadRec =
GetSingleRec(
"upload",
"where upload_pk='$uploadpk'");
143 $user_fk = $UploadRec[
'user_fk'];
145 $user_fk = $_SESSION[UserId];
147 $SQLARS =
"UPDATE ununpack_ars SET ars_success = FALSE WHERE upload_fk = '$uploadpk';";
148 $result = pg_query(
$PG_CONN, $SQLARS);
150 pg_free_result($result);
152 if (empty($uploadpk)) {
153 $SQLInsert =
"INSERT INTO job
154 (job_queued,job_priority,job_name,job_user_fk) VALUES
155 (now(),'$priority','$Job_name','$user_fk');";
158 $SQLInsert =
"INSERT INTO job
159 (job_queued,job_priority,job_name,job_upload_fk,job_user_fk) VALUES
160 (now(),'$priority','$Job_name','$uploadpk','$user_fk');";
163 $SQLcheck =
"SELECT job_pk FROM job WHERE job_upload_fk = '$uploadpk'"
164 .
" AND job_name = '$Job_name' AND job_user_fk = '$user_fk' ORDER BY job_pk DESC LIMIT 1;";
165 $result = pg_query(
$PG_CONN, $SQLcheck);
167 $row = pg_fetch_assoc($result);
168 pg_free_result($result);
171 $result = pg_query(
$PG_CONN, $SQLInsert);
173 $row = pg_fetch_assoc($result);
174 pg_free_result($result);
175 $SQLcheck =
"SELECT job_pk FROM job WHERE job_upload_fk = '$uploadpk'"
176 .
" AND job_name = '$Job_name' AND job_user_fk = '$user_fk';";
177 $result = pg_query(
$PG_CONN, $SQLcheck);
179 $row = pg_fetch_assoc($result);
180 pg_free_result($result);
182 $jobpk = $row[
'job_pk'];
184 if (empty($jobpk) || ($jobpk < 0)) {
return(
"Failed to insert job record! $SQLInsert"); }
185 if (!empty($Depends) && !is_array($Depends)) { $Depends = array($Depends); }
188 $jqargs =
"SELECT pfile.pfile_sha1 || '.' || pfile.pfile_md5 || '.' || pfile.pfile_size AS pfile,
191 INNER JOIN pfile ON upload.pfile_fk = pfile.pfile_pk
192 WHERE upload.upload_pk = '$uploadpk';";
193 echo
"JobQueueAdd used to do a reschedule here<br>";
194 $jobqueuepk =
JobQueueAdd($jobpk,
"ununpack",$uploadpk,NULL,$Depends);
195 if (empty($jobqueuepk)) {
return(
"Failed to insert item into job queue"); }
201 $ErrorMsg = $error_msg .
"\n" . $output;
217 $sql =
"SELECT upload_fk FROM uploadtree WHERE uploadtree_pk = $Item;";
220 $row = pg_fetch_assoc($result);
221 pg_free_result($result);
222 if (empty($row[
'upload_fk'])) {
return; }
223 $Upload_pk = $row[
'upload_fk'];
224 $sql =
"SELECT pfile_fk,ufile_name from uploadtree where upload_fk=$Upload_pk and parent is NULL;";
227 $row = pg_fetch_assoc($result);
228 pg_free_result($result);
229 if (empty($row[
'pfile_fk'])) {
return; }
230 $Pfile_fk = $row[
'pfile_fk'];
231 $Ufile_name = $row[
'ufile_name'];
233 $Fin_gold = @fopen(
RepPath($Pfile_fk,
"gold") ,
"rb");
234 if (empty($Fin_gold))
236 $text = _(
"The File's Gold file is not available in the repository.");
237 return "<p/>$text\n";
241 $text = _(
"This file is unpacked from");
242 $V.=
"$text <font color='blue'>[".$Ufile_name.
"]</font>\n";
245 $V .=
"<form method='post'>\n";
247 $text = _(
"Reunpack");
248 $V .=
"<p />\n$text: " . $Ufile_name .
"<input name='uploadunpack' type='hidden' value='$Upload_pk'/>\n";
249 $V .=
"<input type='submit' value='$text!' ";
250 if ($Reunpack) {$V .=
"disabled";}
This is the Plugin class. All plugins should:
CheckStatus($uploadpk, $job_name, $jobqueue_type)
Given an uploadpk and job_name to check if an reunpack/rewget job is running.
AgentAdd($uploadpk, $Depends=NULL, $priority=0)
Given an uploadpk, add a job.
ShowReunpackView($Item, $Reunpack=0)
Generate the reunpack view page. Give the unploadtree_pk, return page view output.
Output()
This function is called when user output is requested. This function is responsible for content....
displayMessage($Message, $keep=null)
Display a message.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
RepPath($PfilePk, $Repo="files")
Given a pfile id, retrieve the pfile path.
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN