9 namespace Fossology\Lib\Dao;
22 const SWH_STATUS_OK = 200;
23 const SWH_BAD_REQUEST = 400;
24 const SWH_NOT_FOUND = 404;
25 const SWH_RATELIMIT_EXCEED = 429;
37 $this->logger = $logger;
38 $this->uploadDao = $uploadDao;
48 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
49 $stmt = __METHOD__.$uploadTreeTableName;
50 $sql =
"SELECT DISTINCT(SWH.pfile_fk) FROM $uploadTreeTableName UT
51 INNER JOIN software_heritage SWH ON SWH.pfile_fk = UT.pfile_fk
52 WHERE UT.upload_fk = $1";
53 return $this->
dbManager->getRows($sql,array($uploadId),$stmt);
65 if (!empty($this->
dbManager->insertTableRow(
'software_heritage',[
'pfile_fk' => $pfileId,
'swh_shortnames' => $licenseDetails,
'swh_status' => $status]))) {
78 $stmt = __METHOD__ .
"getSoftwareHeritageRecord";
80 "SELECT swh_shortnames, swh_status FROM software_heritage WHERE pfile_fk = $1",
81 array($pfileId), $stmt);
85 'swh_shortnames' => null
88 $img =
'<img alt="done" src="images/red.png" class="icon-small"/>';
89 if (self::SWH_STATUS_OK == $row[
'swh_status']) {
90 $img =
'<img alt="done" src="images/green.png" class="icon-small"/>';
92 return [
"license" => $row[
'swh_shortnames'],
"img" => $img];
104 $left = $itemTreeBounds->
getLeft();
105 $right = $itemTreeBounds->
getRight();
107 $stmt = __METHOD__ . $uploadTreeTableName;
109 COUNT(*) AS total_files,
110 COUNT(SWH.pfile_fk) AS checked_files,
111 SUM(CASE WHEN SWH.swh_status = $1 THEN 1 ELSE 0 END) AS ok_files
112 FROM $uploadTreeTableName UT
113 LEFT JOIN software_heritage SWH ON SWH.pfile_fk = UT.pfile_fk
114 WHERE UT.upload_fk = $2
115 AND UT.lft BETWEEN $3 AND $4
116 AND UT.ufile_mode & (1<<29) = 0";
118 $row = $this->
dbManager->getSingleRow($sql, array(self::SWH_STATUS_OK, $uploadId, $left, $right), $stmt);
120 $totalFiles = intval($row[
'total_files']);
121 $checkedFiles = intval($row[
'checked_files']);
122 $okFiles = intval($row[
'ok_files']);
124 if ($totalFiles == 0) {
125 return [
"license" =>
null,
"img" =>
""];
129 if ($checkedFiles > 0) {
130 $licenseStmt = __METHOD__ .
'licenses' . $uploadTreeTableName;
131 $licenseSql =
"SELECT DISTINCT SWH.swh_shortnames
132 FROM $uploadTreeTableName UT
133 INNER JOIN software_heritage SWH ON SWH.pfile_fk = UT.pfile_fk
134 WHERE UT.upload_fk = $1
135 AND UT.lft BETWEEN $2 AND $3
136 AND UT.ufile_mode & (1<<29) = 0
137 AND SWH.swh_shortnames IS NOT NULL
138 AND SWH.swh_shortnames != ''";
139 $licenseRows = $this->
dbManager->getRows($licenseSql, array($uploadId, $left, $right), $licenseStmt);
140 foreach ($licenseRows as $licenseRow) {
141 $parts = explode(
',', $licenseRow[
'swh_shortnames']);
142 foreach ($parts as $part) {
143 $trimmed =
trim($part);
144 if (!empty($trimmed)) {
145 $licenseNames[$trimmed] =
true;
151 if ($checkedFiles == 0) {
154 "img" =>
'<img alt="pending" src="images/grey.png" class="icon-small"/>'
158 if ($okFiles == $totalFiles) {
159 $img =
'<img alt="done" src="images/green.png" class="icon-small"/>';
161 $img =
'<img alt="needs-attention" src="images/red.png" class="icon-small"/>';
164 $licenseStr = !empty($licenseNames) ? implode(
', ', array_keys($licenseNames)) :
null;
165 return [
"license" => $licenseStr,
"img" => $img];
getAggregatedSWHRecord(ItemTreeBounds $itemTreeBounds)
Get aggregated SWH status for all files under a folder.
getSoftwareHetiageRecord($pfileId)
Get a record from Software Heritage schema from the PfileId.
getSoftwareHeritagePfileFk($uploadId)
Get all the pfile_fk stored in software heritage table.
setSoftwareHeritageDetails($pfileId, $licenseDetails, $status)
Store a record of Software Heritage license info in table.
char * trim(char *ptext)
Trimming whitespace.
fo_dbManager * dbManager
fo_dbManager object