9 namespace Fossology\Lib\Dao;
25 require_once(dirname(dirname(__FILE__)) .
"/common-dir.php");
31 const REUSE_ENHANCED = 2;
33 const REUSE_CONF = 16;
34 const REUSE_COPYRIGHT = 128;
36 const UNIFIED_REPORT_HEADINGS = array(
37 "assessment" => array(
"Assessment Summary" =>
true),
38 "compliancetasks" => array(
"Required license compliance tasks" =>
true),
39 "acknowledgements" => array(
"Acknowledgements" =>
true),
40 "exportrestrictions" => array(
"Export Restrictions" =>
true),
41 "intellectualProperty" => array(
"Patent Relevant Statements" =>
true),
42 "notes" => array(
"Notes" =>
true),
43 "scanresults" => array(
"Results of License Scan" =>
true),
44 "mainlicenses" => array(
"Main Licenses" =>
true),
45 "redlicense" => array(
"Other OSS Licenses (red) - Do not Use Licenses" =>
true),
46 "yellowlicense" => array(
"Other OSS Licenses (yellow) - additional obligations to common rules (e.g. copyleft)" =>
true),
47 "whitelicense" => array(
"Other OSS Licenses (white) - only common rules" =>
true),
48 "overviewwithwithoutobligations" => array(
"Overview of All Licenses with or without Obligations" =>
true),
49 "copyrights" => array(
"Copyrights" =>
true),
50 "copyrightsuf" => array(
"Copyrights (User Findings)" =>
true),
51 "bulkfindings" => array(
"Bulk Findings" =>
true),
52 "licensenf" => array(
"Non-Functional Licenses" =>
true),
53 "irrelevantfiles" => array(
"Irrelevant Files" =>
true),
54 "dnufiles" => array(
"Do not use Files" =>
true),
55 "changelog" => array(
"Clearing Protocol Change Log" =>
true)
57 const CLIXML_REPORT_HEADINGS = array(
58 "mainlicensesclixml" => array(
"Main Licenses" =>
true),
59 "licensepath" => array(
"License File Path" =>
true),
60 "licensehash" => array(
"License File Hash" =>
true),
61 "copyrightsclixml" => array(
"Copyrights" =>
true),
62 "copyrightpath" => array(
"Copyright File Path" =>
true),
63 "copyrighthash" => array(
"Copyright File Hash" =>
true),
64 "exportrestrictionsclixml" => array(
"Export Restrictions(ECC)" =>
true),
65 "eccpath" => array(
"ECC File Path" =>
true),
66 "ecchash" => array(
"ECC File Hash" =>
true),
67 "intellectualPropertyclixml" => array(
"Identified Patent Relevant Analysis(IPRA)" =>
true),
68 "iprapath" => array(
"IPRA File Path" =>
true),
69 "iprahash" => array(
"IPRA File Hash" =>
true),
70 "allobligations" => array(
"All Obligations" =>
true),
71 "acknowledgementsclixml" => array(
"Acknowledgements" =>
true),
72 "irrelevantfilesclixml" => array(
"Irrelevant Files" =>
true),
73 "dnufilesclixml" => array(
"Do not use Files" =>
true),
74 "notesclixml" => array(
"Additional Notes" =>
true)
81 private $permissionDao;
86 $this->logger = $logger;
87 $this->permissionDao = $uploadPermissionDao;
96 public function getUploadEntry($uploadTreeId, $uploadTreeTableName =
"uploadtree")
98 $stmt = __METHOD__ .
".$uploadTreeTableName";
99 $uploadEntry = $this->
dbManager->getSingleRow(
"SELECT * FROM $uploadTreeTableName WHERE uploadtree_pk = $1",
100 array($uploadTreeId), $stmt);
102 $uploadEntry[
'tablename'] = $uploadTreeTableName;
116 $stmt = __METHOD__ .
".$uploadTreeTableName";
117 $uploadEntry = $this->
dbManager->getSingleRow(
"SELECT uploadtree_pk " .
118 "FROM $uploadTreeTableName " .
119 "WHERE upload_fk = $1 AND pfile_fk = $2",
120 array($uploadFk, $pfileFk), $stmt);
121 return intval($uploadEntry[
'uploadtree_pk']);
131 $row = $this->
dbManager->getSingleRow(
"SELECT * FROM upload WHERE upload_pk = $1",
132 array($uploadId), $stmt);
137 public function getActiveUploadsArray()
140 $queryResult = $this->
dbManager->getRows(
"SELECT * FROM upload where pfile_fk IS NOT NULL",
144 foreach ($queryResult as $row) {
160 $sql =
"SELECT u.* FROM upload u
161 LEFT JOIN perm_upload p ON p.upload_fk = u.upload_pk AND p.group_fk = $1
162 WHERE u.pfile_fk IS NOT NULL
163 AND (p.perm > $permNone OR u.public_perm > $permNone)";
165 $queryResult = $this->
dbManager->getRows($sql, array($groupId), $stmt);
168 foreach ($queryResult as $row) {
182 $uploadEntryData = $this->
getUploadEntry($itemId, $uploadTreeTableName);
205 if ($uploadTreeTableName ===
null) {
209 $stmt = __METHOD__ .
".$uploadTreeTableName";
210 $parameters = array();
211 $uploadCondition = $this->handleUploadIdForTable($uploadTreeTableName, $uploadId, $parameters);
213 $uploadEntryData = $this->
dbManager->getSingleRow(
"SELECT * FROM $uploadTreeTableName
219 return $uploadEntryData ? $this->
createItemTreeBounds($uploadEntryData, $uploadTreeTableName) :
false;
230 $stmt = __METHOD__ .
".$uploadTreeTableName";
231 $parameters = array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight());
232 $uploadCondition = $this->handleUploadIdForTable($uploadTreeTableName, $itemTreeBounds->
getUploadId(), $parameters);
234 $row = $this->
dbManager->getSingleRow(
"SELECT count(*) as count FROM $uploadTreeTableName
235 WHERE lft BETWEEN $1 AND $2
237 AND ((ufile_mode & (3<<28))=0)
240 return intval($row[
"count"]);
243 private function handleUploadIdForTable($uploadTreeTableName, $uploadId, &$parameters)
245 if ($uploadTreeTableName ===
"uploadtree" || $uploadTreeTableName ===
"uploadtree_a") {
246 $parameters[] = $uploadId;
247 return " AND upload_fk = $" . count($parameters) .
" ";
256 public function getStatusTypeMap()
260 $uploadStatus = $container->get(
'upload_status.types');
261 return $uploadStatus->getMap();
273 if ($this->isAccessible($uploadId, $groupId)) {
274 $row = $this->
dbManager->getSingleRow(
"SELECT status_fk " .
275 "FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2;",
276 array($uploadId, $groupId));
277 if (
false === $row) {
280 return $row[
'status_fk'];
282 throw new \Exception(
"permission denied");
296 if ($this->isAccessible($uploadId, $groupId)) {
297 $row = $this->
dbManager->getSingleRow(
"SELECT assignee FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2;",
298 array($uploadId, $groupId));
299 if (
false === $row) {
302 return $row[
'assignee'];
304 throw new \Exception(
"permission denied");
317 $sql =
"SELECT MIN(event_ts) as event_ts FROM upload_events WHERE upload_fk = $1 " .
319 $row = $this->
dbManager->getSingleRow($sql, [$uploadId], __METHOD__);
320 if (empty($row) || empty($row[
"event_ts"])) {
323 return $row[
"event_ts"];
334 $sql =
"SELECT MAX(event_ts) as event_ts FROM upload_events WHERE upload_fk = $1 " .
336 $row = $this->
dbManager->getSingleRow($sql, [$uploadId], __METHOD__);
337 if (empty($row) || empty($row[
"event_ts"])) {
340 return $row[
"event_ts"];
352 return $batch[$uploadId] ?? [
'NA', 0];
362 if (empty($uploadIds)) {
366 $uploadIds = array_unique(array_filter($uploadIds));
367 if (empty($uploadIds)) {
372 foreach ($uploadIds as $id) {
373 $results[(int)$id] = array(
"NA", 0);
376 $uploadIdsStr =
'{' . implode(
',', array_map(
'intval', $uploadIds)) .
'}';
378 $sql =
"SELECT upload_fk, " .
379 "MIN(CASE WHEN event_type = $2 THEN event_ts END) as assignee_ts, " .
380 "MAX(CASE WHEN event_type = $3 THEN event_ts END) as closed_ts " .
381 "FROM upload_events " .
382 "WHERE upload_fk = ANY($1::int[]) AND event_type IN ($2, $3) " .
383 "GROUP BY upload_fk";
387 foreach ($rows as $row) {
388 $id = (int)$row[
'upload_fk'];
392 if (!empty($row[
'assignee_ts']) && !empty($row[
'closed_ts'])) {
394 $assignDate =
new DateTime($row[
'assignee_ts']);
395 $closingDate =
new DateTime($row[
'closed_ts']);
396 if ($assignDate < $closingDate) {
398 $durationSort = $closingDate->getTimestamp() - $assignDate->getTimestamp();
403 $results[$id] = array($duration, $durationSort);
418 if (!empty($uploadId)) {
419 $statementName = __METHOD__;
421 "SELECT uploadtree_tablename FROM upload WHERE upload_pk=$1",
425 if (!empty($row[
'uploadtree_tablename'])) {
426 return $row[
'uploadtree_tablename'];
455 const NOT_FOUND =
null;
468 $originItem = $this->
getUploadEntry($itemId, $uploadTreeTableName);
469 $originLft = $originItem[
'lft'];
471 $options[UploadTreeProxy::OPT_ITEM_FILTER] =
" AND ut.ufile_mode & (3<<28) = 0";
472 $uploadTreeViewName =
'items2care';
474 if ($direction == self::DIR_FWD) {
475 $uploadTreeViewName .=
'fwd';
476 $options[UploadTreeProxy::OPT_ITEM_FILTER] .=
" AND lft>$1";
479 $uploadTreeViewName .=
'bwd';
480 $options[UploadTreeProxy::OPT_ITEM_FILTER] .=
" AND lft<$1";
484 $uploadTreeView =
new UploadTreeProxy($uploadId, $options, $uploadTreeTableName, $uploadTreeViewName);
485 $statementName = __METHOD__ .
".$uploadTreeViewName.";
486 $query = $uploadTreeView->getDbViewQuery().
" ORDER BY lft $order";
488 $newItemRow = $this->
dbManager->getSingleRow(
"$query LIMIT 1", array($originLft), $statementName);
490 return $this->
createItem($newItemRow, $uploadTreeTableName);
492 return self::NOT_FOUND;
504 $statementname = __METHOD__ . $uploadTreeTableName;
506 $parent = $this->
dbManager->getSingleRow(
507 "SELECT uploadtree_pk
508 FROM $uploadTreeTableName
509 WHERE upload_fk=$1 AND parent IS NULL", array($uploadId), $statementname);
510 if (
false === $parent) {
511 throw new \Exception(
"Missing upload tree parent for upload");
513 return $parent[
'uploadtree_pk'];
516 public function getLeftAndRight($uploadtreeID, $uploadTreeTableName =
"uploadtree")
518 $statementName = __METHOD__ . $uploadTreeTableName;
519 $leftRight = $this->
dbManager->getSingleRow(
520 "SELECT lft,rgt FROM $uploadTreeTableName WHERE uploadtree_pk = $1",
521 array($uploadtreeID), $statementName
524 return array($leftRight[
'lft'], $leftRight[
'rgt']);
534 $sql =
"SELECT count(*) FROM " . $uploadTreeView->
getDbViewName() .
" WHERE lft BETWEEN $1 AND $2";
535 $result = $this->
dbManager->getSingleRow($sql
536 , array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight()), __METHOD__ . $uploadTreeView->
asCTE());
537 return $result[
'count'];
546 public function getContainedItems(
ItemTreeBounds $itemTreeBounds, $addCondition =
"", $addParameters = array())
550 $statementName = __METHOD__ .
".$uploadTreeTableName";
552 $view =
new UploadTreeViewProxy($itemTreeBounds, array(UploadTreeViewProxy::CONDITION_PLAIN_FILES));
554 $this->
dbManager->prepare($statementName,
555 $view->asCTE() .
" SELECT * FROM " . $view->getDbViewName() .
" ut ".
556 ($addCondition ?
" WHERE " . $addCondition :
''));
557 $res = $this->
dbManager->execute($statementName, $addParameters);
560 while ($row = $this->
dbManager->fetchArray($res)) {
561 $items[] = $this->
createItem($row, $uploadTreeTableName);
574 public function addReusedUpload($uploadId, $reusedUploadId, $groupId, $reusedGroupId, $reuseMode=0)
576 $this->
dbManager->insertTableRow(
'upload_reuse',
577 array(
'upload_fk'=>$uploadId,
'group_fk'=> $groupId,
'reused_upload_fk'=>$reusedUploadId,
'reused_group_fk'=>$reusedGroupId,
'reuse_mode'=>$reuseMode));
588 $statementName = __METHOD__;
590 $this->
dbManager->prepare($statementName,
591 "SELECT reused_upload_fk, reused_group_fk, reuse_mode FROM upload_reuse WHERE upload_fk = $1 AND group_fk=$2 ORDER BY date_added DESC");
592 $res = $this->
dbManager->execute($statementName, array($uploadId, $groupId));
593 $reusedPairs = $this->
dbManager->fetchAll($res);
603 protected function createItem($uploadEntry, $uploadTreeTableName)
606 intval($uploadEntry[
'uploadtree_pk']),
607 $uploadTreeTableName,
608 intval($uploadEntry[
'upload_fk']),
609 intval($uploadEntry[
'lft']), intval($uploadEntry[
'rgt']));
611 $parent = $uploadEntry[
'parent'];
613 $itemTreeBounds, $parent !==
null ? intval($parent) :
null, intval($uploadEntry[
'pfile_fk']), intval($uploadEntry[
'ufile_mode']), $uploadEntry[
'ufile_name']
625 if ($uploadEntryData ===
false) {
626 throw new Exception(
"did not find uploadTreeId in $uploadTreeTableName");
628 return new ItemTreeBounds(intval($uploadEntryData[
'uploadtree_pk']), $uploadTreeTableName, intval($uploadEntryData[
'upload_fk']), intval($uploadEntryData[
'lft']), intval($uploadEntryData[
'rgt']));
639 $sql =
"SELECT count(*) FROM ".$itemTreeBounds->getUploadTreeTableName().
" ut "
640 .
"WHERE ut.upload_fk=$1";
643 $stmt = __METHOD__.
'.parent';
644 $params[] = $itemTreeBounds->
getItemId();
645 $sql .=
" AND ut.ufile_mode & (1<<28) = 0 AND ut.realparent = $2";
647 $params[] = $itemTreeBounds->
getLeft();
648 $params[] = $itemTreeBounds->
getRight();
649 $sql .=
" AND ut.ufile_mode & (3<<28) = 0 AND (ut.lft BETWEEN $2 AND $3)";
652 $descendants = $this->
dbManager->getSingleRow($sql,$params);
653 return $descendants[
'count'];
657 public function isAccessible($uploadId, $groupId)
659 return $this->permissionDao->isAccessible($uploadId, $groupId);
662 public function isEditable($uploadId, $groupId)
664 return $this->permissionDao->isEditable($uploadId, $groupId);
667 public function makeAccessibleToGroup($uploadId, $groupId, $perm=
null)
669 $this->permissionDao->makeAccessibleToGroup($uploadId, $groupId, $perm);
672 public function makeAccessibleToAllGroupsOf($uploadId, $userId, $perm=
null)
674 $this->permissionDao->makeAccessibleToAllGroupsOf($uploadId, $userId, $perm);
677 public function filterAccessibleUploads(array $uploadIds, $groupId)
679 return $this->permissionDao->filterAccessibleUploads($uploadIds, $groupId);
688 $pfile = $this->
dbManager->getSingleRow(
'SELECT pfile.* FROM upload, pfile WHERE upload_pk=$1 AND pfile_fk=pfile_pk',
689 array($uploadId), __METHOD__);
690 return array(
'sha1'=>$pfile[
'pfile_sha1'],
'md5'=>$pfile[
'pfile_md5'],
'sha256'=>$pfile[
'pfile_sha256']);
701 $sqlChildrenOf =
"SELECT COUNT(*) FROM $uploadtreeTablename s
702 WHERE ufile_mode&(1<<28)=0 and s.upload_fk=$2 AND s.realparent=";
703 $sql=
"WITH RECURSIVE item_path (item_id,num_children,depth,ufile_mode,ufile_name) AS (
704 SELECT uploadtree_pk item_id, ($sqlChildrenOf $1) num_children, 0 depth, ufile_mode, ufile_name
705 FROM $uploadtreeTablename WHERE upload_fk=$2 AND uploadtree_pk=$1
707 SELECT uploadtree_pk item_id, ($sqlChildrenOf ut.uploadtree_pk) num_children,
708 item_path.depth+1 depth, ut.ufile_mode, item_path.ufile_name||'/'||ut.ufile_name ufile_name
709 FROM $uploadtreeTablename ut INNER JOIN item_path ON item_id=ut.realparent
710 WHERE upload_fk=$2 AND ut.ufile_mode&(1<<28)=0 AND num_children<2
712 SELECT * FROM item_path WHERE num_children!=1 OR ufile_mode&(1<<29)=0 ORDER BY depth DESC LIMIT 1";
713 return $this->
dbManager->getSingleRow($sql,array($itemId, $uploadId),__METHOD__.$uploadtreeTablename);
724 $itemRow = $this->
getFatItemArray($itemId,$uploadId,$uploadtreeTablename);
725 return $itemRow[
'item_id'];
735 $statementName = __METHOD__ .
'.' . $uploadTreeTableName;
738 $param[] = $itemTreeBounds->
getLeft();
739 $param[] = $itemTreeBounds->
getRight();
740 $condition =
" lft BETWEEN $1 AND $2";
741 $condition .=
" AND (ufile_mode & (1<<28)) = 0";
743 if (
'uploadtree_a' == $uploadTreeTableName) {
745 $condition .=
" AND upload_fk=$".count($param);
749 SELECT ufile_name, uploadtree_pk, lft, rgt, ufile_mode,
750 pfile_pk, pfile_md5, pfile_sha1, pfile_sha256
751 FROM $uploadTreeTableName
753 ON pfile_fk = pfile_pk
758 $this->
dbManager->prepare($statementName, $sql);
759 $result = $this->
dbManager->execute($statementName, $param);
760 $pfilePerFileName = array();
762 $row = $this->
dbManager->fetchArray($result);
763 $pathStack = array($row[
'ufile_name']);
764 $rgtStack = array($row[
'rgt']);
765 $lastLft = $row[
'lft'];
766 $this->addToPFilePerFileName($pfilePerFileName, $pathStack, $row);
767 while ($row = $this->
dbManager->fetchArray($result)) {
768 if ($row[
'lft'] < $lastLft) {
772 $this->updateStackState($pathStack, $rgtStack, $lastLft, $row);
773 $this->addToPFilePerFileName($pfilePerFileName, $pathStack, $row);
776 return $pfilePerFileName;
779 private function updateStackState(&$pathStack, &$rgtStack, &$lastLft, $row)
781 if ($row[
'lft'] >= $lastLft) {
782 while (count($rgtStack) > 0 && $row[
'lft'] > $rgtStack[count($rgtStack)-1]) {
783 array_pop($pathStack);
784 array_pop($rgtStack);
786 if ($row[
'lft'] > $lastLft) {
787 $pathStack[] = $row[
'ufile_name'];
788 $rgtStack[] = $row[
'rgt'];
789 $lastLft = $row[
'lft'];
794 private function addToPFilePerFileName(&$pfilePerFileName, $pathStack, $row)
796 if (($row[
'ufile_mode'] & (1 << 29)) == 0) {
797 $path = implode(
'/', $pathStack);
798 $pfilePerFileName[$path][
'pfile_pk'] = $row[
'pfile_pk'];
799 $pfilePerFileName[$path][
'uploadtree_pk'] = $row[
'uploadtree_pk'];
800 $pfilePerFileName[$path][
'md5'] = $row[
'pfile_md5'];
801 $pfilePerFileName[$path][
'sha1'] = $row[
'pfile_sha1'];
802 $pfilePerFileName[$path][
'sha256'] = $row[
'pfile_sha256'];
814 $statementName = __METHOD__ .
'.' . $uploadTreeTableName;
817 $param[] = $itemTreeBounds->
getLeft();
818 $param[] = $itemTreeBounds->
getRight();
819 $condition =
" lft BETWEEN $1 AND $2";
820 $condition .=
" AND (ufile_mode & (1<<28)) = 0";
822 if (
'uploadtree_a' == $uploadTreeTableName) {
824 $condition .=
" AND upload_fk=$".count($param);
826 $condition .=
" AND pfile_$hashAlgo IS NOT NULL";
829 SELECT pfile_fk, uploadtree_pk, ufile_mode, pfile_$hashAlgo as hash
830 FROM $uploadTreeTableName
832 ON pfile_fk = pfile_pk
837 $this->
dbManager->prepare($statementName, $sql);
838 $result = $this->
dbManager->execute($statementName, $param);
840 $pfilePerHashAlgo = array();
841 while ($row = $this->
dbManager->fetchArray($result)) {
842 if (($row[
'ufile_mode']&(1<<29)) == 0) {
843 $pfilePerHashAlgo[strtolower($row[
'hash'])][] = array(
'pfile_pk' => $row[
'pfile_fk'],
844 'uploadtree_pk' => $row[
'uploadtree_pk']);
848 return $pfilePerHashAlgo;
855 public function getReportInfo($uploadId)
858 $sql =
"SELECT * FROM report_info WHERE upload_fk = $1";
859 $row = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
863 $stmt = __METHOD__.
'ifempty';
866 $sql =
"INSERT INTO report_info (upload_fk, ri_spdx_selection, ri_cyclonedx_selection) VALUES ($1, $2, $3) RETURNING *";
867 $row = $this->
dbManager->getSingleRow($sql, array($uploadId, $userSPDXDefaults, $userCycloneDxDefaults), $stmt);
880 $stmt = __METHOD__ .
'.getOwner';
881 $sql =
"SELECT user_fk FROM upload WHERE upload_pk = $1";
882 $uploadOwner = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
884 if (empty($uploadOwner)) {
885 return "unchecked,unchecked,unchecked";
888 $userId = $uploadOwner[
'user_fk'];
890 $stmt = __METHOD__ .
'.getUserDefaults';
891 $sql =
"SELECT spdx_settings FROM users WHERE user_pk = $1";
892 $userDefaults = $this->
dbManager->getSingleRow($sql, array($userId), $stmt);
894 if (empty($userDefaults) || empty($userDefaults[
'spdx_settings'])) {
895 return "unchecked,unchecked,unchecked";
898 $settings = explode(
',', $userDefaults[
'spdx_settings']);
899 if (count($settings) < 3) {
900 $settings = array_pad($settings, 3,
'unchecked');
903 $osselotExport = $settings[0];
904 $spdxLicenseComment = $settings[1];
905 $ignoreFilesWOInfo = $settings[2];
907 $result =
"$spdxLicenseComment,$ignoreFilesWOInfo,$osselotExport";
919 $sql =
"SELECT user_fk FROM upload WHERE upload_pk = $1";
920 $owner = $this->
dbManager->getSingleRow($sql, array($uploadId),
921 __METHOD__ .
'.owner');
922 if (empty($owner[
'user_fk'])) {
925 $sql =
"SELECT cyclonedx_settings FROM users WHERE user_pk = $1";
926 $row = $this->
dbManager->getSingleRow($sql, array($owner[
'user_fk']),
927 __METHOD__ .
'.settings');
929 empty($row) ?
null : $row[
'cyclonedx_settings']);
942 $sql =
"SELECT ri_cyclonedx_selection FROM report_info WHERE upload_fk = $1";
943 $row = $this->
dbManager->getSingleRow($sql, array($uploadId), __METHOD__);
944 $settings = empty($row) ? null :
958 if ($column ===
"ri_unifiedcolumns") {
959 $value = json_decode($value,
true);
960 $oldValues = $this->getReportInfo($uploadId)[
"ri_unifiedcolumns"];
961 if (!empty($oldValues)) {
962 $oldValues = json_decode($oldValues,
true);
964 $oldValues = self::UNIFIED_REPORT_HEADINGS;
966 foreach ($value as $key => $val) {
967 $newValText = array_keys($val)[0];
968 $newValValue = array_values($val)[0];
969 $newValValue = ($newValValue ===
true || $newValValue ==
"true") ?
"on" :
null;
970 $oldValues[$key] = [$newValText => $newValValue];
972 $value = json_encode($oldValues);
973 } elseif ($column ===
"ri_excluded_obligations") {
974 $value = json_decode($value,
true);
975 $oldValues = $this->getReportInfo($uploadId)[
"ri_excluded_obligations"];
976 if (!empty($oldValues)) {
977 $oldValues = json_decode($oldValues,
true);
981 foreach ($value as $key => $newValue) {
982 $oldValues[$key] = $newValue;
984 $value = json_encode($oldValues);
985 } elseif ($column ===
"ri_globaldecision") {
986 $value = filter_var($value, FILTER_VALIDATE_BOOL);
987 } elseif ($column ===
"ri_cyclonedx_selection") {
991 $sql =
"UPDATE report_info SET $column = $2 WHERE upload_fk = $1;";
992 $stmt = __METHOD__ .
"updateReportInfo" . $column;
993 $this->
dbManager->getSingleRow($sql, [$uploadId, $value], $stmt);
1007 $changes = is_array($value) ? $value : json_decode((
string) $value,
true);
1008 if (!is_array($changes)) {
1009 throw new \UnexpectedValueException(
"CycloneDX settings must be a JSON object");
1012 foreach ($changes as $key => $newValue) {
1013 if (!array_key_exists($key, $merged)) {
1014 throw new \UnexpectedValueException(
"Unknown CycloneDX setting '$key'");
1016 if (is_bool($merged[$key])) {
1017 $newValue = filter_var($newValue, FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE);
1018 if ($newValue ===
null) {
1019 throw new \UnexpectedValueException(
"CycloneDX setting '$key' must be a boolean");
1022 $merged[$key] = $newValue;
1025 throw new \UnexpectedValueException(
"Invalid CycloneDX tag namespace");
1028 throw new \UnexpectedValueException(
"Unsupported CycloneDX spec version");
1036 public function getGlobalDecisionSettingsFromInfo($uploadId, $setGlobal=
null)
1038 $stmt = __METHOD__ .
'get';
1039 $sql =
"SELECT ri_globaldecision, ri_spdx_selection FROM report_info WHERE upload_fk = $1";
1040 $row = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
1042 if ($setGlobal ===
null) {
1046 $stmt = __METHOD__ .
'ifempty';
1049 $sql =
"INSERT INTO report_info (upload_fk, ri_globaldecision, ri_spdx_selection, ri_cyclonedx_selection) VALUES ($1, $2, $3, $4) RETURNING ri_globaldecision";
1050 $row = $this->
dbManager->getSingleRow($sql, array($uploadId, $setGlobal, $userSPDXDefaults, $userCycloneDxDefaults), $stmt);
1054 if (!empty($setGlobal)) {
1055 $stmt = __METHOD__ .
'update';
1056 $sql =
"UPDATE report_info SET ri_globaldecision = $2 WHERE upload_fk = $1 RETURNING ri_globaldecision";
1057 $row = $this->
dbManager->getSingleRow($sql, array($uploadId, $setGlobal), $stmt);
1060 return $row[
'ri_globaldecision'];
1070 $stmt = __METHOD__.
"getUploadHashesFromPfileId";
1071 $sql =
"SELECT * FROM pfile WHERE pfile_pk = $1";
1072 $row = $this->
dbManager->getSingleRow($sql, array($pfilePk), $stmt);
1074 return [
"sha1" => $row[
"pfile_sha1"],
"md5" => $row[
"pfile_md5"],
"sha256" => $row[
"pfile_sha256"]];
1084 $stmt = __METHOD__ .
".checkReused";
1085 $sql =
"SELECT 1 AS exists FROM report_info WHERE upload_fk = $1 LIMIT 1;";
1086 $row = $this->
dbManager->getSingleRow($sql, array($reusedUploadId), $stmt);
1088 if (empty($row[
'exists'])) {
1094 $stmt = __METHOD__ .
".removeExists";
1095 $sql =
"DELETE FROM report_info WHERE upload_fk = $1;";
1096 $this->
dbManager->getSingleRow($sql, [$uploadId], $stmt);
1098 $stmt = __METHOD__ .
".getAllColumns";
1099 $sql =
"SELECT string_agg(column_name, ',') AS columns
1100 FROM information_schema.columns
1101 WHERE table_name = 'report_info'
1102 AND column_name != 'ri_pk'
1103 AND column_name != 'upload_fk';";
1104 $row = $this->
dbManager->getSingleRow($sql, [], $stmt);
1105 $columns = $row[
'columns'];
1107 $stmt = __METHOD__.
"CopyinsertReportConfReuse";
1109 "INSERT INTO report_info(upload_fk, $columns)
1111 FROM report_info WHERE upload_fk = $2"
1114 $stmt, array($uploadId, $reusedUploadId)
Contains the constants and helpers for authentication of user.
getUploadtreeIdFromPfile($uploadFk, $pfileFk)
getParentItemBounds($uploadId, $uploadTreeTableName=null)
getReusedUpload($uploadId, $groupId)
createItem($uploadEntry, $uploadTreeTableName)
addReusedUpload($uploadId, $reusedUploadId, $groupId, $reusedGroupId, $reuseMode=0)
getUploadHashes($uploadId)
countNonArtifactDescendants(ItemTreeBounds $itemTreeBounds, $isFlat=true)
getClearingDuration(int $uploadId)
createItemTreeBounds($uploadEntryData, $uploadTreeTableName)
getUploadHashesFromPfileId($pfilePk)
Get Pfile hashes from the pfile id.
getCyclonedxSettings($uploadId)
CycloneDX settings of an upload.
getPFileDataPerFileName(ItemTreeBounds $itemTreeBounds)
mergeCyclonedxSettings($uploadId, $value)
Apply a partial CycloneDX settings update to an upload's settings.
getContainingFileCount(ItemTreeBounds $itemTreeBounds, UploadTreeProxy $uploadTreeView)
getFatItemId($itemId, $uploadId, $uploadtreeTablename)
getItemTreeBoundsFromUploadId($uploadTreeId, $uploadId)
getAssigneeDate(int $uploadId)
getPFilesDataPerHashAlgo(ItemTreeBounds $itemTreeBounds, $hashAlgo="sha1")
getUploadParent($uploadId)
getItemByDirection($uploadId, $itemId, $direction, $options)
getClearingDurationsBatch(array $uploadIds)
getFatItemArray($itemId, $uploadId, $uploadtreeTablename)
countPlainFiles(ItemTreeBounds $itemTreeBounds)
getNextItem($uploadId, $itemId, $options=null)
getClosedDate(int $uploadId)
getUserCycloneDxDefaultsForUpload($uploadId)
CycloneDX defaults of the upload owner.
updateReportInfo($uploadId, $column, $value)
Update report info for upload.
getPreviousItem($uploadId, $itemId, $options=null)
getItemTreeBounds($itemId, $uploadTreeTableName="uploadtree")
getUploadtreeTableName($uploadId)
Get the uploadtree table name for this upload_pk If upload_pk does not exist, return "uploadtree".
getAssignee($uploadId, $groupId)
Get the upload assignee id.
getUploadEntry($uploadTreeId, $uploadTreeTableName="uploadtree")
insertReportConfReuse($uploadId, $reusedUploadId)
getAccessibleUploads($groupId)
getUserSPDXDefaultsForUpload($uploadId)
getStatus($uploadId, $groupId)
Get the upload status.
CycloneDX export settings of a user (defaults) or of an upload.
static fromUserSettings(?string $csv)
static normaliseSpecVersion(?string $version)
static fromReportInfo(?string $json)
static normaliseNamespace(?string $namespace)
This class contains the events for the upload_events table.
const UPLOAD_CLOSED_EVENT
static createFromTable($row)
asCTE()
Common Table Expressions.
HumanDuration(DateInterval $duration)
Convert DateInterval to Human readable format.
fo_dbManager * dbManager
fo_dbManager object