14 namespace Fossology\Reuser;
22 use Symfony\Component\HttpFoundation\Request;
24 include_once(dirname(__DIR__) .
"/agent/version.php");
39 public function __construct()
41 $this->Name =
"agent_reuser";
42 $this->Title = _(
"Reuse of License Clearing");
43 $this->AgentName =
"reuser";
45 parent::__construct();
47 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
58 return $reuserPlugin->renderContent($vars);
69 return $reuserPlugin->renderFoot($vars);
78 menu_insert(
"ParmAgents::" . $this->Title, 0, $this->Name);
91 $reuseUploadPair = explode(
',',
92 $request->get(self::UPLOAD_TO_REUSE_SELECTOR_NAME), 2);
93 if (count($reuseUploadPair) == 2) {
94 list($reuseUploadId, $reuseGroupId) = $reuseUploadPair;
96 $errorMsg .=
'no reuse upload id given';
101 $getReuseValue = $request->get(
'reuseMode') ?: array();
102 $reuserDependencies = array(
"agent_adj2nest");
104 $reuseMode = UploadDao::REUSE_NONE;
105 foreach ($getReuseValue as $currentReuseValue) {
106 switch ($currentReuseValue) {
108 $reuseMode |= UploadDao::REUSE_MAIN;
110 case 'reuseEnhanced':
111 $reuseMode |= UploadDao::REUSE_ENHANCED;
114 $reuseMode |= UploadDao::REUSE_CONF;
116 case 'reuseCopyright':
117 $reuseMode |= UploadDao::REUSE_COPYRIGHT;
122 list($agentDeps, $scancodeDeps) = $this->getReuserDependencies($request);
123 $reuserDependencies = array_unique(array_merge($reuserDependencies, $agentDeps));
124 if (!empty($scancodeDeps)) {
125 $reuserDependencies[] = $scancodeDeps;
131 return $this->
doAgentAdd($jobId, $uploadId, $errorMsg,
132 $reuserDependencies, $uploadId,
null, $request);
143 protected function createPackageLink($uploadId, $reuseUploadId, $groupId, $reuseGroupId, $reuseMode=0)
146 $packageDao = $GLOBALS[
'container']->get(
'dao.package');
147 $newUpload = $this->uploadDao->getUpload($uploadId);
148 $uploadForReuse = $this->uploadDao->getUpload($reuseUploadId);
150 $package = $packageDao->findPackageForUpload($reuseUploadId);
152 if ($package ===
null) {
154 $package = $packageDao->createPackage($packageName ?: $uploadForReuse->getFilename());
155 $packageDao->addUploadToPackage($reuseUploadId, $package);
158 $packageDao->addUploadToPackage($uploadId, $package);
160 $this->uploadDao->addReusedUpload($uploadId, $reuseUploadId, $groupId, $reuseGroupId, $reuseMode);
168 private function getReuserDependencies($request)
170 $dependencies = array();
172 if ($request->get(
"Check_agent_nomos",
false)) {
173 $dependencies[] =
"agent_nomos";
175 if ($request->get(
"Check_agent_monk",
false)) {
176 $dependencies[] =
"agent_monk";
178 if ($request->get(
"Check_agent_ojo",
false)) {
179 $dependencies[] =
"agent_ojo";
181 if ($request->get(
"Check_agent_ninka",
false)) {
182 $dependencies[] =
"agent_ninka";
184 if ($request->get(
"Check_agent_copyright",
false)) {
185 $dependencies[] =
"agent_copyright";
187 if (!empty($request->get(
"scancodeFlags", []))) {
192 $flags = $request->get(
'scancodeFlags');
193 $unpackArgs = intval($request->get(
'scm', 0)) == 1 ?
'I' :
'';
195 "name" =>
"agent_scancode",
196 "args" => $agentScanCode->getScanCodeArgs($flags, $unpackArgs)
199 return [$dependencies, $scancodeDeps];
203 register_plugin(
new ReuserAgentPlugin());
Contains the constants and helpers for authentication of user.
static getGroupId()
Get the current user's group id.
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null, $request=null)
static getCommonHead($a, $b)
UI element for reuser during Uploading new package.
scheduleAgent($jobId, $uploadId, &$errorMsg, $request)
Get parameters from request and add to job queue.
renderContent(&$vars)
Render twig templates for plugin_reuser.
const UPLOAD_TO_REUSE_SELECTOR_NAME
Form element name for main license to reuse.
createPackageLink($uploadId, $reuseUploadId, $groupId, $reuseGroupId, $reuseMode=0)
Create links between old and new upload.
renderFoot(&$vars)
Render footer twig templates for plugin_reuser.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.