FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
SoftwareHeritageDao.php
1 <?php
2 /*
3  Copyright (C) 2019
4  Author: Sandip Kumar Bhuyan<sandipbhuyan@gmail.com>
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 namespace Fossology\Lib\Dao;
21 
23 use Monolog\Logger;
24 
30 {
31 
32  const SWH_STATUS_OK = 200;
33  const SWH_BAD_REQUEST = 400;
34  const SWH_NOT_FOUND = 404;
35  const SWH_RATELIMIT_EXCEED = 429;
36 
38  private $dbManager;
40  private $logger;
42  private $uploadDao;
43 
44  public function __construct(DbManager $dbManager, Logger $logger,UploadDao $uploadDao)
45  {
46  $this->dbManager = $dbManager;
47  $this->logger = $logger;
48  $this->uploadDao = $uploadDao;
49  }
50 
56  public function getSoftwareHeritagePfileFk($uploadId)
57  {
58  $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
59  $stmt = __METHOD__.$uploadTreeTableName;
60  $sql = "SELECT DISTINCT(SWH.pfile_fk) FROM $uploadTreeTableName UT
61  INNER JOIN software_heritage SWH ON SWH.pfile_fk = UT.pfile_fk
62  WHERE UT.upload_fk = $1";
63  return $this->dbManager->getRows($sql,array($uploadId),$stmt);
64  }
65 
66 
73  public function setSoftwareHeritageDetails($pfileId, $licenseDetails, $status)
74  {
75  if (!empty($this->dbManager->insertTableRow('software_heritage',['pfile_fk' => $pfileId, 'swh_shortnames' => $licenseDetails, 'swh_status' => $status]))) {
76  return true;
77  }
78  return false;
79  }
80 
86  public function getSoftwareHetiageRecord($pfileId)
87  {
88  $stmt = __METHOD__."getSoftwareHeritageRecord";
89  $row = $this->dbManager->getSingleRow("SELECT swh_shortnames, swh_status FROM software_heritage WHERE pfile_fk = $1",
90  array($pfileId), $stmt);
91  $img = '<img alt="done" src="images/red.png" class="icon-small"/>';
92  if (self::SWH_STATUS_OK == $row['swh_status']) {
93  $img = '<img alt="done" src="images/green.png" class="icon-small"/>';
94  }
95  return ["license" => $row['swh_shortnames'], "img" => $img];
96 
97  }
98 }
setSoftwareHeritageDetails($pfileId, $licenseDetails, $status)
Store a record of Software Heritage license info in table.
getSoftwareHetiageRecord($pfileId)
Get a record from Software Heritage schema from the PfileId.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
getSoftwareHeritagePfileFk($uploadId)
Get all the pfile_fk stored in software heritage table.