9 namespace Fossology\Lib\Dao;
24 require_once(dirname(dirname(__FILE__)) .
"/common-dir.php");
30 const REUSE_ENHANCED = 2;
32 const REUSE_CONF = 16;
33 const REUSE_COPYRIGHT = 128;
35 const UNIFIED_REPORT_HEADINGS = array(
36 "assessment" => array(
"Assessment Summary" =>
true),
37 "compliancetasks" => array(
"Required license compliance tasks" =>
true),
38 "acknowledgements" => array(
"Acknowledgements" =>
true),
39 "exportrestrictions" => array(
"Export Restrictions" =>
true),
40 "intellectualProperty" => array(
"Patent Relevant Statements" =>
true),
41 "notes" => array(
"Notes" =>
true),
42 "scanresults" => array(
"Results of License Scan" =>
true),
43 "mainlicenses" => array(
"Main Licenses" =>
true),
44 "redlicense" => array(
"Other OSS Licenses (red) - Do not Use Licenses" =>
true),
45 "yellowlicense" => array(
"Other OSS Licenses (yellow) - additional obligations to common rules (e.g. copyleft)" =>
true),
46 "whitelicense" => array(
"Other OSS Licenses (white) - only common rules" =>
true),
47 "overviewwithwithoutobligations" => array(
"Overview of All Licenses with or without Obligations" =>
true),
48 "copyrights" => array(
"Copyrights" =>
true),
49 "copyrightsuf" => array(
"Copyrights (User Findings)" =>
true),
50 "bulkfindings" => array(
"Bulk Findings" =>
true),
51 "licensenf" => array(
"Non-Functional Licenses" =>
true),
52 "irrelevantfiles" => array(
"Irrelevant Files" =>
true),
53 "dnufiles" => array(
"Do not use Files" =>
true),
54 "changelog" => array(
"Clearing Protocol Change Log" =>
true)
56 const CLIXML_REPORT_HEADINGS = array(
57 "mainlicensesclixml" => array(
"Main Licenses" =>
true),
58 "licensepath" => array(
"License File Path" =>
true),
59 "licensehash" => array(
"License File Hash" =>
true),
60 "copyrightsclixml" => array(
"Copyrights" =>
true),
61 "copyrightpath" => array(
"Copyright File Path" =>
true),
62 "copyrighthash" => array(
"Copyright File Hash" =>
true),
63 "exportrestrictionsclixml" => array(
"Export Restrictions(ECC)" =>
true),
64 "eccpath" => array(
"ECC File Path" =>
true),
65 "ecchash" => array(
"ECC File Hash" =>
true),
66 "intellectualPropertyclixml" => array(
"Identified Patent Relevant Analysis(IPRA)" =>
true),
67 "iprapath" => array(
"IPRA File Path" =>
true),
68 "iprahash" => array(
"IPRA File Hash" =>
true),
69 "allobligations" => array(
"All Obligations" =>
true),
70 "acknowledgementsclixml" => array(
"Acknowledgements" =>
true),
71 "irrelevantfilesclixml" => array(
"Irrelevant Files" =>
true),
72 "dnufilesclixml" => array(
"Do not use Files" =>
true),
73 "notesclixml" => array(
"Additional Notes" =>
true)
80 private $permissionDao;
85 $this->logger = $logger;
86 $this->permissionDao = $uploadPermissionDao;
95 public function getUploadEntry($uploadTreeId, $uploadTreeTableName =
"uploadtree")
97 $stmt = __METHOD__ .
".$uploadTreeTableName";
98 $uploadEntry = $this->
dbManager->getSingleRow(
"SELECT * FROM $uploadTreeTableName WHERE uploadtree_pk = $1",
99 array($uploadTreeId), $stmt);
101 $uploadEntry[
'tablename'] = $uploadTreeTableName;
115 $stmt = __METHOD__ .
".$uploadTreeTableName";
116 $uploadEntry = $this->
dbManager->getSingleRow(
"SELECT uploadtree_pk " .
117 "FROM $uploadTreeTableName " .
118 "WHERE upload_fk = $1 AND pfile_fk = $2",
119 array($uploadFk, $pfileFk), $stmt);
120 return intval($uploadEntry[
'uploadtree_pk']);
130 $row = $this->
dbManager->getSingleRow(
"SELECT * FROM upload WHERE upload_pk = $1",
131 array($uploadId), $stmt);
136 public function getActiveUploadsArray()
139 $queryResult = $this->
dbManager->getRows(
"SELECT * FROM upload where pfile_fk IS NOT NULL",
143 foreach ($queryResult as $row) {
159 $sql =
"SELECT u.* FROM upload u
160 LEFT JOIN perm_upload p ON p.upload_fk = u.upload_pk AND p.group_fk = $1
161 WHERE u.pfile_fk IS NOT NULL
162 AND (p.perm > $permNone OR u.public_perm > $permNone)";
164 $queryResult = $this->
dbManager->getRows($sql, array($groupId), $stmt);
167 foreach ($queryResult as $row) {
181 $uploadEntryData = $this->
getUploadEntry($itemId, $uploadTreeTableName);
204 if ($uploadTreeTableName ===
null) {
208 $stmt = __METHOD__ .
".$uploadTreeTableName";
209 $parameters = array();
210 $uploadCondition = $this->handleUploadIdForTable($uploadTreeTableName, $uploadId, $parameters);
212 $uploadEntryData = $this->
dbManager->getSingleRow(
"SELECT * FROM $uploadTreeTableName
218 return $uploadEntryData ? $this->
createItemTreeBounds($uploadEntryData, $uploadTreeTableName) :
false;
229 $stmt = __METHOD__ .
".$uploadTreeTableName";
230 $parameters = array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight());
231 $uploadCondition = $this->handleUploadIdForTable($uploadTreeTableName, $itemTreeBounds->
getUploadId(), $parameters);
233 $row = $this->
dbManager->getSingleRow(
"SELECT count(*) as count FROM $uploadTreeTableName
234 WHERE lft BETWEEN $1 AND $2
236 AND ((ufile_mode & (3<<28))=0)
239 return intval($row[
"count"]);
242 private function handleUploadIdForTable($uploadTreeTableName, $uploadId, &$parameters)
244 if ($uploadTreeTableName ===
"uploadtree" || $uploadTreeTableName ===
"uploadtree_a") {
245 $parameters[] = $uploadId;
246 return " AND upload_fk = $" . count($parameters) .
" ";
255 public function getStatusTypeMap()
259 $uploadStatus = $container->get(
'upload_status.types');
260 return $uploadStatus->getMap();
272 if ($this->isAccessible($uploadId, $groupId)) {
273 $row = $this->
dbManager->getSingleRow(
"SELECT status_fk " .
274 "FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2;",
275 array($uploadId, $groupId));
276 if (
false === $row) {
279 return $row[
'status_fk'];
281 throw new \Exception(
"permission denied");
295 if ($this->isAccessible($uploadId, $groupId)) {
296 $row = $this->
dbManager->getSingleRow(
"SELECT assignee FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2;",
297 array($uploadId, $groupId));
298 if (
false === $row) {
301 return $row[
'assignee'];
303 throw new \Exception(
"permission denied");
316 $sql =
"SELECT MIN(event_ts) as event_ts FROM upload_events WHERE upload_fk = $1 " .
318 $row = $this->
dbManager->getSingleRow($sql, [$uploadId], __METHOD__);
319 if (empty($row) || empty($row[
"event_ts"])) {
322 return $row[
"event_ts"];
333 $sql =
"SELECT MAX(event_ts) as event_ts FROM upload_events WHERE upload_fk = $1 " .
335 $row = $this->
dbManager->getSingleRow($sql, [$uploadId], __METHOD__);
336 if (empty($row) || empty($row[
"event_ts"])) {
339 return $row[
"event_ts"];
351 return $batch[$uploadId] ?? [
'NA', 0];
361 if (empty($uploadIds)) {
365 $uploadIds = array_unique(array_filter($uploadIds));
366 if (empty($uploadIds)) {
371 foreach ($uploadIds as $id) {
372 $results[(int)$id] = array(
"NA", 0);
375 $uploadIdsStr =
'{' . implode(
',', array_map(
'intval', $uploadIds)) .
'}';
377 $sql =
"SELECT upload_fk, " .
378 "MIN(CASE WHEN event_type = $2 THEN event_ts END) as assignee_ts, " .
379 "MAX(CASE WHEN event_type = $3 THEN event_ts END) as closed_ts " .
380 "FROM upload_events " .
381 "WHERE upload_fk = ANY($1::int[]) AND event_type IN ($2, $3) " .
382 "GROUP BY upload_fk";
386 foreach ($rows as $row) {
387 $id = (int)$row[
'upload_fk'];
391 if (!empty($row[
'assignee_ts']) && !empty($row[
'closed_ts'])) {
393 $assignDate =
new DateTime($row[
'assignee_ts']);
394 $closingDate =
new DateTime($row[
'closed_ts']);
395 if ($assignDate < $closingDate) {
397 $durationSort = $closingDate->getTimestamp() - $assignDate->getTimestamp();
402 $results[$id] = array($duration, $durationSort);
417 if (!empty($uploadId)) {
418 $statementName = __METHOD__;
420 "SELECT uploadtree_tablename FROM upload WHERE upload_pk=$1",
424 if (!empty($row[
'uploadtree_tablename'])) {
425 return $row[
'uploadtree_tablename'];
454 const NOT_FOUND =
null;
467 $originItem = $this->
getUploadEntry($itemId, $uploadTreeTableName);
468 $originLft = $originItem[
'lft'];
470 $options[UploadTreeProxy::OPT_ITEM_FILTER] =
" AND ut.ufile_mode & (3<<28) = 0";
471 $uploadTreeViewName =
'items2care';
473 if ($direction == self::DIR_FWD) {
474 $uploadTreeViewName .=
'fwd';
475 $options[UploadTreeProxy::OPT_ITEM_FILTER] .=
" AND lft>$1";
478 $uploadTreeViewName .=
'bwd';
479 $options[UploadTreeProxy::OPT_ITEM_FILTER] .=
" AND lft<$1";
483 $uploadTreeView =
new UploadTreeProxy($uploadId, $options, $uploadTreeTableName, $uploadTreeViewName);
484 $statementName = __METHOD__ .
".$uploadTreeViewName.";
485 $query = $uploadTreeView->getDbViewQuery().
" ORDER BY lft $order";
487 $newItemRow = $this->
dbManager->getSingleRow(
"$query LIMIT 1", array($originLft), $statementName);
489 return $this->
createItem($newItemRow, $uploadTreeTableName);
491 return self::NOT_FOUND;
503 $statementname = __METHOD__ . $uploadTreeTableName;
505 $parent = $this->
dbManager->getSingleRow(
506 "SELECT uploadtree_pk
507 FROM $uploadTreeTableName
508 WHERE upload_fk=$1 AND parent IS NULL", array($uploadId), $statementname);
509 if (
false === $parent) {
510 throw new \Exception(
"Missing upload tree parent for upload");
512 return $parent[
'uploadtree_pk'];
515 public function getLeftAndRight($uploadtreeID, $uploadTreeTableName =
"uploadtree")
517 $statementName = __METHOD__ . $uploadTreeTableName;
518 $leftRight = $this->
dbManager->getSingleRow(
519 "SELECT lft,rgt FROM $uploadTreeTableName WHERE uploadtree_pk = $1",
520 array($uploadtreeID), $statementName
523 return array($leftRight[
'lft'], $leftRight[
'rgt']);
533 $sql =
"SELECT count(*) FROM " . $uploadTreeView->
getDbViewName() .
" WHERE lft BETWEEN $1 AND $2";
534 $result = $this->
dbManager->getSingleRow($sql
535 , array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight()), __METHOD__ . $uploadTreeView->
asCTE());
536 return $result[
'count'];
545 public function getContainedItems(
ItemTreeBounds $itemTreeBounds, $addCondition =
"", $addParameters = array())
549 $statementName = __METHOD__ .
".$uploadTreeTableName";
551 $view =
new UploadTreeViewProxy($itemTreeBounds, array(UploadTreeViewProxy::CONDITION_PLAIN_FILES));
553 $this->
dbManager->prepare($statementName,
554 $view->asCTE() .
" SELECT * FROM " . $view->getDbViewName() .
" ut ".
555 ($addCondition ?
" WHERE " . $addCondition :
''));
556 $res = $this->
dbManager->execute($statementName, $addParameters);
559 while ($row = $this->
dbManager->fetchArray($res)) {
560 $items[] = $this->
createItem($row, $uploadTreeTableName);
573 public function addReusedUpload($uploadId, $reusedUploadId, $groupId, $reusedGroupId, $reuseMode=0)
575 $this->
dbManager->insertTableRow(
'upload_reuse',
576 array(
'upload_fk'=>$uploadId,
'group_fk'=> $groupId,
'reused_upload_fk'=>$reusedUploadId,
'reused_group_fk'=>$reusedGroupId,
'reuse_mode'=>$reuseMode));
587 $statementName = __METHOD__;
589 $this->
dbManager->prepare($statementName,
590 "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");
591 $res = $this->
dbManager->execute($statementName, array($uploadId, $groupId));
592 $reusedPairs = $this->
dbManager->fetchAll($res);
602 protected function createItem($uploadEntry, $uploadTreeTableName)
605 intval($uploadEntry[
'uploadtree_pk']),
606 $uploadTreeTableName,
607 intval($uploadEntry[
'upload_fk']),
608 intval($uploadEntry[
'lft']), intval($uploadEntry[
'rgt']));
610 $parent = $uploadEntry[
'parent'];
612 $itemTreeBounds, $parent !==
null ? intval($parent) :
null, intval($uploadEntry[
'pfile_fk']), intval($uploadEntry[
'ufile_mode']), $uploadEntry[
'ufile_name']
624 if ($uploadEntryData ===
false) {
625 throw new Exception(
"did not find uploadTreeId in $uploadTreeTableName");
627 return new ItemTreeBounds(intval($uploadEntryData[
'uploadtree_pk']), $uploadTreeTableName, intval($uploadEntryData[
'upload_fk']), intval($uploadEntryData[
'lft']), intval($uploadEntryData[
'rgt']));
638 $sql =
"SELECT count(*) FROM ".$itemTreeBounds->getUploadTreeTableName().
" ut "
639 .
"WHERE ut.upload_fk=$1";
642 $stmt = __METHOD__.
'.parent';
643 $params[] = $itemTreeBounds->
getItemId();
644 $sql .=
" AND ut.ufile_mode & (1<<28) = 0 AND ut.realparent = $2";
646 $params[] = $itemTreeBounds->
getLeft();
647 $params[] = $itemTreeBounds->
getRight();
648 $sql .=
" AND ut.ufile_mode & (3<<28) = 0 AND (ut.lft BETWEEN $2 AND $3)";
651 $descendants = $this->
dbManager->getSingleRow($sql,$params);
652 return $descendants[
'count'];
656 public function isAccessible($uploadId, $groupId)
658 return $this->permissionDao->isAccessible($uploadId, $groupId);
661 public function isEditable($uploadId, $groupId)
663 return $this->permissionDao->isEditable($uploadId, $groupId);
666 public function makeAccessibleToGroup($uploadId, $groupId, $perm=
null)
668 $this->permissionDao->makeAccessibleToGroup($uploadId, $groupId, $perm);
671 public function makeAccessibleToAllGroupsOf($uploadId, $userId, $perm=
null)
673 $this->permissionDao->makeAccessibleToAllGroupsOf($uploadId, $userId, $perm);
676 public function filterAccessibleUploads(array $uploadIds, $groupId)
678 return $this->permissionDao->filterAccessibleUploads($uploadIds, $groupId);
687 $pfile = $this->
dbManager->getSingleRow(
'SELECT pfile.* FROM upload, pfile WHERE upload_pk=$1 AND pfile_fk=pfile_pk',
688 array($uploadId), __METHOD__);
689 return array(
'sha1'=>$pfile[
'pfile_sha1'],
'md5'=>$pfile[
'pfile_md5'],
'sha256'=>$pfile[
'pfile_sha256']);
700 $sqlChildrenOf =
"SELECT COUNT(*) FROM $uploadtreeTablename s
701 WHERE ufile_mode&(1<<28)=0 and s.upload_fk=$2 AND s.realparent=";
702 $sql=
"WITH RECURSIVE item_path (item_id,num_children,depth,ufile_mode,ufile_name) AS (
703 SELECT uploadtree_pk item_id, ($sqlChildrenOf $1) num_children, 0 depth, ufile_mode, ufile_name
704 FROM $uploadtreeTablename WHERE upload_fk=$2 AND uploadtree_pk=$1
706 SELECT uploadtree_pk item_id, ($sqlChildrenOf ut.uploadtree_pk) num_children,
707 item_path.depth+1 depth, ut.ufile_mode, item_path.ufile_name||'/'||ut.ufile_name ufile_name
708 FROM $uploadtreeTablename ut INNER JOIN item_path ON item_id=ut.realparent
709 WHERE upload_fk=$2 AND ut.ufile_mode&(1<<28)=0 AND num_children<2
711 SELECT * FROM item_path WHERE num_children!=1 OR ufile_mode&(1<<29)=0 ORDER BY depth DESC LIMIT 1";
712 return $this->
dbManager->getSingleRow($sql,array($itemId, $uploadId),__METHOD__.$uploadtreeTablename);
723 $itemRow = $this->
getFatItemArray($itemId,$uploadId,$uploadtreeTablename);
724 return $itemRow[
'item_id'];
734 $statementName = __METHOD__ .
'.' . $uploadTreeTableName;
737 $param[] = $itemTreeBounds->
getLeft();
738 $param[] = $itemTreeBounds->
getRight();
739 $condition =
" lft BETWEEN $1 AND $2";
740 $condition .=
" AND (ufile_mode & (1<<28)) = 0";
742 if (
'uploadtree_a' == $uploadTreeTableName) {
744 $condition .=
" AND upload_fk=$".count($param);
748 SELECT ufile_name, uploadtree_pk, lft, rgt, ufile_mode,
749 pfile_pk, pfile_md5, pfile_sha1, pfile_sha256
750 FROM $uploadTreeTableName
752 ON pfile_fk = pfile_pk
757 $this->
dbManager->prepare($statementName, $sql);
758 $result = $this->
dbManager->execute($statementName, $param);
759 $pfilePerFileName = array();
761 $row = $this->
dbManager->fetchArray($result);
762 $pathStack = array($row[
'ufile_name']);
763 $rgtStack = array($row[
'rgt']);
764 $lastLft = $row[
'lft'];
765 $this->addToPFilePerFileName($pfilePerFileName, $pathStack, $row);
766 while ($row = $this->
dbManager->fetchArray($result)) {
767 if ($row[
'lft'] < $lastLft) {
771 $this->updateStackState($pathStack, $rgtStack, $lastLft, $row);
772 $this->addToPFilePerFileName($pfilePerFileName, $pathStack, $row);
775 return $pfilePerFileName;
778 private function updateStackState(&$pathStack, &$rgtStack, &$lastLft, $row)
780 if ($row[
'lft'] >= $lastLft) {
781 while (count($rgtStack) > 0 && $row[
'lft'] > $rgtStack[count($rgtStack)-1]) {
782 array_pop($pathStack);
783 array_pop($rgtStack);
785 if ($row[
'lft'] > $lastLft) {
786 $pathStack[] = $row[
'ufile_name'];
787 $rgtStack[] = $row[
'rgt'];
788 $lastLft = $row[
'lft'];
793 private function addToPFilePerFileName(&$pfilePerFileName, $pathStack, $row)
795 if (($row[
'ufile_mode'] & (1 << 29)) == 0) {
796 $path = implode(
'/', $pathStack);
797 $pfilePerFileName[$path][
'pfile_pk'] = $row[
'pfile_pk'];
798 $pfilePerFileName[$path][
'uploadtree_pk'] = $row[
'uploadtree_pk'];
799 $pfilePerFileName[$path][
'md5'] = $row[
'pfile_md5'];
800 $pfilePerFileName[$path][
'sha1'] = $row[
'pfile_sha1'];
801 $pfilePerFileName[$path][
'sha256'] = $row[
'pfile_sha256'];
813 $statementName = __METHOD__ .
'.' . $uploadTreeTableName;
816 $param[] = $itemTreeBounds->
getLeft();
817 $param[] = $itemTreeBounds->
getRight();
818 $condition =
" lft BETWEEN $1 AND $2";
819 $condition .=
" AND (ufile_mode & (1<<28)) = 0";
821 if (
'uploadtree_a' == $uploadTreeTableName) {
823 $condition .=
" AND upload_fk=$".count($param);
825 $condition .=
" AND pfile_$hashAlgo IS NOT NULL";
828 SELECT pfile_fk, uploadtree_pk, ufile_mode, pfile_$hashAlgo as hash
829 FROM $uploadTreeTableName
831 ON pfile_fk = pfile_pk
836 $this->
dbManager->prepare($statementName, $sql);
837 $result = $this->
dbManager->execute($statementName, $param);
839 $pfilePerHashAlgo = array();
840 while ($row = $this->
dbManager->fetchArray($result)) {
841 if (($row[
'ufile_mode']&(1<<29)) == 0) {
842 $pfilePerHashAlgo[strtolower($row[
'hash'])][] = array(
'pfile_pk' => $row[
'pfile_fk'],
843 'uploadtree_pk' => $row[
'uploadtree_pk']);
847 return $pfilePerHashAlgo;
854 public function getReportInfo($uploadId)
857 $sql =
"SELECT * FROM report_info WHERE upload_fk = $1";
858 $row = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
862 $stmt = __METHOD__.
'ifempty';
863 $sql =
"INSERT INTO report_info (upload_fk) VALUES ($1) RETURNING *";
864 $row = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
877 $stmt = __METHOD__ .
'.getOwner';
878 $sql =
"SELECT user_fk FROM upload WHERE upload_pk = $1";
879 $uploadOwner = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
881 if (empty($uploadOwner)) {
882 return "unchecked,unchecked,unchecked";
885 $userId = $uploadOwner[
'user_fk'];
887 $stmt = __METHOD__ .
'.getUserDefaults';
888 $sql =
"SELECT spdx_settings FROM users WHERE user_pk = $1";
889 $userDefaults = $this->
dbManager->getSingleRow($sql, array($userId), $stmt);
891 if (empty($userDefaults) || empty($userDefaults[
'spdx_settings'])) {
892 return "unchecked,unchecked,unchecked";
895 $settings = explode(
',', $userDefaults[
'spdx_settings']);
896 if (count($settings) < 3) {
897 $settings = array_pad($settings, 3,
'unchecked');
900 $osselotExport = $settings[0];
901 $spdxLicenseComment = $settings[1];
902 $ignoreFilesWOInfo = $settings[2];
904 $result =
"$spdxLicenseComment,$ignoreFilesWOInfo,$osselotExport";
916 $stmt = __METHOD__ .
'.getOwner';
917 $sql =
"SELECT user_fk FROM upload WHERE upload_pk = $1";
918 $uploadOwner = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
920 if (empty($uploadOwner)) {
921 return "unchecked,unchecked,unchecked";
924 $userId = $uploadOwner[
'user_fk'];
926 $stmt = __METHOD__ .
'.getUserDefaults';
927 $sql =
"SELECT cyclonedx_settings FROM users WHERE user_pk = $1";
928 $userDefaults = $this->
dbManager->getSingleRow($sql, array($userId), $stmt);
930 if (empty($userDefaults) || empty($userDefaults[
'cyclonedx_settings'])) {
931 return "unchecked,unchecked,unchecked";
934 $settings = explode(
',', $userDefaults[
'cyclonedx_settings']);
935 if (count($settings) < 3) {
936 $settings = array_pad($settings, 3,
'unchecked');
939 $osselotExport = $settings[0];
940 $cyclonedxLicenseComment = $settings[1];
941 $ignoreFilesWOInfo = $settings[2];
943 $result =
"$cyclonedxLicenseComment,$ignoreFilesWOInfo,$osselotExport";
957 if ($column ===
"ri_unifiedcolumns") {
958 $value = json_decode($value,
true);
959 $oldValues = $this->getReportInfo($uploadId)[
"ri_unifiedcolumns"];
960 if (!empty($oldValues)) {
961 $oldValues = json_decode($oldValues,
true);
963 $oldValues = self::UNIFIED_REPORT_HEADINGS;
965 foreach ($value as $key => $val) {
966 $newValText = array_keys($val)[0];
967 $newValValue = array_values($val)[0];
968 $newValValue = ($newValValue ===
true || $newValValue ==
"true") ?
"on" :
null;
969 $oldValues[$key] = [$newValText => $newValValue];
971 $value = json_encode($oldValues);
972 } elseif ($column ===
"ri_excluded_obligations") {
973 $value = json_decode($value,
true);
974 $oldValues = $this->getReportInfo($uploadId)[
"ri_excluded_obligations"];
975 if (!empty($oldValues)) {
976 $oldValues = json_decode($oldValues,
true);
980 foreach ($value as $key => $newValue) {
981 $oldValues[$key] = $newValue;
983 $value = json_encode($oldValues);
984 } elseif ($column ===
"ri_globaldecision") {
985 $value = filter_var($value, FILTER_VALIDATE_BOOL);
988 $sql =
"UPDATE report_info SET $column = $2 WHERE upload_fk = $1;";
989 $stmt = __METHOD__ .
"updateReportInfo" . $column;
990 $this->
dbManager->getSingleRow($sql, [$uploadId, $value], $stmt);
997 public function getGlobalDecisionSettingsFromInfo($uploadId, $setGlobal=
null)
999 $stmt = __METHOD__ .
'get';
1000 $sql =
"SELECT ri_globaldecision, ri_spdx_selection FROM report_info WHERE upload_fk = $1";
1001 $row = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
1003 if ($setGlobal ===
null) {
1007 $stmt = __METHOD__ .
'ifempty';
1009 $sql =
"INSERT INTO report_info (upload_fk, ri_globaldecision, ri_spdx_selection) VALUES ($1, $2, $3) RETURNING ri_globaldecision";
1010 $row = $this->
dbManager->getSingleRow($sql, array($uploadId, $setGlobal, $userSPDXDefaults), $stmt);
1014 if (!empty($setGlobal)) {
1015 $stmt = __METHOD__ .
'update';
1016 $sql =
"UPDATE report_info SET ri_globaldecision = $2 WHERE upload_fk = $1 RETURNING ri_globaldecision";
1017 $row = $this->
dbManager->getSingleRow($sql, array($uploadId, $setGlobal), $stmt);
1020 return $row[
'ri_globaldecision'];
1030 $stmt = __METHOD__.
"getUploadHashesFromPfileId";
1031 $sql =
"SELECT * FROM pfile WHERE pfile_pk = $1";
1032 $row = $this->
dbManager->getSingleRow($sql, array($pfilePk), $stmt);
1034 return [
"sha1" => $row[
"pfile_sha1"],
"md5" => $row[
"pfile_md5"],
"sha256" => $row[
"pfile_sha256"]];
1044 $stmt = __METHOD__ .
".checkReused";
1045 $sql =
"SELECT 1 AS exists FROM report_info WHERE upload_fk = $1 LIMIT 1;";
1046 $row = $this->
dbManager->getSingleRow($sql, array($reusedUploadId), $stmt);
1048 if (empty($row[
'exists'])) {
1054 $stmt = __METHOD__ .
".removeExists";
1055 $sql =
"DELETE FROM report_info WHERE upload_fk = $1;";
1056 $this->
dbManager->getSingleRow($sql, [$uploadId], $stmt);
1058 $stmt = __METHOD__ .
".getAllColumns";
1059 $sql =
"SELECT string_agg(column_name, ',') AS columns
1060 FROM information_schema.columns
1061 WHERE table_name = 'report_info'
1062 AND column_name != 'ri_pk'
1063 AND column_name != 'upload_fk';";
1064 $row = $this->
dbManager->getSingleRow($sql, [], $stmt);
1065 $columns = $row[
'columns'];
1067 $stmt = __METHOD__.
"CopyinsertReportConfReuse";
1069 "INSERT INTO report_info(upload_fk, $columns)
1071 FROM report_info WHERE upload_fk = $2"
1074 $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)
Get cyclone dx settings for a user.
getPFileDataPerFileName(ItemTreeBounds $itemTreeBounds)
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)
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.
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