10 define(
"TITLE_MAINTAGENT", _(
"FOSSology Maintenance"));
25 "a"=>
"Run all non slow maintenance operations.",
26 "A"=>
"Run all maintenance operations.",
27 "F"=>
"Validate folder contents.",
28 "g"=>
"Remove orphaned gold files.",
29 "E"=>
"Remove orphaned rows from database.",
30 "L"=>
"Remove orphaned log files from file system.",
31 "N"=>
"Normalize priority ",
34 "R"=>
"Remove uploads with no pfiles.",
35 "t"=>
"Remove expired personal access tokens.",
36 "T"=>
"Remove orphaned temp tables.",
37 "D"=>
"Vacuum Analyze the database.",
39 "Z"=>
"Remove orphaned files from the repository (slow).",
40 "I"=>
"Reindexing of database (This activity may take 5-10 mins. Execute only when system is not in use).",
41 "v"=>
"verbose (turns on debugging output)",
42 "o"=>
"Remove older gold files from repository.",
43 "l"=>
"Remove older log files from repository."
48 $this->Name =
"maintagent";
49 $this->Title = TITLE_MAINTAGENT;
50 $this->MenuList =
"Admin::Maintenance";
54 $this->
dbManager = $container->get(
'db.manager');
56 parent::__construct();
71 foreach ($request[
'options'] as $key => $value) {
75 $retentionPeriod = $SysConf[
'SYSCONFIG'][
'PATMaxPostExpiryRetention'];
76 $options .= $retentionPeriod;
77 } elseif ($key ===
"l") {
78 $options .= $request[
'logsDate'];
81 $options .= $request[
'goldDate'];
87 $user_pk = Auth::getUserId();
88 $groupId = Auth::getGroupId();
90 $job_pk = JobAddJob($user_pk, $groupId,
"Maintenance");
91 if (empty($job_pk) || ($job_pk < 0)) {
return _(
"Failed to insert job record");
94 $jq_pk =
JobQueueAdd($job_pk,
"maintagent", NULL, NULL, NULL, NULL, $options);
95 if (empty($jq_pk)) {
return _(
"Failed to insert task 'Maintenance' into job queue");
100 if (!$success) {
return($error_msg .
"\n" . $output);
103 return _(
"The maintenance job has been queued");
114 $statementName = __METHOD__.
"maintenanceInfo";
115 $row = $this->
dbManager->getSingleRow(
"SELECT jq_endtime FROM jobqueue WHERE jq_type = $1 AND jq_end_bits=$2 ORDER BY jq_endtime DESC LIMIT $2",
116 array(
"maintagent",1), $statementName);
117 if(!empty($row[
'jq_endtime'])){
119 $text = _(
"Last maintenance job was executed on '$dateLastExecuted'");
120 $V.= DisplayMessage($text);
122 $V .=
"<form method='post'>\n";
123 foreach (self::OPTIONS as $option => $description) {
124 $V .=
"<div class='form-group'><div class='form-check'>";
125 $V .=
" <input class='form-check-input' type='checkbox' name='$option' value='$option' id='men$option'>
126 <label class='form-check-label' for='men$option'>$description</label>";
127 if ($option ===
"o") {
128 $V .=
"<input type='date' class='form-control' name='goldDate' value='" . gmdate(
'Y-m-d', strtotime(
"-1 year")) .
"' style='width:auto'>";
130 if ($option ===
"l") {
131 $V .=
"<input type='date' class='form-control' name='logsDate' value='" . gmdate(
'Y-m-d', strtotime(
"-1 year")) .
"' style='width:auto'>";
133 $V .=
"</div></div>\n";
136 $text = _(
"Queue the maintenance agent");
137 $V.=
"<br /><button type='submit' class='btn btn-primary'>$text</button>\n";
140 $V.= _(
"More information about these operations can be found ");
142 $V.=
"<a href=https://github.com/fossology/fossology/wiki/Maintenance-Agent> $text </a></p>";
144 $V.=
"<input type=hidden name=queue value=true>";
163 $Msg = $this->
handle($request);
164 $V .=
"<font style='background-color:#111110'>" . $Msg .
"</font>";
170 public function getOptions() {
171 return $this::OPTIONS;
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
Queue the maintenance agent with the requested parameters.
__construct()
base constructor. Most plugins will just use this
handle($request)
Queue the job.
DisplayForm()
Display the input form.
Output()
This function is called when user output is requested. This function is responsible for content....
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.
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
fo_dbManager * dbManager
fo_dbManager object