FOSSology  4.4.0
Open Source License Compliance by Open Source Software
FoDecisionImporter.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2022 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
15 namespace Fossology\DecisionImporter\UI;
16 
18 use Symfony\Component\HttpFoundation\File\UploadedFile;
19 use Symfony\Component\HttpFoundation\Request;
20 use UnexpectedValueException;
21 
28 {
29  const NAME = 'agent_fodecisionimporter';
30 
31  private const KEYS = [
32  'userselect'
33  ];
34 
35  public function __construct()
36  {
37  $this->Name = self::NAME;
38  $this->Title = _("FOSSology Dump Importer");
39  $this->AgentName = "decisionimporter";
40 
41  parent::__construct();
42  }
43 
48  function preInstall()
49  {
50  // no AgentCheckBox
51  }
52 
58  public function setAdditionalJqCmdArgs(Request $request): string
59  {
60  $additionalJqCmdArgs = "";
61 
62  foreach (self::KEYS as $key) {
63  if ($request->get($key) !== NULL) {
64  $additionalJqCmdArgs .= " --" . $key . "=" . $request->get($key);
65  }
66  }
67 
68  return $additionalJqCmdArgs;
69  }
70 
77  public function addReport(UploadedFile $report): string
78  {
79  if ($report->isValid()) {
80  if (!$report->isFile()) {
81  throw new UnexpectedValueException('Uploaded tmpfile not found');
82  }
83 
84  global $SysConf;
85  $fileBase = $SysConf['FOSSOLOGY']['path'] . "/DecisionImport/";
86  if (!is_dir($fileBase)) {
87  mkdir($fileBase, 0755, true);
88  }
89  $targetFile = time() . '_' . rand() . '_' . $report->getClientOriginalName();
90  $movedFile = $report->move($fileBase, $targetFile);
91  if ($movedFile->isFile()) {
92  return '--report=' . $movedFile->getFilename();
93  }
94  }
95  return '';
96  }
97 }
98 
99 register_plugin(new FoDecisionImporter());
const KEYS
Additional keys used by agent.