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;
34 const UNIFIED_REPORT_HEADINGS = array(
35 "assessment" => array(
"Assessment Summary" =>
true),
36 "compliancetasks" => array(
"Required license compliance tasks" =>
true),
37 "acknowledgements" => array(
"Acknowledgements" =>
true),
38 "exportrestrictions" => array(
"Export Restrictions" =>
true),
39 "intellectualProperty" => array(
"Patent Relevant Statements" =>
true),
40 "notes" => array(
"Notes" =>
true),
41 "scanresults" => array(
"Results of License Scan" =>
true),
42 "mainlicenses" => array(
"Main Licenses" =>
true),
43 "redlicense" => array(
"Other OSS Licenses (red) - Do not Use Licenses" =>
true),
44 "yellowlicense" => array(
"Other OSS Licenses (yellow) - additional obligations to common rules (e.g. copyleft)" =>
true),
45 "whitelicense" => array(
"Other OSS Licenses (white) - only common rules" =>
true),
46 "overviewwithwithoutobligations" => array(
"Overview of All Licenses with or without Obligations" =>
true),
47 "copyrights" => array(
"Copyrights" =>
true),
48 "copyrightsuf" => array(
"Copyrights (User Findings)" =>
true),
49 "bulkfindings" => array(
"Bulk Findings" =>
true),
50 "licensenf" => array(
"Non-Functional Licenses" =>
true),
51 "irrelevantfiles" => array(
"Irrelevant Files" =>
true),
52 "dnufiles" => array(
"Do not use Files" =>
true),
53 "changelog" => array(
"Clearing Protocol Change Log" =>
true)
55 const CLIXML_REPORT_HEADINGS = array(
56 "mainlicensesclixml" => array(
"Main Licenses" =>
true),
57 "licensepath" => array(
"License File Path" =>
true),
58 "licensehash" => array(
"License File Hash" =>
true),
59 "copyrightsclixml" => array(
"Copyrights" =>
true),
60 "copyrightpath" => array(
"Copyright File Path" =>
true),
61 "copyrighthash" => array(
"Copyright File Hash" =>
true),
62 "exportrestrictionsclixml" => array(
"Export Restrictions(ECC)" =>
true),
63 "eccpath" => array(
"ECC File Path" =>
true),
64 "ecchash" => array(
"ECC File Hash" =>
true),
65 "intellectualPropertyclixml" => array(
"Identified Patent Relevant Analysis(IPRA)" =>
true),
66 "iprapath" => array(
"IPRA File Path" =>
true),
67 "iprahash" => array(
"IPRA File Hash" =>
true),
68 "allobligations" => array(
"All Obligations" =>
true),
69 "acknowledgementsclixml" => array(
"Acknowledgements" =>
true),
70 "irrelevantfilesclixml" => array(
"Irrelevant Files" =>
true),
71 "dnufilesclixml" => array(
"Do not use Files" =>
true),
72 "notesclixml" => array(
"Additional Notes" =>
true)
79 private $permissionDao;
84 $this->logger = $logger;
85 $this->permissionDao = $uploadPermissionDao;
94 public function getUploadEntry($uploadTreeId, $uploadTreeTableName =
"uploadtree")
96 $stmt = __METHOD__ .
".$uploadTreeTableName";
97 $uploadEntry = $this->
dbManager->getSingleRow(
"SELECT * FROM $uploadTreeTableName WHERE uploadtree_pk = $1",
98 array($uploadTreeId), $stmt);
100 $uploadEntry[
'tablename'] = $uploadTreeTableName;
114 $stmt = __METHOD__ .
".$uploadTreeTableName";
115 $uploadEntry = $this->
dbManager->getSingleRow(
"SELECT uploadtree_pk " .
116 "FROM $uploadTreeTableName " .
117 "WHERE upload_fk = $1 AND pfile_fk = $2",
118 array($uploadFk, $pfileFk), $stmt);
119 return intval($uploadEntry[
'uploadtree_pk']);
129 $row = $this->
dbManager->getSingleRow(
"SELECT * FROM upload WHERE upload_pk = $1",
130 array($uploadId), $stmt);
135 public function getActiveUploadsArray()
138 $queryResult = $this->
dbManager->getRows(
"SELECT * FROM upload where pfile_fk IS NOT NULL",
142 foreach ($queryResult as $row) {
158 $sql =
"SELECT u.* FROM upload u
159 LEFT JOIN perm_upload p ON p.upload_fk = u.upload_pk AND p.group_fk = $1
160 WHERE u.pfile_fk IS NOT NULL
161 AND (p.perm > $permNone OR u.public_perm > $permNone)";
163 $queryResult = $this->
dbManager->getRows($sql, array($groupId), $stmt);
166 foreach ($queryResult as $row) {
180 $uploadEntryData = $this->
getUploadEntry($itemId, $uploadTreeTableName);
203 if ($uploadTreeTableName ===
null) {
207 $stmt = __METHOD__ .
".$uploadTreeTableName";
208 $parameters = array();
209 $uploadCondition = $this->handleUploadIdForTable($uploadTreeTableName, $uploadId, $parameters);
211 $uploadEntryData = $this->
dbManager->getSingleRow(
"SELECT * FROM $uploadTreeTableName
217 return $uploadEntryData ? $this->
createItemTreeBounds($uploadEntryData, $uploadTreeTableName) :
false;
228 $stmt = __METHOD__ .
".$uploadTreeTableName";
229 $parameters = array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight());
230 $uploadCondition = $this->handleUploadIdForTable($uploadTreeTableName, $itemTreeBounds->
getUploadId(), $parameters);
232 $row = $this->
dbManager->getSingleRow(
"SELECT count(*) as count FROM $uploadTreeTableName
233 WHERE lft BETWEEN $1 AND $2
235 AND ((ufile_mode & (3<<28))=0)
238 return intval($row[
"count"]);
241 private function handleUploadIdForTable($uploadTreeTableName, $uploadId, &$parameters)
243 if ($uploadTreeTableName ===
"uploadtree" || $uploadTreeTableName ===
"uploadtree_a") {
244 $parameters[] = $uploadId;
245 return " AND upload_fk = $" . count($parameters) .
" ";
254 public function getStatusTypeMap()
258 $uploadStatus = $container->get(
'upload_status.types');
259 return $uploadStatus->getMap();
271 if ($this->isAccessible($uploadId, $groupId)) {
272 $row = $this->
dbManager->getSingleRow(
"SELECT status_fk " .
273 "FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2;",
274 array($uploadId, $groupId));
275 if (
false === $row) {
278 return $row[
'status_fk'];
280 throw new \Exception(
"permission denied");
294 if ($this->isAccessible($uploadId, $groupId)) {
295 $row = $this->
dbManager->getSingleRow(
"SELECT assignee FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2;",
296 array($uploadId, $groupId));
297 if (
false === $row) {
300 return $row[
'assignee'];
302 throw new \Exception(
"permission denied");
315 $sql =
"SELECT MIN(event_ts) as event_ts FROM upload_events WHERE upload_fk = $1 " .
317 $row = $this->
dbManager->getSingleRow($sql, [$uploadId], __METHOD__);
318 if (empty($row) || empty($row[
"event_ts"])) {
321 return $row[
"event_ts"];
332 $sql =
"SELECT MAX(event_ts) as event_ts FROM upload_events WHERE upload_fk = $1 " .
334 $row = $this->
dbManager->getSingleRow($sql, [$uploadId], __METHOD__);
335 if (empty($row) || empty($row[
"event_ts"])) {
338 return $row[
"event_ts"];
350 return $batch[$uploadId] ?? [
'NA', 0];
360 if (empty($uploadIds)) {
364 $uploadIds = array_unique(array_filter($uploadIds));
365 if (empty($uploadIds)) {
370 foreach ($uploadIds as $id) {
371 $results[(int)$id] = array(
"NA", 0);
374 $uploadIdsStr =
'{' . implode(
',', array_map(
'intval', $uploadIds)) .
'}';
376 $sql =
"SELECT upload_fk, " .
377 "MIN(CASE WHEN event_type = $2 THEN event_ts END) as assignee_ts, " .
378 "MAX(CASE WHEN event_type = $3 THEN event_ts END) as closed_ts " .
379 "FROM upload_events " .
380 "WHERE upload_fk = ANY($1::int[]) AND event_type IN ($2, $3) " .
381 "GROUP BY upload_fk";
385 foreach ($rows as $row) {
386 $id = (int)$row[
'upload_fk'];
390 if (!empty($row[
'assignee_ts']) && !empty($row[
'closed_ts'])) {
392 $assignDate =
new DateTime($row[
'assignee_ts']);
393 $closingDate =
new DateTime($row[
'closed_ts']);
394 if ($assignDate < $closingDate) {
396 $durationSort = $closingDate->getTimestamp() - $assignDate->getTimestamp();
401 $results[$id] = array($duration, $durationSort);
416 if (!empty($uploadId)) {
417 $statementName = __METHOD__;
419 "SELECT uploadtree_tablename FROM upload WHERE upload_pk=$1",
423 if (!empty($row[
'uploadtree_tablename'])) {
424 return $row[
'uploadtree_tablename'];
453 const NOT_FOUND =
null;
466 $originItem = $this->
getUploadEntry($itemId, $uploadTreeTableName);
467 $originLft = $originItem[
'lft'];
469 $options[UploadTreeProxy::OPT_ITEM_FILTER] =
" AND ut.ufile_mode & (3<<28) = 0";
470 $uploadTreeViewName =
'items2care';
472 if ($direction == self::DIR_FWD) {
473 $uploadTreeViewName .=
'fwd';
474 $options[UploadTreeProxy::OPT_ITEM_FILTER] .=
" AND lft>$1";
477 $uploadTreeViewName .=
'bwd';
478 $options[UploadTreeProxy::OPT_ITEM_FILTER] .=
" AND lft<$1";
482 $uploadTreeView =
new UploadTreeProxy($uploadId, $options, $uploadTreeTableName, $uploadTreeViewName);
483 $statementName = __METHOD__ .
".$uploadTreeViewName.";
484 $query = $uploadTreeView->getDbViewQuery().
" ORDER BY lft $order";
486 $newItemRow = $this->
dbManager->getSingleRow(
"$query LIMIT 1", array($originLft), $statementName);
488 return $this->
createItem($newItemRow, $uploadTreeTableName);
490 return self::NOT_FOUND;
502 $statementname = __METHOD__ . $uploadTreeTableName;
504 $parent = $this->
dbManager->getSingleRow(
505 "SELECT uploadtree_pk
506 FROM $uploadTreeTableName
507 WHERE upload_fk=$1 AND parent IS NULL", array($uploadId), $statementname);
508 if (
false === $parent) {
509 throw new \Exception(
"Missing upload tree parent for upload");
511 return $parent[
'uploadtree_pk'];
514 public function getLeftAndRight($uploadtreeID, $uploadTreeTableName =
"uploadtree")
516 $statementName = __METHOD__ . $uploadTreeTableName;
517 $leftRight = $this->
dbManager->getSingleRow(
518 "SELECT lft,rgt FROM $uploadTreeTableName WHERE uploadtree_pk = $1",
519 array($uploadtreeID), $statementName
522 return array($leftRight[
'lft'], $leftRight[
'rgt']);
532 $sql =
"SELECT count(*) FROM " . $uploadTreeView->
getDbViewName() .
" WHERE lft BETWEEN $1 AND $2";
533 $result = $this->
dbManager->getSingleRow($sql
534 , array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight()), __METHOD__ . $uploadTreeView->
asCTE());
535 return $result[
'count'];
544 public function getContainedItems(
ItemTreeBounds $itemTreeBounds, $addCondition =
"", $addParameters = array())
548 $statementName = __METHOD__ .
".$uploadTreeTableName";
550 $view =
new UploadTreeViewProxy($itemTreeBounds, array(UploadTreeViewProxy::CONDITION_PLAIN_FILES));
552 $this->
dbManager->prepare($statementName,
553 $view->asCTE() .
" SELECT * FROM " . $view->getDbViewName() .
" ut ".
554 ($addCondition ?
" WHERE " . $addCondition :
''));
555 $res = $this->
dbManager->execute($statementName, $addParameters);
558 while ($row = $this->
dbManager->fetchArray($res)) {
559 $items[] = $this->
createItem($row, $uploadTreeTableName);
572 public function addReusedUpload($uploadId, $reusedUploadId, $groupId, $reusedGroupId, $reuseMode=0)
574 $this->
dbManager->insertTableRow(
'upload_reuse',
575 array(
'upload_fk'=>$uploadId,
'group_fk'=> $groupId,
'reused_upload_fk'=>$reusedUploadId,
'reused_group_fk'=>$reusedGroupId,
'reuse_mode'=>$reuseMode));
586 $statementName = __METHOD__;
588 $this->
dbManager->prepare($statementName,
589 "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");
590 $res = $this->
dbManager->execute($statementName, array($uploadId, $groupId));
591 $reusedPairs = $this->
dbManager->fetchAll($res);
601 protected function createItem($uploadEntry, $uploadTreeTableName)
604 intval($uploadEntry[
'uploadtree_pk']),
605 $uploadTreeTableName,
606 intval($uploadEntry[
'upload_fk']),
607 intval($uploadEntry[
'lft']), intval($uploadEntry[
'rgt']));
609 $parent = $uploadEntry[
'parent'];
611 $itemTreeBounds, $parent !==
null ? intval($parent) :
null, intval($uploadEntry[
'pfile_fk']), intval($uploadEntry[
'ufile_mode']), $uploadEntry[
'ufile_name']
623 if ($uploadEntryData ===
false) {
624 throw new Exception(
"did not find uploadTreeId in $uploadTreeTableName");
626 return new ItemTreeBounds(intval($uploadEntryData[
'uploadtree_pk']), $uploadTreeTableName, intval($uploadEntryData[
'upload_fk']), intval($uploadEntryData[
'lft']), intval($uploadEntryData[
'rgt']));
637 $sql =
"SELECT count(*) FROM ".$itemTreeBounds->getUploadTreeTableName().
" ut "
638 .
"WHERE ut.upload_fk=$1";
641 $stmt = __METHOD__.
'.parent';
642 $params[] = $itemTreeBounds->
getItemId();
643 $sql .=
" AND ut.ufile_mode & (1<<28) = 0 AND ut.realparent = $2";
645 $params[] = $itemTreeBounds->
getLeft();
646 $params[] = $itemTreeBounds->
getRight();
647 $sql .=
" AND ut.ufile_mode & (3<<28) = 0 AND (ut.lft BETWEEN $2 AND $3)";
650 $descendants = $this->
dbManager->getSingleRow($sql,$params);
651 return $descendants[
'count'];
655 public function isAccessible($uploadId, $groupId)
657 return $this->permissionDao->isAccessible($uploadId, $groupId);
660 public function isEditable($uploadId, $groupId)
662 return $this->permissionDao->isEditable($uploadId, $groupId);
665 public function makeAccessibleToGroup($uploadId, $groupId, $perm=
null)
667 $this->permissionDao->makeAccessibleToGroup($uploadId, $groupId, $perm);
670 public function makeAccessibleToAllGroupsOf($uploadId, $userId, $perm=
null)
672 $this->permissionDao->makeAccessibleToAllGroupsOf($uploadId, $userId, $perm);
675 public function filterAccessibleUploads(array $uploadIds, $groupId)
677 return $this->permissionDao->filterAccessibleUploads($uploadIds, $groupId);
686 $pfile = $this->
dbManager->getSingleRow(
'SELECT pfile.* FROM upload, pfile WHERE upload_pk=$1 AND pfile_fk=pfile_pk',
687 array($uploadId), __METHOD__);
688 return array(
'sha1'=>$pfile[
'pfile_sha1'],
'md5'=>$pfile[
'pfile_md5'],
'sha256'=>$pfile[
'pfile_sha256']);
699 $sqlChildrenOf =
"SELECT COUNT(*) FROM $uploadtreeTablename s
700 WHERE ufile_mode&(1<<28)=0 and s.upload_fk=$2 AND s.realparent=";
701 $sql=
"WITH RECURSIVE item_path (item_id,num_children,depth,ufile_mode,ufile_name) AS (
702 SELECT uploadtree_pk item_id, ($sqlChildrenOf $1) num_children, 0 depth, ufile_mode, ufile_name
703 FROM $uploadtreeTablename WHERE upload_fk=$2 AND uploadtree_pk=$1
705 SELECT uploadtree_pk item_id, ($sqlChildrenOf ut.uploadtree_pk) num_children,
706 item_path.depth+1 depth, ut.ufile_mode, item_path.ufile_name||'/'||ut.ufile_name ufile_name
707 FROM $uploadtreeTablename ut INNER JOIN item_path ON item_id=ut.realparent
708 WHERE upload_fk=$2 AND ut.ufile_mode&(1<<28)=0 AND num_children<2
710 SELECT * FROM item_path WHERE num_children!=1 OR ufile_mode&(1<<29)=0 ORDER BY depth DESC LIMIT 1";
711 return $this->
dbManager->getSingleRow($sql,array($itemId, $uploadId),__METHOD__.$uploadtreeTablename);
722 $itemRow = $this->
getFatItemArray($itemId,$uploadId,$uploadtreeTablename);
723 return $itemRow[
'item_id'];
733 $statementName = __METHOD__ .
'.' . $uploadTreeTableName;
736 $param[] = $itemTreeBounds->
getLeft();
737 $param[] = $itemTreeBounds->
getRight();
738 $condition =
" lft BETWEEN $1 AND $2";
739 $condition .=
" AND (ufile_mode & (1<<28)) = 0";
741 if (
'uploadtree_a' == $uploadTreeTableName) {
743 $condition .=
" AND upload_fk=$".count($param);
747 SELECT ufile_name, uploadtree_pk, lft, rgt, ufile_mode,
748 pfile_pk, pfile_md5, pfile_sha1, pfile_sha256
749 FROM $uploadTreeTableName
751 ON pfile_fk = pfile_pk
756 $this->
dbManager->prepare($statementName, $sql);
757 $result = $this->
dbManager->execute($statementName, $param);
758 $pfilePerFileName = array();
760 $row = $this->
dbManager->fetchArray($result);
761 $pathStack = array($row[
'ufile_name']);
762 $rgtStack = array($row[
'rgt']);
763 $lastLft = $row[
'lft'];
764 $this->addToPFilePerFileName($pfilePerFileName, $pathStack, $row);
765 while ($row = $this->
dbManager->fetchArray($result)) {
766 if ($row[
'lft'] < $lastLft) {
770 $this->updateStackState($pathStack, $rgtStack, $lastLft, $row);
771 $this->addToPFilePerFileName($pfilePerFileName, $pathStack, $row);
774 return $pfilePerFileName;
777 private function updateStackState(&$pathStack, &$rgtStack, &$lastLft, $row)
779 if ($row[
'lft'] >= $lastLft) {
780 while (count($rgtStack) > 0 && $row[
'lft'] > $rgtStack[count($rgtStack)-1]) {
781 array_pop($pathStack);
782 array_pop($rgtStack);
784 if ($row[
'lft'] > $lastLft) {
785 $pathStack[] = $row[
'ufile_name'];
786 $rgtStack[] = $row[
'rgt'];
787 $lastLft = $row[
'lft'];
792 private function addToPFilePerFileName(&$pfilePerFileName, $pathStack, $row)
794 if (($row[
'ufile_mode'] & (1 << 29)) == 0) {
795 $path = implode(
'/', $pathStack);
796 $pfilePerFileName[$path][
'pfile_pk'] = $row[
'pfile_pk'];
797 $pfilePerFileName[$path][
'uploadtree_pk'] = $row[
'uploadtree_pk'];
798 $pfilePerFileName[$path][
'md5'] = $row[
'pfile_md5'];
799 $pfilePerFileName[$path][
'sha1'] = $row[
'pfile_sha1'];
800 $pfilePerFileName[$path][
'sha256'] = $row[
'pfile_sha256'];
812 $statementName = __METHOD__ .
'.' . $uploadTreeTableName;
815 $param[] = $itemTreeBounds->
getLeft();
816 $param[] = $itemTreeBounds->
getRight();
817 $condition =
" lft BETWEEN $1 AND $2";
818 $condition .=
" AND (ufile_mode & (1<<28)) = 0";
820 if (
'uploadtree_a' == $uploadTreeTableName) {
822 $condition .=
" AND upload_fk=$".count($param);
824 $condition .=
" AND pfile_$hashAlgo IS NOT NULL";
827 SELECT pfile_fk, uploadtree_pk, ufile_mode, pfile_$hashAlgo as hash
828 FROM $uploadTreeTableName
830 ON pfile_fk = pfile_pk
835 $this->
dbManager->prepare($statementName, $sql);
836 $result = $this->
dbManager->execute($statementName, $param);
838 $pfilePerHashAlgo = array();
839 while ($row = $this->
dbManager->fetchArray($result)) {
840 if (($row[
'ufile_mode']&(1<<29)) == 0) {
841 $pfilePerHashAlgo[strtolower($row[
'hash'])][] = array(
'pfile_pk' => $row[
'pfile_fk'],
842 'uploadtree_pk' => $row[
'uploadtree_pk']);
846 return $pfilePerHashAlgo;
853 public function getReportInfo($uploadId)
856 $sql =
"SELECT * FROM report_info WHERE upload_fk = $1";
857 $row = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
861 $stmt = __METHOD__.
'ifempty';
862 $sql =
"INSERT INTO report_info (upload_fk) VALUES ($1) RETURNING *";
863 $row = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
876 $stmt = __METHOD__ .
'.getOwner';
877 $sql =
"SELECT user_fk FROM upload WHERE upload_pk = $1";
878 $uploadOwner = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
880 if (empty($uploadOwner)) {
881 return "unchecked,unchecked,unchecked";
884 $userId = $uploadOwner[
'user_fk'];
886 $stmt = __METHOD__ .
'.getUserDefaults';
887 $sql =
"SELECT spdx_settings FROM users WHERE user_pk = $1";
888 $userDefaults = $this->
dbManager->getSingleRow($sql, array($userId), $stmt);
890 if (empty($userDefaults) || empty($userDefaults[
'spdx_settings'])) {
891 return "unchecked,unchecked,unchecked";
894 $settings = explode(
',', $userDefaults[
'spdx_settings']);
895 if (count($settings) < 3) {
896 $settings = array_pad($settings, 3,
'unchecked');
899 $osselotExport = $settings[0];
900 $spdxLicenseComment = $settings[1];
901 $ignoreFilesWOInfo = $settings[2];
903 $result =
"$spdxLicenseComment,$ignoreFilesWOInfo,$osselotExport";
917 if ($column ===
"ri_unifiedcolumns") {
918 $value = json_decode($value,
true);
919 $oldValues = $this->getReportInfo($uploadId)[
"ri_unifiedcolumns"];
920 if (!empty($oldValues)) {
921 $oldValues = json_decode($oldValues,
true);
923 $oldValues = self::UNIFIED_REPORT_HEADINGS;
925 foreach ($value as $key => $val) {
926 $newValText = array_keys($val)[0];
927 $newValValue = array_values($val)[0];
928 $newValValue = ($newValValue ===
true || $newValValue ==
"true") ?
"on" :
null;
929 $oldValues[$key] = [$newValText => $newValValue];
931 $value = json_encode($oldValues);
932 } elseif ($column ===
"ri_excluded_obligations") {
933 $value = json_decode($value,
true);
934 $oldValues = $this->getReportInfo($uploadId)[
"ri_excluded_obligations"];
935 if (!empty($oldValues)) {
936 $oldValues = json_decode($oldValues,
true);
940 foreach ($value as $key => $newValue) {
941 $oldValues[$key] = $newValue;
943 $value = json_encode($oldValues);
944 } elseif ($column ===
"ri_globaldecision") {
945 $value = filter_var($value, FILTER_VALIDATE_BOOL);
948 $sql =
"UPDATE report_info SET $column = $2 WHERE upload_fk = $1;";
949 $stmt = __METHOD__ .
"updateReportInfo" . $column;
950 $this->
dbManager->getSingleRow($sql, [$uploadId, $value], $stmt);
957 public function getGlobalDecisionSettingsFromInfo($uploadId, $setGlobal=
null)
959 $stmt = __METHOD__ .
'get';
960 $sql =
"SELECT ri_globaldecision, ri_spdx_selection FROM report_info WHERE upload_fk = $1";
961 $row = $this->
dbManager->getSingleRow($sql, array($uploadId), $stmt);
963 if ($setGlobal ===
null) {
967 $stmt = __METHOD__ .
'ifempty';
969 $sql =
"INSERT INTO report_info (upload_fk, ri_globaldecision, ri_spdx_selection) VALUES ($1, $2, $3) RETURNING ri_globaldecision";
970 $row = $this->
dbManager->getSingleRow($sql, array($uploadId, $setGlobal, $userSPDXDefaults), $stmt);
974 if (!empty($setGlobal)) {
975 $stmt = __METHOD__ .
'update';
976 $sql =
"UPDATE report_info SET ri_globaldecision = $2 WHERE upload_fk = $1 RETURNING ri_globaldecision";
977 $row = $this->
dbManager->getSingleRow($sql, array($uploadId, $setGlobal), $stmt);
980 return $row[
'ri_globaldecision'];
990 $stmt = __METHOD__.
"getUploadHashesFromPfileId";
991 $sql =
"SELECT * FROM pfile WHERE pfile_pk = $1";
992 $row = $this->
dbManager->getSingleRow($sql, array($pfilePk), $stmt);
994 return [
"sha1" => $row[
"pfile_sha1"],
"md5" => $row[
"pfile_md5"],
"sha256" => $row[
"pfile_sha256"]];
1004 $stmt = __METHOD__ .
".checkReused";
1005 $sql =
"SELECT 1 AS exists FROM report_info WHERE upload_fk = $1 LIMIT 1;";
1006 $row = $this->
dbManager->getSingleRow($sql, array($reusedUploadId), $stmt);
1008 if (empty($row[
'exists'])) {
1014 $stmt = __METHOD__ .
".removeExists";
1015 $sql =
"DELETE FROM report_info WHERE upload_fk = $1;";
1016 $this->
dbManager->getSingleRow($sql, [$uploadId], $stmt);
1018 $stmt = __METHOD__ .
".getAllColumns";
1019 $sql =
"SELECT string_agg(column_name, ',') AS columns
1020 FROM information_schema.columns
1021 WHERE table_name = 'report_info'
1022 AND column_name != 'ri_pk'
1023 AND column_name != 'upload_fk';";
1024 $row = $this->
dbManager->getSingleRow($sql, [], $stmt);
1025 $columns = $row[
'columns'];
1027 $stmt = __METHOD__.
"CopyinsertReportConfReuse";
1029 "INSERT INTO report_info(upload_fk, $columns)
1031 FROM report_info WHERE upload_fk = $2"
1034 $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.
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