ILIAS  release_8 Revision v8.24
class.ilWebDAVLocksRepository.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
26{
27 protected ilDBInterface $db;
28
29 private string $lock_table = 'dav_lock';
30
31 public function __construct(ilDBInterface $db)
32 {
33 $this->db = $db;
34 }
35
36 public function checkIfLockExistsInDB(string $token): bool
37 {
38 $select_query = "SELECT SELECT EXISTS(SELECT 1 FROM $this->lock_table WHERE token = " .
39 $this->db->quote($token, 'text') . ") AS count";
40 $select_result = $this->db->query($select_query);
41 $select_result->numRows();
42 $row = $this->db->fetchAssoc($select_result);
43 if (isset($row)) {
44 return true;
45 }
46 return false;
47 }
48
50 {
51 $query = "SELECT obj_id, ilias_owner, dav_owner, expires, depth, type, scope FROM $this->lock_table"
52 . " WHERE token = " . $this->db->quote($token, 'text')
53 . " AND expires > " . $this->db->quote(time(), 'integer');
54
55 $select_result = $this->db->query($query);
56 $row = $this->db->fetchAssoc($select_result);
57
58 if ($row) {
59 return new ilWebDAVLockObject(
60 $token,
61 (int) $row['obj_id'],
62 (int) $row['ilias_owner'],
63 $row['dav_owner'],
64 (int) $row['expires'],
65 (int) $row['depth'],
66 $row['type'],
67 (int) $row['scope']
68 );
69 }
70
71 return null;
72 }
73
74 public function getLockObjectWithObjIdFromDB(int $obj_id): ?ilWebDAVLockObject
75 {
76 $query = "SELECT token, ilias_owner, dav_owner, expires, depth, type, scope FROM $this->lock_table WHERE obj_id = "
77 . $this->db->quote($obj_id, 'integer')
78 . " AND expires > " . $this->db->quote(time(), 'integer');
79 $select_result = $this->db->query($query);
80 $row = $this->db->fetchAssoc($select_result);
81
82 if ($row) {
83 return new ilWebDAVLockObject(
84 $row['token'],
85 $obj_id,
86 (int) $row['ilias_owner'],
87 $row['dav_owner'],
88 (int) $row['expires'],
89 (int) $row['depth'],
90 $row['type'],
91 (int) $row['scope']
92 );
93 }
94
95 return null;
96 }
97
98 public function saveLockToDB(ilWebDAVLockObject $ilias_lock): void
99 {
100 $this->db->insert($this->lock_table, array(
101 'token' => array('text', $ilias_lock->getToken()),
102 'obj_id' => array('integer', $ilias_lock->getObjId()),
103 'ilias_owner' => array('integer', $ilias_lock->getIliasOwner()),
104 'dav_owner' => array('text', $ilias_lock->getDavOwner()),
105 'expires' => array('integer', $ilias_lock->getExpires()),
106 'depth' => array('integer', $ilias_lock->getDepth()),
107 'type' => array('text', $ilias_lock->getType()),
108 'scope' => array('integer', $ilias_lock->getScope())
109 ));
110 }
111
112 public function removeLockWithTokenFromDB(string $token): int
113 {
114 return $this->db->manipulate("DELETE FROM $this->lock_table WHERE token = " . $this->db->quote($token, "integer"));
115 }
116
117 public function purgeExpiredLocksFromDB(): int
118 {
119 return $this->db->manipulate("DELETE FROM $this->lock_table WHERE expires < " . $this->db->quote(time(), 'integer'));
120 }
121
122 public function updateLocks(int $old_obj_id, int $new_obj_id): int
123 {
124 return $this->db->update(
125 $this->lock_table,
126 ["obj_id" => ["integer", $new_obj_id]],
127 ["obj_id" => ["integer", $old_obj_id]]
128 );
129 }
130}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveLockToDB(ilWebDAVLockObject $ilias_lock)
updateLocks(int $old_obj_id, int $new_obj_id)
Interface ilDBInterface.
$query
$token
Definition: xapitoken.php:70