76 function __construct()
78 $this->Name =
"export-list";
79 $this->Title = _(
"Export Lists");
80 $this->Dependency = array(
"browse");
84 parent::__construct();
85 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
86 $this->licenseDao = $GLOBALS[
'container']->get(
'dao.license');
87 $this->clearingDao = $GLOBALS[
'container']->get(
'dao.clearing');
88 $this->copyrightDao = $GLOBALS[
'container']->get(
'dao.copyright');
89 $this->treeDao = $GLOBALS[
'container']->get(
'dao.tree');
90 $this->clearingFilter = $GLOBALS[
'container']->get(
'businessrules.clearing_decision_filter');
124 $MenuDisplayString = _(
"Export List");
127 if (empty($Item) || empty($Upload)) {
133 menu_insert(
"Browse::$MenuDisplayString", 1, $URI, $MenuDisplayString);
151 $agents = array_keys(AgentRef::AGENT_LIST);
152 $agent_pks = array();
154 foreach ($agents as $agent) {
157 $AgentRec = AgentARSList($agent.
"_ars", $upload_pk, 1);
158 if ($AgentRec !==
false) {
159 $agent_pks[$agent] = $AgentRec[0][
"agent_fk"];
161 $agent_pks[$agent] =
false;
180 public function createListOfLines($uploadtreeTablename, $uploadtree_pk,
181 $agent_pks, $NomostListNum, $includeSubfolder, $exclude, $ignore)
183 $licensesPerFileName = array();
185 $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadtree_pk,
186 $uploadtreeTablename);
187 $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds,
189 $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisionsForLicenseList($allDecisions);
190 $licensesPerFileName = $this->licenseDao->getLicensesPerFileNameForAgentId($itemTreeBounds,
191 $agent_pks, $includeSubfolder, $exclude, $ignore, $editedMappedLicenses);
195 foreach ($licensesPerFileName as $fileName => $licenseNames) {
196 if ($licenseNames !==
false && count($licenseNames) > 0) {
197 if ($NomostListNum > -1 && ++$currentNum > $NomostListNum) {
198 $lines[
"warn"] = _(
"<br><b>Warning: Only the first $NomostListNum " .
199 "lines are displayed. To see the whole list, run " .
200 "fo_nomos_license_list from the command line.</b><br>");
206 $row[
'filePath'] = $fileName;
207 $row[
'agentFindings'] = $licenseNames[
'scanResults'];
208 $row[
'conclusions'] = null;
209 if (array_key_exists(
'concludedResults', $licenseNames) && !empty($licenseNames[
'concludedResults'])) {
216 if (!$ignore && $licenseNames ===
false) {
218 $row[
'filePath'] = $fileName;
219 $row[
'agentFindings'] = null;
220 $row[
'conclusions'] = null;
233 return "ui-export-list.html.twig";
245 echo _(
"NO DB connection");
248 if ($this->
State != PLUGIN_STATE_READY) {
252 if (empty($uploadtree_pk)) {
257 if (empty($upload_pk)) {
260 if (!$this->uploadDao->isAccessible($upload_pk, Auth::getGroupId())) {
261 $text = _(
"Permission Denied");
262 return "<h2>$text</h2>";
268 if (!empty($exportCopyright) && $exportCopyright ==
"yes") {
269 $exportCopyright =
true;
271 $formVars[
"export_copy"] =
"1";
272 if ($copyrightType ==
"all") {
273 $formVars[
"copy_type_all"] = 1;
275 $formVars[
"copy_type_nolic"] = 1;
278 $exportCopyright =
false;
280 $agent_pks = array();
281 foreach ($agent_pks_dict as $agent_name => $agent_pk) {
282 if ($agent_pk ===
false) {
283 $warnings[] = _(
"No information for agent: $agent_name");
285 $agent_pks[] = $agent_pk;
286 $formVars[
"agentToInclude_".$agent_name] =
"1";
292 if (!(array_key_exists(
'copy_type_all', $formVars) ||
293 array_key_exists(
'copy_type_nolic', $formVars))) {
294 $formVars[
"copy_type_all"] = 1;
298 $formVars[
"dltext"] = $dltext;
300 $NomostListNum = @$SysConf[
'SYSCONFIG'][
'NomostListNum'];
301 $formVars[
"NomostListNum"] = $NomostListNum;
304 $formVars[
"includeSubfolder"] = $includeSubfolder;
307 $formVars[
"showContainers"] = !$ignore;
309 $formVars[
"exclude"] = $exclude;
311 $this->vars = array_merge($this->vars, $formVars);
313 if ($exportCopyright) {
315 $uploadtreeTablename, $NomostListNum, $exclude, $copyrightType);
317 $lines = $this->createListOfLines($uploadtreeTablename, $uploadtree_pk,
318 $agent_pks, $NomostListNum, $includeSubfolder, $exclude, $ignore);
321 $this->vars[
'warnings'] = array();
322 if (array_key_exists(
"warn",$lines)) {
323 $warnings[] = $lines[
"warn"];
324 unset($lines[
"warn"]);
326 foreach ($warnings as $warning) {
327 $this->vars[
'warnings'][] =
"<br><b>$warning</b><br>";
330 $this->vars[
'warnings'][] =
"<br /><b>Result empty</b><br />";
334 return $this->
printCSV($lines, $uploadtreeTablename, $exportCopyright);
336 $this->vars[
'listoutput'] = $this->
printLines($lines, $exportCopyright);
354 public function getCopyrights($uploadId, $uploadtree_pk, $uploadTreeTableName,
355 $NomostListNum, $exclude, $copyrightType =
"all")
357 $agentName =
"copyright";
358 $scanJobProxy =
new ScanJobProxy($GLOBALS[
'container']->
get(
'dao.agent'),
360 $scanJobProxy->createAgentStatus([$agentName]);
361 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
362 if (!array_key_exists($agentName, $selectedScanners)) {
365 $latestAgentId = $selectedScanners[$agentName];
366 $agentFilter =
' AND C.agent_fk='.$latestAgentId;
368 $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadtree_pk,
369 $uploadTreeTableName);
370 $extrawhere =
"UT.lft BETWEEN " . $itemTreeBounds->getLeft() .
" AND " .
371 $itemTreeBounds->getRight();
372 if (! empty($exclude)) {
373 $extrawhere .=
" AND UT.ufile_name NOT LIKE '%$exclude%'";
377 $copyrights = $this->copyrightDao->getScannerEntries($agentName,
378 $uploadTreeTableName, $uploadId, null, $extrawhere . $agentFilter);
380 $uploadTreeTableName,
"content");
382 $copyrights = $this->copyrightDao->getEditedEntries(
'copyright_decision',
383 $uploadTreeTableName, $uploadId, [], $extrawhere);
385 $uploadTreeTableName,
"textfinding");
387 if ($copyrightType !=
"all") {
389 foreach (AgentRef::AGENT_LIST as $agentname => $value) {
390 $AgentRec = AgentARSList($agentname.
"_ars", $uploadId, 1);
391 if (!empty($AgentRec)) {
392 $agentList[] = $AgentRec[0][
"agent_fk"];
410 $uploadTreeTableName, $key)
412 foreach ($newCopyrights as $copyright) {
413 if ($NomostListNum > -1 && count($list) >= $NomostListNum) {
414 $lines[
"warn"] = _(
"<br><b>Warning: Only the first $NomostListNum lines 415 are displayed. To see the whole list, run fo_nomos_license_list from the 416 command line.</b><br>");
420 $row[
"content"] = $copyright[$key];
421 $row[
"filePath"] = $this->treeDao->getFullPath($copyright[
"uploadtree_pk"],
422 $uploadTreeTableName);
423 $list[$row[
"filePath"]][] = $row;
436 $agentList, $exclude)
438 $licensesPerFileName = array();
439 $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds,
441 $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisionsForCopyrightList(
443 $licensesPerFileName = $this->licenseDao->getLicensesPerFileNameForAgentId(
444 $itemTreeBounds, $agentList,
true, $exclude,
true, $editedMappedLicenses);
445 foreach ($licensesPerFileName as $fileName => $licenseNames) {
446 if ($licenseNames !==
false && count($licenseNames) > 0) {
447 if (array_key_exists(
'concludedResults', $licenseNames)) {
449 if (in_array(
"Void", $conclusions)) {
456 if ((! empty($licenseNames[
'scanResults'])) &&
457 ! (in_array(
"No_license_found", $licenseNames[
'scanResults']) ||
458 in_array(
"Void", $licenseNames[
'scanResults']))) {
472 $consolidatedConclusions = array();
473 foreach ($conclusions as $conclusion) {
474 $consolidatedConclusions = array_merge($consolidatedConclusions,
477 return array_unique($consolidatedConclusions);
489 foreach (array_keys($lines) as $file) {
490 if (strpos($file, $key) !==
false) {
491 unset($lines[$file]);
507 foreach ($lines as $row) {
508 $V .= $row[
'filePath'] .
": " . htmlentities($row[
'content']) .
"\n";
511 foreach ($lines as $row) {
512 $V .= $row[
'filePath'];
513 if ($row[
'agentFindings'] !== null) {
514 $V .=
": " . implode(
' ', $row[
'agentFindings']);
515 if ($row[
'conclusions'] !== null) {
516 $V .=
", " . implode(
' ', $row[
'conclusions']);
532 private function printCSV($lines, $uploadtreeTablename, $copyright =
false)
535 $itemId = intval($request->get(
'item'));
536 $path =
Dir2Path($itemId, $uploadtreeTablename);
537 $fileName = $path[count($path) - 1][
'ufile_name'].
"-".date(
"Ymd");
539 $fileName .=
"-copyrights";
541 $fileName .=
"-licenses";
544 $out = fopen(
'php://output',
'w');
547 $head = array(
'file path',
'scan results',
'concluded results');
549 $head = array(
'file path',
'copyright');
551 fputcsv($out, $head, $this->delimiter, $this->enclosure);
552 foreach ($lines as $row) {
554 $newRow[] = $row[
'filePath'];
556 $newRow[] = $row[
'content'];
558 if ($row[
'agentFindings'] !== null) {
559 $newRow[] = implode(
' ', $row[
'agentFindings']);
563 if ($row[
'conclusions'] !== null) {
564 $newRow[] = implode(
' ', $row[
'conclusions']);
569 fputcsv($out, $newRow, $this->delimiter, $this->enclosure);
571 $content = ob_get_contents();
575 'Content-type' =>
'text/csv, charset=UTF-8',
576 'Content-Disposition' =>
'attachment; filename='.$fileName.
'.csv',
577 'Pragma' =>
'no-cache',
578 'Cache-Control' =>
'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0',
579 'Expires' =>
'Expires: Thu, 19 Nov 1981 08:52:00 GMT' 582 return new Response($content, Response::HTTP_OK, $headers);
592 $reducedLines = array();
593 foreach ($lines as $line) {
594 foreach ($line as $copyright) {
595 $reducedLines[] = $copyright;
598 return $reducedLines;
603 $NewPlugin->Initialize();
FUNCTION char * GetUploadtreeTableName(PGconn *pgConn, int upload_pk)
Get the uploadtree table name for this upload_pk If upload_pk does not exist, return "uploadtree"...
printCSV($lines, $uploadtreeTablename, $copyright=false)
getCopyrights($uploadId, $uploadtree_pk, $uploadTreeTableName, $NomostListNum, $exclude, $copyrightType="all")
setEnclosure($enclosure='"')
Dir2Path($uploadtree_pk, $uploadtree_tablename='uploadtree')
Return the path (without artifacts) of an uploadtree_pk.
setDelimiter($delimiter=',')
reduceCopyrightLines($lines)
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
removeCopyrightWithLicense(&$lines, $itemTreeBounds, $agentList, $exclude)
printLines($lines, $copyright=false)
updateCopyrightList(&$list, $newCopyrights, $NomostListNum, $uploadTreeTableName, $key)
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Output()
This function returns the scheduler status.
removeIfKeyExists(&$lines, $key)
getAgentPksFromRequest($upload_pk)
This is the Plugin class. All plugins should:
RegisterMenus()
Customize submenus.
consolidateConclusions($conclusions)
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
Traceback_parm_keep($List)
Create a new URI, keeping only these items.