FOSSology  4.4.0
Open Source License Compliance by Open Source Software
DetectLicensesFolder.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2022 Rohit Pandey <rohit.pandey4900@gmail.com>
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
13 
19 {
21  private $uploadDao;
22 
24  private $searchHelperDao;
25 
26  function __construct()
27  {
28  $this->uploadDao = $GLOBALS['container']->get('dao.upload');
29  $this->searchHelperDao = $GLOBALS['container']->get('dao.searchhelperdao');
30  }
31 
37  function getDeclearedLicenses($uploadId)
38  {
39  $uploadTreeId = $this->uploadDao->getUploadParent($uploadId);
40 
41  // Search the upload tree for LICENSES directory
42  $Item = $uploadTreeId;
43  $Filename = "LICENSES";
44  $tag = "";
45  $Page = 0;
46  $Limit = 100;
47  $SizeMin = "";
48  $SizeMax = "";
49  $searchtype = "containers";
50  $License = "";
51  $Copyright = "";
52 
53  list($result, $count) = $this->searchHelperDao->GetResults($Item, $Filename, $uploadId, $tag, $Page, $Limit, $SizeMin, $SizeMax, $searchtype, $License, $Copyright, $this->uploadDao, Auth::getGroupId());
54 
55  if ($count==0) {
56  return array();
57  }
58  $itemTreeBounds = $this->uploadDao->getItemTreeBounds($result[0]['uploadtree_pk']);
59  $condition = "(ut.lft BETWEEN $1 AND $2)";
60  $params = array($itemTreeBounds->getLeft(), $itemTreeBounds->getRight());
61  $licenseId = array();
62  $containedItems = $this->uploadDao->getContainedItems($itemTreeBounds, $condition, $params);
63  foreach ($containedItems as $item) {
64  $licenseId[] = $this->cleanLicenseId($item->getFileName());
65  }
66 
67  return $licenseId;
68  }
69 
75  public function cleanLicenseId($licenseFileName)
76  {
77  return preg_replace("/(.*)\\.txt$/i", "$1", $licenseFileName);
78  }
79 }
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
static getGroupId()
Get the current user's group id.
Definition: Auth.php:80
Detects licenses declard inside LICENSES directory.
getDeclearedLicenses($uploadId)
Get licenses decleared in LICENSES folder.
cleanLicenseId($licenseFileName)
Truncate .txt from licenseFileName.
Contains business rules for FOSSology.