24 define(
"TITLE_ui_reunpack", _(
"Schedule an Reunpack"));
32 public $Name =
"ui_reunpack";
33 public $Title = TITLE_ui_reunpack;
35 public $Version =
"1.2";
36 public $Dependency = array();
45 if ($this->
State != PLUGIN_STATE_READY) {
return; }
48 switch($this->OutputType)
55 if (!empty($uploadpk))
57 $P = &$Plugins[plugin_find_id(
"agent_unpack")];
58 $rc = $P->AgentAdd($uploadpk);
62 $text = _(
"Unpack added to job queue");
67 $text = _(
"Unpack of Upload failed");
73 if (empty($GetURL)) { $GetURL=
'http://'; }
83 if (!$this->OutputToStdout) {
return($V); }
103 $SQLcheck =
"SELECT jq_pk,jq_starttime,jq_endtime,jq_end_bits FROM jobqueue 104 LEFT OUTER JOIN job ON jobqueue.jq_job_fk = job.job_pk 105 WHERE job.job_upload_fk = '$uploadpk' 106 AND job.job_name = '$job_name' 107 AND jobqueue.jq_type = '$jobqueue_type' ORDER BY jq_pk DESC;";
108 $result = pg_query($PG_CONN, $SQLcheck);
112 while ($Row = pg_fetch_assoc($result)) {
113 if ($Row[
'jq_end_bits'] == 2) {
117 if (!empty($Row[
'jq_starttime'])) {
118 if (!empty($Row[
'jq_endtime'])) {
132 pg_free_result($result);
146 function AgentAdd ($uploadpk, $Depends=NULL, $priority=0)
149 $Job_name = str_replace(
"'",
"''",
"reunpack");
152 $UploadRec =
GetSingleRec(
"upload",
"where upload_pk='$uploadpk'");
154 $user_fk = $UploadRec[
'user_fk'];
156 $user_fk = $_SESSION[UserId];
158 $SQLARS =
"UPDATE ununpack_ars SET ars_success = FALSE WHERE upload_fk = '$uploadpk';";
159 $result = pg_query($PG_CONN, $SQLARS);
161 pg_free_result($result);
163 if (empty($uploadpk)) {
164 $SQLInsert =
"INSERT INTO job 165 (job_queued,job_priority,job_name,job_user_fk) VALUES 166 (now(),'$priority','$Job_name','$user_fk');";
169 $SQLInsert =
"INSERT INTO job 170 (job_queued,job_priority,job_name,job_upload_fk,job_user_fk) VALUES 171 (now(),'$priority','$Job_name','$uploadpk','$user_fk');";
174 $SQLcheck =
"SELECT job_pk FROM job WHERE job_upload_fk = '$uploadpk'" 175 .
" AND job_name = '$Job_name' AND job_user_fk = '$user_fk' ORDER BY job_pk DESC LIMIT 1;";
176 $result = pg_query($PG_CONN, $SQLcheck);
178 $row = pg_fetch_assoc($result);
179 pg_free_result($result);
182 $jobpk = $row[
'job_pk'];
184 $result = pg_query($PG_CONN, $SQLInsert);
186 $row = pg_fetch_assoc($result);
187 pg_free_result($result);
188 $SQLcheck =
"SELECT job_pk FROM job WHERE job_upload_fk = '$uploadpk'" 189 .
" AND job_name = '$Job_name' AND job_user_fk = '$user_fk';";
190 $result = pg_query($PG_CONN, $SQLcheck);
192 $row = pg_fetch_assoc($result);
193 pg_free_result($result);
194 $jobpk = $row[
'job_pk'];
197 if (empty($jobpk) || ($jobpk < 0)) {
return(
"Failed to insert job record! $SQLInsert"); }
198 if (!empty($Depends) && !is_array($Depends)) { $Depends = array($Depends); }
201 $jqargs =
"SELECT pfile.pfile_sha1 || '.' || pfile.pfile_md5 || '.' || pfile.pfile_size AS pfile, 204 INNER JOIN pfile ON upload.pfile_fk = pfile.pfile_pk 205 WHERE upload.upload_pk = '$uploadpk';";
206 echo
"JobQueueAdd used to do a reschedule here<br>";
207 $jobqueuepk =
JobQueueAdd($jobpk,
"ununpack",$uploadpk,NULL,$Depends);
208 if (empty($jobqueuepk)) {
return(
"Failed to insert item into job queue"); }
214 $ErrorMsg = $error_msg .
"\n" . $output;
230 $sql =
"SELECT upload_fk FROM uploadtree WHERE uploadtree_pk = $Item;";
231 $result = pg_query($PG_CONN, $sql);
233 $row = pg_fetch_assoc($result);
234 pg_free_result($result);
235 if (empty($row[
'upload_fk'])) {
return; }
236 $Upload_pk = $row[
'upload_fk'];
237 $sql =
"SELECT pfile_fk,ufile_name from uploadtree where upload_fk=$Upload_pk and parent is NULL;";
238 $result = pg_query($PG_CONN, $sql);
240 $row = pg_fetch_assoc($result);
241 pg_free_result($result);
242 if (empty($row[
'pfile_fk'])) {
return; }
243 $Pfile_fk = $row[
'pfile_fk'];
244 $Ufile_name = $row[
'ufile_name'];
246 $Fin_gold = @fopen(
RepPath($Pfile_fk,
"gold") ,
"rb");
247 if (empty($Fin_gold))
249 $text = _(
"The File's Gold file is not available in the repository.");
255 $text = _(
"This file is unpacked from");
256 $V.=
"$text <font color='blue'>[".$Ufile_name.
"]</font>\n";
259 $V .=
"<form method='post'>\n";
261 $text = _(
"Reunpack");
262 $V .=
"<p />\n$text: " . $Ufile_name .
"<input name='uploadunpack' type='hidden' value='$Upload_pk'/>\n";
263 $V .=
"<input type='submit' value='$text!' ";
264 if ($Reunpack) {$V .=
"disabled";}
displayMessage($Message, $keep=null)
Display a message.
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
RepPath($PfilePk, $Repo="files")
Given a pfile id, retrieve the pfile path.
CheckStatus($uploadpk, $job_name, $jobqueue_type)
Given an uploadpk and job_name to check if an reunpack/rewget job is running.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
ShowReunpackView($Item, $Reunpack=0)
Generate the reunpack view page. Give the unploadtree_pk, return page view output.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
This is the Plugin class. All plugins should:
AgentAdd($uploadpk, $Depends=NULL, $priority=0)
Given an uploadpk, add a job.
Output()
This function is called when user output is requested. This function is responsible for content...
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.