23 use Symfony\Component\HttpFoundation\JsonResponse;
 
   25 define(
"TITLE_AJAXSHOWJOBS", _(
"ShowJobs"));
 
   35   const MAX_LOG_OUTPUT = 32768;
 
   51     $this->Name = 
"ajaxShowJobs";
 
   52     $this->Title = TITLE_AJAXSHOWJOBS;
 
   56     $this->OutputType = 
'JSON';
 
   57     $this->OutputToStdout = 
true;
 
   60     $this->showJobsDao = $container->get(
'dao.show_jobs');
 
   61     $this->userDao = $container->get(
'dao.user');
 
   62     $this->clearingDao = $container->get(
'dao.clearing');
 
   63     $this->
dbManager = $container->get(
'db.manager');
 
   65     parent::__construct();
 
   70     if ($this->
State != PLUGIN_STATE_READY) {
 
   74     if (empty($uploadId)) {
 
   87     $job_pk1 = $JobsInfo1[
"job"][
"job_pk"];
 
   88     $job_pk2 = $JobsInfo2[
"job"][
"job_pk"];
 
   90     return $job_pk2 - $job_pk1;
 
  101     $fields=array(
'jq_pk'=>
'jq_pk',
 
  102                   'job_pk'=>
'jq_job_fk',
 
  103                   'Job Name'=> 
'job_name',
 
  104                   'Agent Name'=>
'jq_type',
 
  105                   'Priority'=>
'job_priority',
 
  107                   'jq_runonpfile'=>
'jq_runonpfile',
 
  108                   'Queued'=>
'job_queued',
 
  109                   'Started'=>
'jq_starttime',
 
  110                   'Ended'=>
'jq_endtime',
 
  111                   'Elapsed HH:MM:SS'=>
'elapsed',
 
  112                   'Status'=>
'jq_end_bits',
 
  113                   'Items processed'=>
'jq_itemsprocessed',
 
  114                   'Submitter'=>
'job_user_fk',
 
  115                   'Upload'=>
'job_upload_fk',
 
  119     $row = $this->showJobsDao->getDataForASingleJob($job_pk);
 
  122     foreach ($fields as $labelKey=>$field) {
 
  129           if (! empty($row[$field])) {
 
  133         case 'jq_itemsprocessed':
 
  134           $value = number_format($row[$field]);
 
  140           if (!empty($row[
'job_upload_fk'])) {
 
  141             $value = 
"<a href='$uri" . $row[
'job_upload_fk'] . 
"'>" . htmlentities($row[$field]) . 
"</a>".
" (" . _(
"Click to view jobs for this upload") . 
")";
 
  144             $back = 
"(" . _(
"Click to return to Show Jobs") . 
")";
 
  145             $value = 
"<a href='$uri2'>$row[$field] $back</a>";
 
  148         case 'job_upload_fk':
 
  149           if (!empty($row[$field])) {
 
  150             $browse = 
Traceback_uri() . 
"?mod=browse&upload=" . htmlentities($row[$field]);
 
  151             $value = 
"<a href='$browse'>" . htmlentities($row[$field]) . 
"</a>".
" (" . _(
"Click to browse upload") . 
")";
 
  155           if (empty($row[$field]) || $row[$field] == 
'removed' || !file_exists($row[$field])) {
 
  158           if (filesize($row[$field]) > self::MAX_LOG_OUTPUT) {
 
  159             $value = 
"<pre>" .file_get_contents($row[$field],
false,
null,-1,self::MAX_LOG_OUTPUT).
"</pre>" 
  160                     .
'<a href="'.
Traceback_uri() . 
'?mod=download&log=' . $row[
'jq_pk'] . 
'">Download full log</a>';
 
  162             $value = 
"<pre>" . file_get_contents($row[$field]). 
"</pre>";
 
  166           if (!empty($row[$field])) {
 
  167             $value = $this->userDao->getUserName($row[$field]);
 
  171           $jq_args_temp = $row[$field];
 
  172           $jq_args_show = $jq_args_temp;
 
  173           if (! empty($jq_args_temp)) {
 
  174             $pos = strpos($jq_args_temp, 
' SVN ');
 
  176               $jq_args_show = substr($jq_args_temp, 0, $pos + 4);
 
  178             $pos = strpos($jq_args_temp, 
' CVS ');
 
  180               $jq_args_show = substr($jq_args_temp, 0, $pos + 4);
 
  182             $pos = strpos($jq_args_temp, 
' Git ');
 
  184               $jq_args_show = substr($jq_args_temp, 0, $pos + 4);
 
  186             $value = $jq_args_show;
 
  190           if (array_key_exists($field, $row)) {
 
  191             $value = htmlentities($row[$field]);
 
  195       $table[] = array(
'DT_RowId' => $i++,
 
  199     $tableData = array_values($table);
 
  200     return new JsonResponse(array(
'sEcho' => intval($_GET[
'sEcho']),
 
  201                                   'aaData' => $tableData,
 
  202                                   'iTotalRecords' => count($tableData),
 
  203                                   'iTotalDisplayRecords' => count($tableData)));
 
  215     if (count($jobData) == 0) {
 
  216       return array(
'showJobsData' => 
"There are no jobs to display");
 
  219     foreach ($jobData as $jobId => $jobs) {
 
  221         'jobId' => $jobs[
'job'][
'job_pk'],
 
  222         'jobName' => $jobs[
'job'][
'job_name'],
 
  223         'jobQueue' => $jobs[
'jobqueue']
 
  225       foreach ($jobArr[
'jobQueue'] as $key => $singleJobQueue) {
 
  227           if (! empty($jobArr[
'jobQueue'][$key][
'jq_starttime'])) {
 
  229               $jobArr[
'jobQueue'][$key][
'jq_starttime']);
 
  231           if (! empty($jobArr[
'jobQueue'][$key][
'jq_endtime'])) {
 
  233               $jobArr[
'jobQueue'][$key][
'jq_endtime']) ;
 
  236         if (! empty($singleJobQueue[
"jq_endtime"])) {
 
  237           $numSecs = strtotime($singleJobQueue[
'jq_endtime']) -
 
  238             strtotime($singleJobQueue[
'jq_starttime']);
 
  239           $numSecs = ($numSecs == 0) ? 1 : $numSecs; 
 
  241           $numSecs = time() - strtotime($singleJobQueue[
'jq_starttime']);
 
  244         $jobArr[
'jobQueue'][$key][
'itemsPerSec'] = $itemsPerSec = 0;
 
  245         if ($singleJobQueue[
'jq_starttime']) {
 
  246           $itemsPerSec = $this->showJobsDao->getNumItemsPerSec(
 
  247             $singleJobQueue[
'jq_itemsprocessed'], $numSecs);
 
  248           $jobArr[
'jobQueue'][$key][
'itemsPerSec'] = $itemsPerSec;
 
  250         if (empty($singleJobQueue[
'jq_endtime'])) {
 
  251           $jobArr[
'jobQueue'][$key][
'eta'] = $this->showJobsDao->getEstimatedTime(
 
  252             $singleJobQueue[
'jq_job_fk'], $singleJobQueue[
'jq_type'],
 
  253             $itemsPerSec, $jobs[
'job'][
'job_upload_fk']);
 
  254           if ($singleJobQueue[
'jq_type'] === 
'monkbulk' ||
 
  255             $singleJobQueue[
'jq_type'] === 
'deciderjob') {
 
  256             $noOfMonkBulk = $this->showJobsDao->getItemsProcessedForDecider(
 
  257               'decider', $singleJobQueue[
'jq_job_fk']);
 
  258             if (! empty($noOfMonkBulk)) {
 
  259               $totalCountOfMb = $this->clearingDao->getPreviousBulkIds(
 
  263             if (! empty($totalCountOfMb)) {
 
  264               $jobArr[
'jobQueue'][$key][
'isNoOfMonkBulk'] = $noOfMonkBulk[0] .
 
  265                 "/" . $totalCountOfMb;
 
  272         $jobArr[
'jobQueue'][$key][
'isInProgress'] = ($singleJobQueue[
'jq_end_bits'] ==
 
  274         $jobArr[
'jobQueue'][$key][
'isReady'] = ($singleJobQueue[
'jq_end_bits'] ==
 
  278         if ($this->showJobsDao->isJobIdPresentInReportGen($singleJobQueue[
'jq_job_fk'])) {
 
  279           switch ($singleJobQueue[
'jq_type']) {
 
  281               $reportName = 
"ReadMeOss";
 
  284               $reportName = 
"SPDX2 report";
 
  287               $reportName = 
"SPDX2 tag/value report";
 
  290               $reportName = 
"SPDX2 CSV report";
 
  293               $reportName = 
"SPDX3 JSON-LD report";
 
  296               $reportName = 
"SPDX3 JSON report";
 
  299               $reportName = 
"SPDX3 RDF report";
 
  302               $reportName = 
"SPDX3 tag/value report";
 
  305               $reportName = 
"DEP5 copyright file";
 
  308               $reportName = 
"uploaded SPDX2 report";
 
  310             case 'unifiedreport':
 
  311               $reportName = 
"Unified Report";
 
  314               $reportName = 
"Clixml Report";
 
  317               $reportName = 
"CycloneDX json Report";
 
  319             case 'decisionexporter':
 
  320               $reportName = 
"FOSSology Decisions";
 
  324         $jobArr[
'jobQueue'][$key][
'download'] = $reportName;
 
  326       if (! empty($jobs[
'upload'])) {
 
  328           'uploadName' => $jobs[
'upload'][
'upload_filename'],
 
  329           'uploadId' => $jobs[
'upload'][
'upload_pk'],
 
  330           'uploadDesc' => $jobs[
'upload'][
'upload_desc'],
 
  331           'uploadItem' => empty($jobs[
'uploadtree']) ? -1 : $jobs[
'uploadtree'][
'uploadtree_pk'],
 
  332           'uploadEta' => $this->showJobsDao->getEstimatedTime($jobs[
'job'][
'job_pk'], 
'', 0, $jobs[
'upload'][
'upload_pk'])
 
  337       $returnData[] = array(
 
  339         'upload' => $uploadArr,
 
  352     foreach ($job[
'jobqueue'] as $jobqueueRec) {
 
  353       if ($jobqueueRec[
'jq_end_bits'] === 0) {
 
  368     if ($jobqueueRec[
'jq_end_bits'] > 1) {
 
  370     } 
else if (! empty($jobqueueRec[
'jq_starttime']) &&
 
  371       empty($jobqueueRec[
'jq_endtime'])) {
 
  372       return 'jobScheduled';
 
  373     } 
else if (!empty($jobqueueRec[
'jq_starttime']) && !empty($jobqueueRec[
'jq_endtime'])) {
 
  374       return 'jobFinished';
 
  395     if (! empty($jobqueueRec[
'jq_endtext'])) {
 
  396       $status .= 
"$jobqueueRec[jq_endtext]";
 
  399     if (! strstr($status, 
"Success") && ! strstr($status, 
"Fail") &&
 
  400       $jobqueueRec[
"jq_end_bits"]) {
 
  402       if ($jobqueueRec[
"jq_end_bits"] == 0x1) {
 
  403         $status .= _(
"Success");
 
  404       } 
else if ($jobqueueRec[
"jq_end_bits"] == 0x2) {
 
  405         $status .= _(
"Failure");
 
  406       } 
else if ($jobqueueRec[
"jq_end_bits"] == 0x4) {
 
  407         $status .= _(
"Nonfatal");
 
  423     $uri = 
"?mod=showjobs";
 
  424     if (!empty($allusers) && $allusers > 0) {
 
  425       $uri .= 
"&allusers=$allusers";
 
  428       $uri .= 
"&upload=$uploadPk";
 
  431     if (empty($allusers)) {
 
  436       $upload_pks = array($uploadPk);
 
  437       list($jobs, $totalPages) = $this->showJobsDao->uploads2Jobs($upload_pks, $page);
 
  439       list($jobs, $totalPages) = $this->showJobsDao->myJobs($allusers, $page);
 
  441     $jobsInfo = $this->showJobsDao->getJobInfo($jobs);
 
  442     usort($jobsInfo, array($this,
"compareJobsInfo"));
 
  444     $pagination = ($totalPages > 1 ? 
MenuPage($page, $totalPages, $uri) : 
"");
 
  447     return new JsonResponse(
 
  449         'showJobsData' => $showJobData,
 
  450         'pagination' => $pagination
 
  456     if ($this->
State != PLUGIN_STATE_READY) {
 
  459     $output = $this->jsonContent();
 
  460     if (!$this->OutputToStdout) {
 
  466   protected function jsonContent()
 
  472         if (! empty($uploadPk)) {
 
  473           return $this->
getJobs($uploadPk);
 
  476       case "showSingleJob":
 
  483 $NewPlugin = 
new AjaxShowJobs();
 
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
static getGroupId()
Get the current user's group id.
Provide data for jobs table.
isUnfinishedJob($job)
Are there any unfinished jobqueues in this job?
__construct()
base constructor. Most plugins will just use this
getJobs($uploadPk)
get data of all jobs using uploadpk
Output()
This function is called when user output is requested. This function is responsible for content....
getGeekyScanDetailsForJob($job_pk)
Returns geeky scan details about the jobqueue item.
getClass($jobqueueRec)
array $jobqueueRec get the jobqueue row color
compareJobsInfo($JobsInfo1, $JobsInfo2)
Sort compare function to order $JobsInfo by job_pk.
getShowJobsForEachJob($jobData, $forApi=false)
Returns an upload job status in array for API or browser.
OutputOpen()
This function is called when user output is requested. This function is responsible for assigning hea...
jobqueueStatus($jobqueueRec)
Get the status of a jobqueue item If the job isn't known to the scheduler, then report the status bas...
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
fo_dbManager * dbManager
fo_dbManager object
list_t type structure used to keep various lists. (e.g. there are multiple lists).