8 namespace Fossology\Lib\Proxy;
17 const PRIO_COLUMN =
'priority';
24 public function __construct($groupId, $userPerm,
DbManager $dbManager, $doSanity=
true)
26 $this->groupId = $groupId;
27 $this->userPerm = $userPerm;
34 public function sanity()
37 $sql =
'INSERT INTO upload_clearing (upload_fk,group_fk,status_fk,'.self::PRIO_COLUMN.
') '
38 .
' SELECT upload_pk,$1,$2,upload_pk as '.self::PRIO_COLUMN
39 .
' FROM upload LEFT JOIN upload_clearing ON upload_pk=upload_fk AND group_fk=$1'
40 .
' WHERE upload_clearing.upload_fk IS NULL'
41 .
' AND (public_perm>=$3 OR EXISTS(SELECT * FROM perm_upload WHERE perm_upload.upload_fk = upload_pk AND group_fk=$1))';
42 $this->
dbManager->getSingleRow($sql, $params);
45 public function updateTable($columnName, $uploadId, $value)
47 if ($columnName ==
'status_fk') {
48 $this->changeStatus($uploadId, $value);
49 }
else if ($columnName ==
'assignee' && $this->userPerm) {
50 $sql =
"UPDATE upload_clearing SET assignee=$1 WHERE group_fk=$2 AND upload_fk=$3";
51 $this->
dbManager->getSingleRow($sql, array($value, $this->groupId, $uploadId), $sqlLog = __METHOD__);
54 throw new \Exception(
'invalid column');
58 protected function changeStatus($uploadId, $newStatus)
60 if ($newStatus == UploadStatus::REJECTED && $this->userPerm) {
61 $this->setStatusAndComment($uploadId, $newStatus, $commentText =
'');
62 }
else if ($newStatus == UploadStatus::REJECTED) {
63 throw new \Exception(
'missing permission');
64 }
else if ($this->userPerm) {
65 $sql =
"UPDATE upload_clearing SET status_fk=$1 WHERE group_fk=$2 AND upload_fk=$3";
66 $this->
dbManager->getSingleRow($sql, array($newStatus, $this->groupId, $uploadId), __METHOD__ .
'.advisor');
68 $sql =
"UPDATE upload_clearing SET status_fk=$1 WHERE group_fk=$2 AND upload_fk=$3 AND status_fk<$4";
69 $params = array($newStatus, $this->groupId, $uploadId, UploadStatus::REJECTED);
70 $this->
dbManager->getSingleRow($sql, $params, __METHOD__ .
'.user');
72 if ($newStatus == UploadStatus::CLOSED || $newStatus == UploadStatus::REJECTED) {
77 public function setStatusAndComment($uploadId, $statusId, $commentText)
79 $sql =
"UPDATE upload_clearing SET status_fk=$1, status_comment=$2 WHERE group_fk=$3 AND upload_fk=$4";
80 $this->
dbManager->getSingleRow($sql, array($statusId, $commentText, $this->groupId, $uploadId), __METHOD__);
81 if ($statusId == UploadStatus::CLOSED || $statusId == UploadStatus::REJECTED) {
94 $sql =
"SELECT 1 as exists FROM upload_events WHERE upload_fk = $1 " .
96 $row = $this->
dbManager->getSingleRow($sql, [$uploadId],
97 __METHOD__ .
".exists");
98 if (empty($row) || empty($row[
"exists"])) {
99 $sql =
"INSERT INTO upload_events (upload_fk, event_type) VALUES ($1, " .
101 $this->
dbManager->getSingleRow($sql, [$uploadId],
102 __METHOD__ .
".insert");
114 $sql =
"SELECT 1 as exists FROM upload_events WHERE upload_fk = $1 " .
116 $row = $this->
dbManager->getSingleRow($sql, [$uploadId],
117 __METHOD__ .
".exists");
118 if (empty($row) || empty($row[
"exists"])) {
119 $sql =
"INSERT INTO upload_events (upload_fk, event_type) VALUES ($1, " .
121 $this->
dbManager->getSingleRow($sql, [$uploadId],
122 __METHOD__ .
".insert");
126 public function moveUploadToInfinity($uploadId, $top)
128 $fun = $top ?
'MAX('.self::PRIO_COLUMN.
')+1' :
'MIN('.self::PRIO_COLUMN.
')-1';
129 $sql =
"UPDATE upload_clearing SET ".self::PRIO_COLUMN.
"=(SELECT $fun FROM upload_clearing WHERE group_fk=$1)"
130 .
" WHERE group_fk=$1 AND upload_fk=$2";
132 array($this->groupId,$uploadId),
133 __METHOD__.($top?
'+':
'-'));
136 public function moveUploadBeyond($moveUpload, $beyondUpload)
139 $this->
dbManager->prepare($stmt = __METHOD__ .
'.get.single.Upload',
140 $sql=
'SELECT upload_fk,'.self::PRIO_COLUMN.
' FROM upload_clearing WHERE group_fk=$1 AND upload_fk=$2');
141 $movePoint = $this->
dbManager->getSingleRow($sql, array($this->groupId,$moveUpload), $stmt);
142 $beyondPoint = $this->
dbManager->getSingleRow($sql, array($this->groupId,$beyondUpload), $stmt);
144 if ($movePoint[self::PRIO_COLUMN] > $beyondPoint[self::PRIO_COLUMN]) {
145 $farPoint = $this->
dbManager->getSingleRow(
"SELECT MAX(".self::PRIO_COLUMN.
") m FROM upload_clearing WHERE group_fk=$1 AND ".self::PRIO_COLUMN.
"<$2",
146 array($this->groupId,$beyondPoint[self::PRIO_COLUMN]),
'get.upload.with.lower.priority');
147 $farPrio = $farPoint[
'm']!==
null ? $farPoint[
'm'] : $beyondPoint[self::PRIO_COLUMN]-1;
149 $farPoint = $this->
dbManager->getSingleRow(
"SELECT MIN(".self::PRIO_COLUMN.
") m FROM upload_clearing WHERE group_fk=$1 AND ".self::PRIO_COLUMN.
">$2",
150 array($this->groupId,$beyondPoint[self::PRIO_COLUMN]),
'get.upload.with.higher.priority');
151 $farPrio = $farPoint[
'm']!==
null ? $farPoint[
'm'] : $beyondPoint[self::PRIO_COLUMN]+1;
154 $newPriority = ($farPrio + $beyondPoint[self::PRIO_COLUMN]) / 2;
155 $this->
dbManager->getSingleRow(
'UPDATE upload_clearing SET '.self::PRIO_COLUMN.
'=$1 WHERE group_fk=$2 AND upload_fk=$3',
156 array($newPriority, $this->groupId, $moveUpload),
157 __METHOD__.
'.update.priority');
167 if (count($params)!=1) {
168 throw new \Exception(
'expected argument to be array with exactly one element for folderId');
170 if (! is_array($params[0])) {
171 $params[0] = [$params[0]];
173 $params[0] =
'{' . implode(
',', $params[0]) .
'}';
174 $params[] = $this->groupId;
177 INNER JOIN upload_clearing ON upload_pk = upload_clearing.upload_fk AND group_fk=$2
178 INNER JOIN uploadtree ON upload_pk = uploadtree.upload_fk AND upload.pfile_fk = uploadtree.pfile_fk
179 WHERE upload_pk IN (SELECT child_id FROM foldercontents WHERE foldercontents_mode&2 != 0 AND parent_fk = ANY($1::int[]) )
181 OR EXISTS(SELECT * FROM perm_upload WHERE perm_upload.upload_fk = upload_pk AND group_fk=$2))
183 AND lft IS NOT NULL';
193 $row = $this->
dbManager->getSingleRow(
"SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2",
194 array($uploadId, $this->groupId));
195 if (
false === $row) {
196 throw new \Exception(
"cannot find uploadId=$uploadId");
198 return $row[
'status_fk'];
Contains the constants and helpers for authentication of user.
This class contains the events for the upload_events table.
const UPLOAD_CLOSED_EVENT
getFolderPartialQuery(& $params)
setAssigneeEvent($uploadId)
fo_dbManager * dbManager
fo_dbManager object