14 namespace Fossology\Reuser;
22 use Symfony\Component\HttpFoundation\Request;
24 include_once(dirname(__DIR__) .
"/agent/version.php");
40 public function __construct()
42 $this->Name =
"agent_reuser";
43 $this->Title = _(
"Reuse of License Clearing");
44 $this->AgentName =
"reuser";
46 parent::__construct();
48 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
59 return $reuserPlugin->renderContent($vars);
70 return $reuserPlugin->renderFoot($vars);
79 menu_insert(
"ParmAgents::" . $this->Title, 0, $this->Name);
92 $reuseUploadPair = explode(
',',
93 $request->get(self::UPLOAD_TO_REUSE_SELECTOR_NAME), 2);
94 if (count($reuseUploadPair) == 2) {
95 list($reuseUploadId, $reuseGroupId) = $reuseUploadPair;
97 $errorMsg .=
'no reuse upload id given';
102 $getReuseValue = $request->get(self::REUSE_MODE) ?: array();
103 $reuserDependencies = array(
"agent_adj2nest");
105 $reuseMode = UploadDao::REUSE_NONE;
106 foreach ($getReuseValue as $currentReuseValue) {
107 switch ($currentReuseValue) {
109 $reuseMode |= UploadDao::REUSE_MAIN;
111 case 'reuseEnhanced':
112 $reuseMode |= UploadDao::REUSE_ENHANCED;
115 $reuseMode |= UploadDao::REUSE_CONF;
117 case 'reuseCopyright':
118 $reuseMode |= UploadDao::REUSE_COPYRIGHT;
123 list($agentDeps, $scancodeDeps) = $this->getReuserDependencies($request);
124 $reuserDependencies = array_unique(array_merge($reuserDependencies, $agentDeps));
125 if (!empty($scancodeDeps)) {
126 $reuserDependencies[] = $scancodeDeps;
132 return $this->
doAgentAdd($jobId, $uploadId, $errorMsg,
133 $reuserDependencies, $uploadId,
null, $request);
144 protected function createPackageLink($uploadId, $reuseUploadId, $groupId, $reuseGroupId, $reuseMode=0)
147 $packageDao = $GLOBALS[
'container']->get(
'dao.package');
148 $newUpload = $this->uploadDao->getUpload($uploadId);
149 $uploadForReuse = $this->uploadDao->getUpload($reuseUploadId);
151 $package = $packageDao->findPackageForUpload($reuseUploadId);
153 if ($package ===
null) {
155 $package = $packageDao->createPackage($packageName ?: $uploadForReuse->getFilename());
156 $packageDao->addUploadToPackage($reuseUploadId, $package);
159 $packageDao->addUploadToPackage($uploadId, $package);
161 $this->uploadDao->addReusedUpload($uploadId, $reuseUploadId, $groupId, $reuseGroupId, $reuseMode);
169 private function getReuserDependencies($request)
171 $dependencies = array();
173 if ($request->get(
"Check_agent_nomos",
false)) {
174 $dependencies[] =
"agent_nomos";
176 if ($request->get(
"Check_agent_monk",
false)) {
177 $dependencies[] =
"agent_monk";
179 if ($request->get(
"Check_agent_ojo",
false)) {
180 $dependencies[] =
"agent_ojo";
182 if ($request->get(
"Check_agent_ninka",
false)) {
183 $dependencies[] =
"agent_ninka";
185 if ($request->get(
"Check_agent_copyright",
false)) {
186 $dependencies[] =
"agent_copyright";
188 if (!empty($request->get(
"scancodeFlags", []))) {
193 $flags = $request->get(
'scancodeFlags');
194 $unpackArgs = intval($request->get(
'scm', 0)) == 1 ?
'I' :
'';
196 "name" =>
"agent_scancode",
197 "args" => $agentScanCode->getScanCodeArgs($flags, $unpackArgs)
200 return [$dependencies, $scancodeDeps];
204 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 REUSE_MODE
Form element name for main license to reuse.
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.