27 const PRIO_COLUMN =
'priority';
34 public function __construct($groupId, $userPerm,
DbManager $dbManager, $doSanity=
true)
36 $this->groupId = $groupId;
37 $this->userPerm = $userPerm;
44 public function sanity()
47 $sql =
'INSERT INTO upload_clearing (upload_fk,group_fk,status_fk,'.self::PRIO_COLUMN.
') ' 48 .
' SELECT upload_pk,$1,$2,upload_pk as '.self::PRIO_COLUMN
49 .
' FROM upload LEFT JOIN upload_clearing ON upload_pk=upload_fk AND group_fk=$1' 50 .
' WHERE upload_clearing.upload_fk IS NULL' 51 .
' AND (public_perm>=$3 OR EXISTS(SELECT * FROM perm_upload WHERE perm_upload.upload_fk = upload_pk AND group_fk=$1))';
52 $this->
dbManager->getSingleRow($sql, $params);
56 public function updateTable($columnName, $uploadId, $value)
58 if ($columnName ==
'status_fk') {
59 $this->changeStatus($uploadId, $value);
60 }
else if ($columnName ==
'assignee' && $this->userPerm) {
61 $sql =
"UPDATE upload_clearing SET assignee=$1 WHERE group_fk=$2 AND upload_fk=$3";
62 $this->
dbManager->getSingleRow($sql, array($value, $this->groupId, $uploadId), $sqlLog = __METHOD__);
64 throw new \Exception(
'invalid column');
68 protected function changeStatus($uploadId, $newStatus)
70 if ($newStatus == UploadStatus::REJECTED && $this->userPerm) {
71 $this->setStatusAndComment($uploadId, $newStatus, $commentText =
'');
72 }
else if ($newStatus == UploadStatus::REJECTED) {
73 throw new \Exception(
'missing permission');
74 }
else if ($this->userPerm) {
75 $sql =
"UPDATE upload_clearing SET status_fk=$1 WHERE group_fk=$2 AND upload_fk=$3";
76 $this->
dbManager->getSingleRow($sql, array($newStatus, $this->groupId, $uploadId), __METHOD__ .
'.advisor');
78 $sql =
"UPDATE upload_clearing SET status_fk=$1 WHERE group_fk=$2 AND upload_fk=$3 AND status_fk<$4";
79 $params = array($newStatus, $this->groupId, $uploadId, UploadStatus::REJECTED);
80 $this->
dbManager->getSingleRow($sql, $params, __METHOD__ .
'.user');
84 public function setStatusAndComment($uploadId, $statusId, $commentText)
86 $sql =
"UPDATE upload_clearing SET status_fk=$1, status_comment=$2 WHERE group_fk=$3 AND upload_fk=$4";
87 $this->
dbManager->getSingleRow($sql, array($statusId, $commentText, $this->groupId, $uploadId), __METHOD__);
90 public function moveUploadToInfinity($uploadId, $top)
92 $fun = $top ?
'MAX('.self::PRIO_COLUMN.
')+1' :
'MIN('.self::PRIO_COLUMN.
')-1';
93 $sql =
"UPDATE upload_clearing SET ".self::PRIO_COLUMN.
"=(SELECT $fun FROM upload_clearing WHERE group_fk=$1)" 94 .
" WHERE group_fk=$1 AND upload_fk=$2";
96 array($this->groupId,$uploadId),
97 __METHOD__.($top?
'+':
'-'));
100 public function moveUploadBeyond($moveUpload, $beyondUpload)
103 $this->
dbManager->prepare($stmt = __METHOD__ .
'.get.single.Upload',
104 $sql=
'SELECT upload_fk,'.self::PRIO_COLUMN.
' FROM upload_clearing WHERE group_fk=$1 AND upload_fk=$2');
105 $movePoint = $this->
dbManager->getSingleRow($sql, array($this->groupId,$moveUpload), $stmt);
106 $beyondPoint = $this->
dbManager->getSingleRow($sql, array($this->groupId,$beyondUpload), $stmt);
108 if ($movePoint[self::PRIO_COLUMN] > $beyondPoint[self::PRIO_COLUMN]) {
109 $farPoint = $this->
dbManager->getSingleRow(
"SELECT MAX(".self::PRIO_COLUMN.
") m FROM upload_clearing WHERE group_fk=$1 AND ".self::PRIO_COLUMN.
"<$2",
110 array($this->groupId,$beyondPoint[self::PRIO_COLUMN]),
'get.upload.with.lower.priority');
111 $farPrio = $farPoint[
'm']!==null ? $farPoint[
'm'] : $beyondPoint[self::PRIO_COLUMN]-1;
113 $farPoint = $this->
dbManager->getSingleRow(
"SELECT MIN(".self::PRIO_COLUMN.
") m FROM upload_clearing WHERE group_fk=$1 AND ".self::PRIO_COLUMN.
">$2",
114 array($this->groupId,$beyondPoint[self::PRIO_COLUMN]),
'get.upload.with.higher.priority');
115 $farPrio = $farPoint[
'm']!==null ? $farPoint[
'm'] : $beyondPoint[self::PRIO_COLUMN]+1;
118 $newPriority = ($farPrio + $beyondPoint[self::PRIO_COLUMN]) / 2;
119 $this->
dbManager->getSingleRow(
'UPDATE upload_clearing SET '.self::PRIO_COLUMN.
'=$1 WHERE group_fk=$2 AND upload_fk=$3',
120 array($newPriority, $this->groupId, $moveUpload),
121 __METHOD__.
'.update.priority');
131 if (count($params)!=1) {
132 throw new \Exception(
'expected argument to be array with exactly one element for folderId');
134 $params[] = $this->groupId;
137 INNER JOIN upload_clearing ON upload_pk = upload_clearing.upload_fk AND group_fk=$2 138 INNER JOIN uploadtree ON upload_pk = uploadtree.upload_fk AND upload.pfile_fk = uploadtree.pfile_fk 139 WHERE upload_pk IN (SELECT child_id FROM foldercontents WHERE foldercontents_mode&2 != 0 AND parent_fk = $1 ) 141 OR EXISTS(SELECT * FROM perm_upload WHERE perm_upload.upload_fk = upload_pk AND group_fk=$2)) 143 AND lft IS NOT NULL';
154 $row = $this->
dbManager->getSingleRow(
"SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2",
155 array($uploadId, $this->groupId));
156 if (
false === $row) {
157 throw new \Exception(
"cannot find uploadId=$uploadId");
159 return $row[
'status_fk'];
getFolderPartialQuery(&$params)
fo_dbManager * dbManager
fo_dbManager object