46 private $licenseRefCache;
55 $this->logger =
new Logger(self::class);
56 $this->uploadDao = $uploadDao;
57 $this->licenseRefCache = array();
60 private function getRelevantDecisionsCte(
ItemTreeBounds $itemTreeBounds, $groupId, $onlyCurrent, &$statementName, &$params, $condition=
"")
64 $params[] = DecisionTypes::WIP; $p1 =
"$". count($params);
65 $params[] = $groupId; $p2 =
"$". count($params);
68 if (
'uploadtree' === $uploadTreeTable ||
'uploadtree_a' === $uploadTreeTable) {
69 $params[] = $itemTreeBounds->
getUploadId(); $p =
"$". count($params);
70 $sql_upload =
"ut.upload_fk=$p AND ";
72 if (!empty($condition)) {
73 $statementName .=
".(".$condition.
")";
74 $condition .=
" AND ";
77 $filterClause = $onlyCurrent ?
"DISTINCT ON(itemid)" :
"";
79 $statementName .=
"." . $uploadTreeTable . ($onlyCurrent ?
".current":
"");
81 $globalScope = DecisionScopes::REPO;
82 $localScope = DecisionScopes::ITEM;
84 return "WITH allDecs AS ( 86 cd.clearing_decision_pk AS id, 87 cd.pfile_fk AS pfile_id, 88 ut.uploadtree_pk AS itemid, 89 cd.user_fk AS user_id, 90 cd.decision_type AS type_id, 92 EXTRACT(EPOCH FROM cd.date_added) AS ts_added, 93 CASE cd.scope WHEN $globalScope THEN 1 ELSE 0 END AS scopesort 94 FROM clearing_decision cd 95 INNER JOIN $uploadTreeTable ut 96 ON (ut.pfile_fk = cd.pfile_fk AND cd.scope = $globalScope) 97 OR (ut.uploadtree_pk = cd.uploadtree_fk 98 AND cd.scope = $localScope AND cd.group_fk = $p2) 99 WHERE $sql_upload $condition 100 cd.decision_type!=$p1), 102 SELECT $filterClause * 104 ORDER BY itemid, scopesort, id DESC 115 $statementName = __METHOD__;
117 $params = array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight());
118 $condition =
"ut.lft BETWEEN $1 AND $2";
120 $decisionsCte = $this->getRelevantDecisionsCte($itemTreeBounds, $groupId, $onlyCurrent=
true, $statementName, $params, $condition);
121 $params[] = DecisionTypes::IRRELEVANT;
122 $sql =
"$decisionsCte 124 lr.rf_pk AS license_id, 125 lr.rf_shortname AS shortname, 126 lr.rf_fullname AS fullname 128 INNER JOIN clearing_decision_event cde ON cde.clearing_decision_fk = decision.id 129 INNER JOIN clearing_event ce ON ce.clearing_event_pk = cde.clearing_event_fk 130 INNER JOIN license_ref lr ON lr.rf_pk = ce.rf_fk 131 WHERE NOT ce.removed AND type_id!=$".count($params).
" 132 GROUP BY license_id,shortname,fullname";
134 $this->
dbManager->prepare($statementName, $sql);
136 $res = $this->
dbManager->execute($statementName, $params);
139 while ($row = $this->
dbManager->fetchArray($res)) {
140 $licenses[] =
new LicenseRef($row[
'license_id'], $row[
'shortname'], $row[
'fullname']);
158 $statementName = __METHOD__;
160 $params = array($itemTreeBounds->
getItemId());
161 $condition =
"ut.uploadtree_pk = $1";
163 $decisionsCte = $this->getRelevantDecisionsCte($itemTreeBounds, $groupId, $onlyCurrent, $statementName, $params, $condition);
165 $clearingsWithLicensesArray = $this->
getDecisionsFromCte($decisionsCte, $statementName, $params, $forClearingHistory);
168 return $clearingsWithLicensesArray;
182 $statementName = __METHOD__;
184 if (!$includeSubFolders) {
185 $params = array($itemTreeBounds->
getItemId());
186 $condition =
"ut.realparent = $1";
188 $params = array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight());
189 $condition =
"ut.lft BETWEEN $1 AND $2";
192 $decisionsCte = $this->getRelevantDecisionsCte($itemTreeBounds, $groupId, $onlyCurrent, $statementName, $params, $condition);
194 $clearingsWithLicensesArray = $this->
getDecisionsFromCte($decisionsCte, $statementName, $params);
197 return $clearingsWithLicensesArray;
208 $sql =
"$decisionsCte 211 users.user_name AS user_name, 212 ce.clearing_event_pk as event_id, 213 ce.user_fk as event_user_id, 214 ce.group_fk as event_group_id, 215 lr.rf_pk AS license_id, 216 lr.rf_shortname AS shortname, 217 lr.rf_fullname AS fullname, 218 ce.removed AS removed, 219 ce.type_fk AS event_type_id, 220 ce.reportinfo AS reportinfo, 221 ce.comment AS comment, 222 ce.acknowledgement AS acknowledgement 224 LEFT JOIN users ON decision.user_id = users.user_pk 225 LEFT JOIN clearing_decision_event cde ON cde.clearing_decision_fk = decision.id 226 LEFT JOIN clearing_event ce ON ce.clearing_event_pk = cde.clearing_event_fk 227 LEFT JOIN license_ref lr ON lr.rf_pk = ce.rf_fk 228 ORDER BY decision.id DESC, event_id ASC";
230 $this->
dbManager->prepare($statementName, $sql);
232 $result = $this->
dbManager->execute($statementName, $params);
233 $clearingsWithLicensesArray = array();
235 $previousClearingId = -1;
236 $previousItemId = -1;
237 $clearingEvents = array();
238 $clearingEventCache = array();
241 while ($row = $this->
dbManager->fetchArray($result)) {
242 $clearingId = $row[
'id'];
243 $itemId = $row[
'itemid'];
244 $licenseId = $row[
'license_id'];
245 $eventId = $row[
'event_id'];
246 $licenseShortName = $row[
'shortname'];
247 $licenseName = $row[
'fullname'];
248 $licenseIsRemoved = $row[
'removed'];
250 $eventType = $row[
'event_type_id'];
251 $eventUserId = $row[
'event_user_id'];
252 $eventGroupId = $row[
'event_group_id'];
253 $comment = $row[
'comment'];
254 $reportInfo = $row[
'reportinfo'];
255 $acknowledgement = $row[
'acknowledgement'];
257 if ($clearingId !== $previousClearingId && $itemId !== $previousItemId) {
260 $clearingsWithLicensesArray[] = $clearingDecisionBuilder->setClearingEvents($clearingEvents)->build();
265 if ($forClearingHistory) {
266 $previousClearingId = $clearingId;
268 $previousItemId = $itemId;
270 $clearingEvents = array();
272 ->setClearingId($row[
'id'])
273 ->setUploadTreeId($itemId)
274 ->setPfileId($row[
'pfile_id'])
275 ->setUserName($row[
'user_name'])
276 ->setUserId($row[
'user_id'])
277 ->setType(intval($row[
'type_id']))
278 ->setScope(intval($row[
'scope']))
279 ->setTimeStamp($row[
'ts_added']);
282 if ($licenseId !== null) {
283 if (!array_key_exists($eventId, $clearingEventCache)) {
284 if (!array_key_exists($licenseId, $this->licenseRefCache)) {
285 $this->licenseRefCache[$licenseId] =
new LicenseRef($licenseId, $licenseShortName, $licenseName);
287 $licenseRef = $this->licenseRefCache[$licenseId];
288 $clearingEventCache[$eventId] = $this->
buildClearingEvent($eventId, $eventUserId, $eventGroupId, $licenseRef, $licenseIsRemoved, $eventType, $reportInfo, $comment, $acknowledgement);
290 $clearingEvents[] = $clearingEventCache[$eventId];
296 $clearingsWithLicensesArray[] = $clearingDecisionBuilder->setClearingEvents($clearingEvents)->build();
300 return $clearingsWithLicensesArray;
310 if (count($clearingDecisions) > 0) {
311 return $clearingDecisions[0];
322 $sql =
"DELETE FROM clearing_decision WHERE uploadtree_fk=$1 AND group_fk=$2 AND decision_type=$3";
323 $this->
dbManager->prepare($stmt = __METHOD__, $sql);
324 $this->
dbManager->freeResult($this->
dbManager->execute($stmt, array($uploadTreeId, $groupId, DecisionTypes::WIP)));
336 if ( ($scope == DecisionScopes::REPO) &&
338 throw new \Exception( _(
"Cannot add candidate license as global decision\n") );
344 $statementName = __METHOD__;
345 $this->
dbManager->prepare($statementName,
347 INSERT INTO clearing_decision ( 356 (SELECT pfile_fk FROM uploadtree WHERE uploadtree_pk=$1), 360 $5) RETURNING clearing_decision_pk 362 $res = $this->
dbManager->execute($statementName,
363 array($uploadTreeId, $userId, $groupId, $decType, $scope));
364 $result = $this->
dbManager->fetchArray($res);
365 $clearingDecisionId = $result[
'clearing_decision_pk'];
368 $statementNameClearingDecisionEventInsert = __METHOD__ .
".insertClearingDecisionEvent";
369 $this->
dbManager->prepare($statementNameClearingDecisionEventInsert,
370 "INSERT INTO clearing_decision_event (clearing_decision_fk, clearing_event_fk) VALUES($1, $2)" 373 foreach ($eventIds as $eventId) {
374 $this->
dbManager->freeResult($this->
dbManager->execute($statementNameClearingDecisionEventInsert, array($clearingDecisionId, $eventId)));
387 $decision = $this->
getFileClearingsFolder($itemTreeBounds, $groupId, $includeSubFolders, $onlyCurrent=
true);
391 if (count($decision)) {
392 foreach ($decision[0]->getClearingEvents() as $event) {
393 $events[$event->getLicenseId()] = $event;
395 $date = $decision[0]->getTimeStamp();
399 $sql =
'SELECT rf_fk,rf_shortname,rf_fullname,clearing_event_pk,comment,type_fk,removed,reportinfo,acknowledgement, EXTRACT(EPOCH FROM date_added) AS ts_added 400 FROM clearing_event LEFT JOIN license_ref ON rf_fk=rf_pk 401 WHERE uploadtree_fk=$1 AND group_fk=$2 AND date_added>to_timestamp($3) 402 ORDER BY clearing_event_pk ASC';
404 $res = $this->
dbManager->execute($stmt,array($itemTreeBounds->
getItemId(),$groupId,$date));
406 while ($row = $this->
dbManager->fetchArray($res)) {
407 $licenseRef =
new LicenseRef($row[
'rf_fk'],$row[
'rf_shortname'],$row[
'rf_fullname']);
408 $events[$row[
'rf_fk']] = ClearingEventBuilder::create()
409 ->setEventId($row[
'clearing_event_pk'])
410 ->setComment($row[
'comment'])
411 ->setTimeStamp($row[
'ts_added'])
412 ->setEventType($row[
'type_fk'])
413 ->setLicenseRef($licenseRef)
414 ->setRemoved($this->
dbManager->booleanFromDb($row[
'removed']))
415 ->setReportinfo($row[
'reportinfo'])
416 ->setAcknowledgement($row[
'acknowledgement'])
417 ->setUploadTreeId($itemTreeBounds->
getItemId())
436 $statementGetOldata =
"SELECT * FROM clearing_event WHERE uploadtree_fk=$1 AND rf_fk=$2 AND group_fk=$3 ORDER BY clearing_event_pk DESC LIMIT 1";
437 $statementName = __METHOD__ .
'getOld';
438 $params = array($uploadTreeId, $licenseId, $groupId);
439 $row = $this->
dbManager->getSingleRow($statementGetOldata, $params, $statementName);
442 $type = ClearingEventTypes::USER;
443 $row[
'type_fk'] = $type;
444 $row[
'comment'] =
"";
445 $row[
'reportinfo'] =
"";
446 $row[
'acknowledgement'] =
"";
449 if ($what ==
'reportinfo') {
450 $reportInfo = $changeTo;
451 $comment = $row[
'comment'];
452 $acknowledgement = $row[
'acknowledgement'];
453 } elseif ($what ==
'comment') {
454 $reportInfo = $row[
'reportinfo'];
455 $comment = $changeTo;
456 $acknowledgement = $row[
'acknowledgement'];
458 $reportInfo = $row[
'reportinfo'];
459 $comment = $row[
'comment'];
460 $acknowledgement = $changeTo;
462 $this->
insertClearingEvent($uploadTreeId, $userId, $groupId, $licenseId,
false, $row[
'type_fk'], $reportInfo, $comment, $acknowledgement);
468 public function copyEventIdTo($eventId, $itemId, $userId, $groupId)
472 "INSERT INTO clearing_event(uploadtree_fk, user_fk, group_fk, type_fk, rf_fk, removed, reportinfo, comment, acknowledgement) 473 SELECT $2, $3, $4, type_fk, rf_fk, removed, reportinfo, comment, acknowledgement FROM clearing_event WHERE clearing_event_pk = $1" 476 $this->
dbManager->freeResult($this->
dbManager->execute($stmt, array($eventId, $itemId, $userId, $groupId)));
491 public function insertClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, $isRemoved, $type = ClearingEventTypes::USER, $reportInfo =
'', $comment =
'', $acknowledgement =
'', $jobId=0)
493 $insertIsRemoved = $this->
dbManager->booleanToDb($isRemoved);
496 $params = array($uploadTreeId, $userId, $groupId, $type, $licenseId, $insertIsRemoved, $reportInfo, $comment, $acknowledgement);
497 $columns =
"uploadtree_fk, user_fk, group_fk, type_fk, rf_fk, removed, reportinfo, comment, acknowledgement";
498 $values =
"$1,$2,$3,$4,$5,$6,$7,$8,$9";
503 $columns .=
", job_fk";
504 $values .=
",$".count($params);
509 $this->
dbManager->prepare($stmt,
"INSERT INTO clearing_event ($columns) VALUES($values) RETURNING clearing_event_pk");
510 $res = $this->
dbManager->execute($stmt, $params);
512 $row = $this->
dbManager->fetchArray($res);
515 return intval($row[
'clearing_event_pk']);
524 $statementName = __METHOD__;
527 "SELECT uploadtree_fk, clearing_event_pk, rf_fk FROM clearing_event WHERE job_fk = $1" 530 $res = $this->
dbManager->execute($statementName, array($jobId));
533 while ($row = $this->
dbManager->fetchArray($res)) {
534 $itemId = intval($row[
'uploadtree_fk']);
535 $eventId = intval($row[
'clearing_event_pk']);
536 $licenseId = intval($row[
'rf_fk']);
538 $events[$itemId][$licenseId] = $eventId;
556 protected function buildClearingEvent($eventId, $userId, $groupId, $licenseRef, $licenseIsRemoved, $type, $reportInfo, $comment, $acknowledgement)
558 $removed = $this->
dbManager->booleanFromDb($licenseIsRemoved);
560 return ClearingEventBuilder::create()
561 ->setEventId($eventId)
563 ->setGroupId($groupId)
564 ->setEventType($type)
565 ->setLicenseRef($licenseRef)
566 ->setRemoved($removed)
567 ->setReportInfo($reportInfo)
568 ->setAcknowledgement($acknowledgement)
569 ->setComment($comment)
580 $statementName = __METHOD__;
582 $this->
dbManager->prepare($statementName,
583 "INSERT INTO clearing_decision (uploadtree_fk,pfile_fk,user_fk,group_fk,decision_type,scope) VALUES ( 584 $1, (SELECT pfile_fk FROM uploadtree WHERE uploadtree_pk=$1), $2, $3, $4, $5)");
585 $res = $this->
dbManager->execute($statementName,
586 array($uploadTreeId, $userId, $groupId, DecisionTypes::WIP, DecisionScopes::ITEM));
590 public function isDecisionWip($uploadTreeId, $groupId)
592 $sql =
"SELECT decision_type FROM clearing_decision WHERE uploadtree_fk=$1 AND group_fk = $2 ORDER BY date_added DESC LIMIT 1";
593 $latestDec = $this->
dbManager->getSingleRow($sql,
594 array($uploadTreeId, $groupId), $sqlLog = __METHOD__);
595 if ($latestDec ===
false) {
598 return ($latestDec[
'decision_type'] == DecisionTypes::WIP);
601 public function isDecisionTBD($uploadTreeId, $groupId)
603 $sql =
"SELECT decision_type FROM clearing_decision WHERE uploadtree_fk=$1 AND group_fk = $2 ORDER BY date_added DESC LIMIT 1";
604 $latestDec = $this->
dbManager->getSingleRow($sql,
605 array($uploadTreeId, $groupId), $sqlLog = __METHOD__);
606 if ($latestDec ===
false) {
609 return ($latestDec[
'decision_type'] == DecisionTypes::TO_BE_DISCUSSED);
612 public function isDecisionDNU($uploadTreeId, $groupId)
614 $sql =
"SELECT decision_type FROM clearing_decision 615 WHERE uploadtree_fk=$1 AND group_fk = $2 616 ORDER BY clearing_decision_pk DESC LIMIT 1";
617 $latestDec = $this->
dbManager->getSingleRow($sql,
618 array($uploadTreeId, $groupId), $sqlLog = __METHOD__);
619 if ($latestDec ===
false) {
622 return ($latestDec[
'decision_type'] == DecisionTypes::DO_NOT_USE);
636 $left = $itemTreeBound->
getLeft();
638 $params = array($uploadId, $itemId, $left, $groupId);
639 $stmt = __METHOD__ .
"." . $uploadTreeTableName;
641 $triedExpr =
"$3 between ut2.lft and ut2.rgt";
644 $triedFilter =
"and " . $triedExpr;
648 $sql =
"WITH alltried AS ( 649 SELECT lr.lrb_pk, ce.clearing_event_pk ce_pk, lr.rf_text, ce.uploadtree_fk, 651 FROM license_ref_bulk lr 652 LEFT JOIN highlight_bulk h ON lrb_fk = lrb_pk 653 LEFT JOIN clearing_event ce ON ce.clearing_event_pk = h.clearing_event_fk 654 LEFT JOIN $uploadTreeTableName ut ON ut.uploadtree_pk = ce.uploadtree_fk 655 INNER JOIN $uploadTreeTableName ut2 ON ut2.uploadtree_pk = lr.uploadtree_fk 656 WHERE ut2.upload_fk = $1 AND lr.group_fk = $4 659 ), aggregated_tried AS ( 660 SELECT DISTINCT ON(lrb_pk) lrb_pk, ce_pk, rf_text AS text, tried, matched 662 SELECT DISTINCT ON(lrb_pk) lrb_pk, ce_pk, rf_text, tried, true AS matched FROM alltried WHERE uploadtree_fk = $2 664 SELECT DISTINCT ON(lrb_pk) lrb_pk, ce_pk, rf_text, tried, false AS matched FROM alltried WHERE uploadtree_fk != $2 OR uploadtree_fk IS NULL 665 ) AS result ORDER BY lrb_pk, matched DESC) 666 SELECT lrb_pk, text, rf_shortname, removing, tried, ce_pk, matched 667 FROM aggregated_tried 668 INNER JOIN license_set_bulk lsb ON lsb.lrb_fk = lrb_pk 669 INNER JOIN license_ref lrf ON lsb.rf_fk = lrf.rf_pk 673 $res = $this->
dbManager->execute($stmt, $params);
676 while ($row = $this->
dbManager->fetchArray($res)) {
677 $bulkRun = $row[
'lrb_pk'];
678 if (!array_key_exists($bulkRun, $bulks)) {
679 $bulks[$bulkRun] = array(
680 "bulkId" => $row[
'lrb_pk'],
681 "id" => $row[
'ce_pk'],
682 "text" => $row[
'text'],
683 "matched" => $this->
dbManager->booleanFromDb($row[
'matched']),
684 "tried" => $this->
dbManager->booleanFromDb($row[
'tried']),
685 "removedLicenses" => array(),
686 "addedLicenses" => array());
688 $key = $this->
dbManager->booleanFromDb($row[
'removing']) ?
'removedLicenses' :
'addedLicenses';
689 $bulks[$bulkRun][$key][] = $row[
'rf_shortname'];
697 public function getBulkMatches($bulkId, $groupId)
700 $sql =
"SELECT uploadtree_fk AS itemid 701 FROM clearing_event ce 702 INNER JOIN highlight_bulk h 703 ON ce.clearing_event_pk = h.clearing_event_fk 704 WHERE lrb_fk = $1 AND group_fk = $2";
707 $res = $this->
dbManager->execute($stmt, array($bulkId, $groupId));
709 $result = $this->
dbManager->fetchAll($res);
721 $statementName = __METHOD__;
723 $params = array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight());
724 $condition =
"ut.lft BETWEEN $1 AND $2";
726 $decisionsCte = $this->getRelevantDecisionsCte($itemTreeBounds, $groupId, $onlyCurrent=
true, $statementName, $params, $condition);
727 $params[] = DecisionTypes::IRRELEVANT;
728 $sql =
"$decisionsCte 730 COUNT(DISTINCT itemid) AS count, 731 lr.rf_shortname AS shortname, 734 LEFT JOIN clearing_decision_event cde ON cde.clearing_decision_fk = decision.id 735 LEFT JOIN clearing_event ce ON ce.clearing_event_pk = cde.clearing_event_fk 736 LEFT JOIN license_ref lr ON lr.rf_pk = ce.rf_fk 737 WHERE (NOT ce.removed OR clearing_event_pk IS NULL) AND type_id!=$".count($params).
" 738 GROUP BY shortname,rf_pk";
740 $this->
dbManager->prepare($statementName, $sql);
741 $res = $this->
dbManager->execute($statementName, $params);
742 $multiplicity = array();
743 while ($row = $this->
dbManager->fetchArray($res)) {
744 $shortname= empty($row[
'rf_pk']) ? LicenseDao::NO_LICENSE_FOUND : $row[
'shortname'];
745 $multiplicity[$shortname] = $row;
749 return $multiplicity;
759 if ($decisionMark ==
"doNotUse") {
760 $decisionMark = DecisionTypes::DO_NOT_USE;
762 $decisionMark = DecisionTypes::IRRELEVANT;
775 if ($decisionMark ==
"deleteDoNotUse") {
776 $decisionMark = DecisionTypes::DO_NOT_USE;
778 $decisionMark = DecisionTypes::IRRELEVANT;
791 $statementName = __METHOD__ ;
792 $params = array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight());
793 $params[] = $groupId;
795 $options = array(UploadTreeProxy::OPT_SKIP_THESE=>
'noLicense',
796 UploadTreeProxy::OPT_ITEM_FILTER=>
' AND (lft BETWEEN $1 AND $2)',
797 UploadTreeProxy::OPT_GROUP_ID=>
'$'.$a.
'');
799 if (!$removeDecision) {
801 $params[] = $decisionMark;
802 $params[] = DecisionScopes::ITEM;
803 $sql = $uploadTreeProxy->asCte()
804 .
' INSERT INTO clearing_decision (uploadtree_fk,pfile_fk,user_fk,group_fk,decision_type,scope) 805 SELECT uploadtree_pk itemid,pfile_fk pfile_id, $'.($a+1).
', $'.$a.
', $'.($a+2).
', $'.($a+3).
' 806 FROM UploadTreeView WHERE NOT EXISTS ( 807 SELECT uploadtree_fk FROM clearing_decision 808 WHERE decision_type=$'.($a+2).
' AND uploadtree_fk=UploadTreeView.uploadtree_pk)';
810 $params[] = $decisionMark;
811 $sql = $uploadTreeProxy->asCte()
812 .
' DELETE FROM clearing_decision WHERE clearing_decision_pk IN ( 813 SELECT clearing_decision_pk 814 FROM clearing_decision cd INNER JOIN ( 815 SELECT MAX(date_added) AS date_added, uploadtree_fk 816 FROM clearing_decision WHERE uploadtree_fk IN ( 817 SELECT uploadtree_pk FROM UploadTreeView) GROUP BY uploadtree_fk) cd2 ON cd.uploadtree_fk = cd2.uploadtree_fk 818 AND cd.date_added = cd2.date_added AND decision_type = $'.($a+1).
')';
820 $this->
dbManager->prepare($statementName, $sql);
821 $res = $this->
dbManager->execute($statementName,$params);
832 $statementName = __METHOD__ ;
833 $params = array($itemTreeBounds->
getLeft(), $itemTreeBounds->
getRight());
834 $condition =
"ut.lft BETWEEN $1 AND $2";
835 $decisionsCte = $this->getRelevantDecisionsCte($itemTreeBounds, $groupId, $onlyCurrent=
true, $statementName, $params, $condition);
836 if (!$removeDecision) {
839 $params[] = $groupId;
840 $params[] = $decisionMark;
841 $params[] = DecisionScopes::ITEM;
842 $this->
dbManager->prepare($statementName, $decisionsCte
843 .
' INSERT INTO clearing_decision (uploadtree_fk,pfile_fk,user_fk,group_fk,decision_type,scope) 844 SELECT itemid,pfile_id, $'.$a.
', $'.($a+1).
', $'.($a+2).
', $'.($a+3).
' 845 FROM allDecs ad WHERE type_id != $'.($a+2));
847 $params[] = $decisionMark;
849 $this->
dbManager->prepare($statementName, $decisionsCte
850 .
' DELETE FROM clearing_decision WHERE decision_type = $'.$a.
' 851 AND clearing_decision_pk IN ( 852 SELECT id FROM allDecs WHERE type_id = $'.$a.
')');
854 $res = $this->
dbManager->execute($statementName,$params);
866 $sql =
"SELECT rf_fk FROM upload_clearing_license WHERE upload_fk=$1 AND group_fk=$2";
868 $res = $this->
dbManager->execute($stmt,array($uploadId,$groupId));
870 while ($row = $this->
dbManager->fetchArray($res)) {
871 $ids[$row[
'rf_fk']] = $row[
'rf_fk'];
884 $this->
dbManager->insertTableRow(
'upload_clearing_license',
885 array(
'upload_fk'=>$uploadId,
'group_fk'=>$groupId,
'rf_fk'=>$licenseId));
895 $this->
dbManager->getSingleRow(
'DELETE FROM upload_clearing_license WHERE upload_fk=$1 AND group_fk=$2 AND rf_fk=$3',
896 array($uploadId,$groupId,$licenseId));
907 if (!empty($decisionMark)) {
908 $decisionMark = DecisionTypes::DO_NOT_USE;
910 $decisionMark = DecisionTypes::IRRELEVANT;
912 $statementName = __METHOD__;
914 $decisionsCte = $this->getRelevantDecisionsCte($itemTreeBounds, $groupId, $onlyCurrent, $statementName, $params);
915 $params[] = $decisionMark;
916 $sql =
"$decisionsCte 918 itemid as uploadtree_pk, 919 lr.rf_shortname AS shortname, 922 LEFT JOIN clearing_decision_event cde ON cde.clearing_decision_fk = decision.id 923 LEFT JOIN clearing_event ce ON ce.clearing_event_pk = cde.clearing_event_fk 924 LEFT JOIN license_ref lr ON lr.rf_pk = ce.rf_fk 925 WHERE type_id=$".count($params);
926 $this->
dbManager->prepare($statementName, $sql);
927 $res = $this->
dbManager->execute($statementName, $params);
928 $irrelevantFiles = $this->
dbManager->fetchAll($res);
930 return $irrelevantFiles;
942 $sql =
"SELECT jq_args FROM upload_reuse, jobqueue, job 943 WHERE upload_fk=$1 AND group_fk=$2 944 AND EXISTS(SELECT * FROM group_user_member gum WHERE gum.group_fk=upload_reuse.group_fk AND gum.user_fk=$3) 945 AND jq_type=$4 AND jq_job_fk=job_pk 946 AND job_upload_fk=reused_upload_fk AND job_group_fk=reused_group_fk";
948 $res = $this->
dbManager->execute($stmt,array($uploadId, $groupId, $userId,
'monkbulk'));
949 while ($row= $this->
dbManager->fetchArray($res)) {
950 $bulkIds = array_merge($bulkIds,explode(
"\n", $row[
'jq_args']));
953 if (empty($onlyCount)) {
954 return array_unique($bulkIds);
956 return count(array_unique($bulkIds));
969 $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId);
973 $cte = $this->getRelevantDecisionsCte($itemTreeBounds, $groupId,
true,
974 $statementName, $params);
976 $statementName = __METHOD__ . $statementName;
977 $sql =
"$cte SELECT COUNT(*) AS cnt FROM decision WHERE type_id <> ".DecisionTypes::TO_BE_DISCUSSED;
979 $clearedCounter = $this->
dbManager->getSingleRow($sql, $params,
981 return $clearedCounter[
'cnt'];
993 $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
994 $scanJobProxy =
new ScanJobProxy($GLOBALS[
'container']->
get(
'dao.agent'), $uploadId);
995 $scanJobProxy->createAgentStatus(array_keys(AgentRef::AGENT_LIST));
996 $latestAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
997 $agentIds =
"{" . implode(
",", $latestAgentIds) .
"}";
999 $globalScope = DecisionScopes::REPO;
1000 $params = array($groupId, $uploadId, $agentIds);
1001 $statement = __METHOD__ .
"." . $uploadTreeTable;
1004 SELECT DISTINCT ON (ut.uploadtree_pk) * FROM $uploadTreeTable AS ut 1005 LEFT JOIN license_file AS lf 1006 ON lf.pfile_fk = ut.pfile_fk 1007 AND lf.agent_fk = ANY($3::int[]) 1008 AND lf.rf_fk NOT IN (SELECT rf_pk FROM license_ref 1009 WHERE rf_shortname = ANY(VALUES('No_license_found'),('Void')) 1011 AND lf.rf_fk IS NOT NULL 1012 LEFT JOIN clearing_decision AS cd ON 1013 (ut.uploadtree_pk = cd.uploadtree_fk) 1014 OR (ut.pfile_fk = cd.pfile_fk AND cd.scope = $globalScope) 1015 AND cd.group_fk = $1 1016 WHERE ut.upload_fk = $2 AND ( 1018 WHEN lf.fl_pk IS NULL AND cd.clearing_decision_pk IS NULL 1024 SELECT count(*) AS cnt 1025 FROM (SELECT DISTINCT uploadtree_pk FROM allDecs) AS no_license_uploadtree;";
1026 $foundCounter = $this->
dbManager->getSingleRow($sql, $params, $statement);
1027 return $foundCounter[
'cnt'];
1036 if (!empty($uploadId)) {
1037 $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
1038 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
1039 $params[] = $itemTreeBounds->
getLeft();
1040 $params[] = $itemTreeBounds->
getRight();
1041 $condition =
"UT.lft BETWEEN $1 AND $2";
1042 $uploadtreeStatement =
" uploadtree_fk IN (SELECT uploadtree_pk FROM $uploadTreeTableName UT WHERE $condition)";
1044 $params = array($uploadTreeId);
1045 $uploadtreeStatement =
" uploadtree_fk = $1";
1048 $sql =
"WITH latestEvents AS ( 1049 SELECT rf_fk, date_added, removed FROM ( 1050 SELECT rf_fk, date_added, removed, row_number() 1051 OVER (PARTITION BY rf_fk ORDER BY date_added DESC) AS ROWNUM 1052 FROM clearing_event WHERE $uploadtreeStatement) SORTABLE 1053 WHERE ROWNUM = 1 ORDER BY rf_fk) 1054 SELECT count(*) FROM license_candidate WHERE license_candidate.rf_pk IN 1055 (SELECT rf_fk FROM latestEvents WHERE removed=false);";
1056 $countCandidate = $this->
dbManager->getSingleRow($sql,
1057 $params, $sqlLog = __METHOD__);
1059 return $countCandidate[
'count'];
1068 $statementName = __METHOD__ . $uploadId;
1070 $sql =
"WITH latestDecisions AS ( 1071 SELECT clearing_decision_pk FROM ( 1072 SELECT clearing_decision_pk, uploadtree_fk, date_added, row_number() 1073 OVER (PARTITION BY uploadtree_fk ORDER BY date_added DESC) AS ROWNUM 1074 FROM clearing_decision WHERE uploadtree_fk IN 1075 (SELECT uploadtree_pk FROM uploadtree WHERE upload_fk = $1)) SORTABLE 1076 WHERE ROWNUM = $2 ORDER BY uploadtree_fk) 1077 UPDATE clearing_decision SET scope = $2 WHERE clearing_decision_pk IN ( 1078 SELECT clearing_decision_pk FROM latestDecisions) RETURNING clearing_decision_pk";
1080 $countUpdated = $this->
dbManager->getSingleRow($sql,
1081 array($uploadId, DecisionScopes::REPO), $statementName);
1083 return count($countUpdated);
getFileClearingsFolder(ItemTreeBounds $itemTreeBounds, $groupId, $includeSubFolders=true, $onlyCurrent=true)
markDirectoryAsDecisionTypeIfUserEdited(ItemTreeBounds $itemTreeBounds, $groupId, $userId, $removeDecision=false, $decisionMark=DecisionTypes::IRRELEVANT)
getCandidateLicenseCountForCurrentDecisions($uploadTreeId, $uploadId=0)
getTotalDecisionCount($uploadId, $groupId)
getRelevantClearingDecision(ItemTreeBounds $itemTreeBounds, $groupId)
getMainLicenseIds($uploadId, $groupId)
getClearedLicenses(ItemTreeBounds $itemTreeBounds, $groupId)
removeWipClearingDecision($uploadTreeId, $groupId)
deleteDecisionTypeFromDirectory(ItemTreeBounds $itemTreeBounds, $groupId, $userId, $decisionMark)
getFileClearings(ItemTreeBounds $itemTreeBounds, $groupId, $onlyCurrent=true, $forClearingHistory=false)
marklocalDecisionsAsGlobal($uploadId)
insertClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, $isRemoved, $type=ClearingEventTypes::USER, $reportInfo= '', $comment= '', $acknowledgement= '', $jobId=0)
buildClearingEvent($eventId, $userId, $groupId, $licenseRef, $licenseIsRemoved, $type, $reportInfo, $comment, $acknowledgement)
getRelevantClearingEvents($itemTreeBounds, $groupId, $includeSubFolders=true)
updateClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, $what, $changeTo)
makeMainLicense($uploadId, $groupId, $licenseId)
getPreviousBulkIds($uploadId, $groupId, $userId, $onlyCount=0)
markDirectoryAsDecisionType(ItemTreeBounds $itemTreeBounds, $groupId, $userId, $decisionMark)
getFilesForDecisionTypeFolderLevel(ItemTreeBounds $itemTreeBounds, $groupId, $onlyCurrent=true, $decisionMark="")
__construct(DbManager $dbManager, UploadDao $uploadDao)
fo_dbManager * dbManager
fo_dbManager object
getDecisionsFromCte($decisionsCte, $statementName, $params, $forClearingHistory=false)
getBulkHistory(ItemTreeBounds $itemTreeBound, $groupId, $onlyTried=true)
markDecisionAsWip($uploadTreeId, $userId, $groupId)
getClearedLicenseIdAndMultiplicities(ItemTreeBounds $itemTreeBounds, $groupId)
getClearingDecisionsCount($uploadId, $groupId)
createDecisionFromEvents($uploadTreeId, $userId, $groupId, $decType, $scope, $eventIds)
markDirectoryAsDecisionTypeIfScannerDetected(ItemTreeBounds $itemTreeBounds, $groupId, $userId, $removeDecision=false, $decisionMark=DecisionTypes::IRRELEVANT)
removeMainLicense($uploadId, $groupId, $licenseId)