ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
LocksRepositoryDB.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Lock;
22
24
30{
31 private string $lock_table = 'dav_lock';
32
33 public function __construct(protected ilDBInterface $db)
34 {
35 }
36
37 public function existsFor(string $token): bool
38 {
39 $select_query = "SELECT 1 FROM $this->lock_table WHERE token = "
40 . $this->db->quote($token, 'text');
41 $select_result = $this->db->query($select_query);
42 return $this->db->fetchAssoc($select_result) !== null;
43 }
44
45 public function maybeGetLockFromToken(string $token): ?LockObject
46 {
47 $query = "SELECT obj_id, ilias_owner, dav_owner, expires, depth, type, scope FROM $this->lock_table"
48 . " WHERE token = " . $this->db->quote($token, 'text')
49 . " AND expires > " . $this->db->quote(time(), 'integer');
50
51 $select_result = $this->db->query($query);
52 $row = $this->db->fetchAssoc($select_result);
53
54 if ($row) {
55 return new Lock(
56 $token,
57 (int) $row['obj_id'],
58 (int) $row['ilias_owner'],
59 $row['dav_owner'],
60 (int) $row['expires'],
61 (int) $row['depth'],
62 $row['type'] ?? '',
63 (int) $row['scope']
64 );
65 }
66
67 return null;
68 }
69
70 public function maybeGetLockFromObjId(int $obj_id): ?LockObject
71 {
72 $query = "SELECT token, ilias_owner, dav_owner, expires, depth, type, scope FROM $this->lock_table WHERE obj_id = "
73 . $this->db->quote($obj_id, 'integer')
74 . " AND expires > " . $this->db->quote(time(), 'integer');
75 $select_result = $this->db->query($query);
76 $row = $this->db->fetchAssoc($select_result);
77
78 if ($row) {
79 return new Lock(
80 $row['token'],
81 $obj_id,
82 (int) $row['ilias_owner'],
83 $row['dav_owner'],
84 (int) $row['expires'],
85 (int) $row['depth'],
86 $row['type'] ?? '',
87 (int) $row['scope']
88 );
89 }
90
91 return null;
92 }
93
94 public function save(LockObject $ilias_lock): void
95 {
96 $this->db->insert($this->lock_table, [
97 'token' => ['text', $ilias_lock->getToken()],
98 'obj_id' => ['integer', $ilias_lock->getObjId()],
99 'ilias_owner' => ['integer', $ilias_lock->getIliasOwner()],
100 'dav_owner' => ['text', $ilias_lock->getDavOwner()],
101 'expires' => ['integer', $ilias_lock->getExpires()],
102 'depth' => ['integer', $ilias_lock->getDepth()],
103 'type' => ['text', $ilias_lock->getType()],
104 'scope' => ['integer', $ilias_lock->getScope()]
105 ]);
106 }
107
108 public function remove(string $token): int
109 {
110 return $this->db->manipulate(
111 "DELETE FROM $this->lock_table WHERE token = " . $this->db->quote($token, 'text')
112 );
113 }
114
115 public function purgeExpired(): int
116 {
117 return $this->db->manipulate(
118 "DELETE FROM $this->lock_table WHERE expires < " . $this->db->quote(time(), 'integer')
119 );
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}
__construct(protected ilDBInterface $db)
updateLocks(int $old_obj_id, int $new_obj_id)
Interface ilDBInterface.
$token
Definition: xapitoken.php:67