ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilWebDAVLocksRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  private string $lock_table = 'dav_lock';
28 
29  public function __construct(protected ilDBInterface $db)
30  {
31  }
32 
33  public function checkIfLockExistsInDB(string $token): bool
34  {
35  $select_query = "SELECT SELECT EXISTS(SELECT 1 FROM $this->lock_table WHERE token = " .
36  $this->db->quote($token, 'text') . ") AS count";
37  $select_result = $this->db->query($select_query);
38  $select_result->numRows();
39  $row = $this->db->fetchAssoc($select_result);
40  return isset($row);
41  }
42 
44  {
45  $query = "SELECT obj_id, ilias_owner, dav_owner, expires, depth, type, scope FROM $this->lock_table"
46  . " WHERE token = " . $this->db->quote($token, 'text')
47  . " AND expires > " . $this->db->quote(time(), 'integer');
48 
49  $select_result = $this->db->query($query);
50  $row = $this->db->fetchAssoc($select_result);
51 
52  if ($row) {
53  return new ilWebDAVLockObject(
54  $token,
55  (int) $row['obj_id'],
56  (int) $row['ilias_owner'],
57  $row['dav_owner'],
58  (int) $row['expires'],
59  (int) $row['depth'],
60  $row['type'],
61  (int) $row['scope']
62  );
63  }
64 
65  return null;
66  }
67 
68  public function getLockObjectWithObjIdFromDB(int $obj_id): ?ilWebDAVLockObject
69  {
70  $query = "SELECT token, ilias_owner, dav_owner, expires, depth, type, scope FROM $this->lock_table WHERE obj_id = "
71  . $this->db->quote($obj_id, 'integer')
72  . " AND expires > " . $this->db->quote(time(), 'integer');
73  $select_result = $this->db->query($query);
74  $row = $this->db->fetchAssoc($select_result);
75 
76  if ($row) {
77  return new ilWebDAVLockObject(
78  $row['token'],
79  $obj_id,
80  (int) $row['ilias_owner'],
81  $row['dav_owner'],
82  (int) $row['expires'],
83  (int) $row['depth'],
84  $row['type'],
85  (int) $row['scope']
86  );
87  }
88 
89  return null;
90  }
91 
92  public function saveLockToDB(ilWebDAVLockObject $ilias_lock): void
93  {
94  $this->db->insert($this->lock_table, [
95  'token' => ['text', $ilias_lock->getToken()],
96  'obj_id' => ['integer', $ilias_lock->getObjId()],
97  'ilias_owner' => ['integer', $ilias_lock->getIliasOwner()],
98  'dav_owner' => ['text', $ilias_lock->getDavOwner()],
99  'expires' => ['integer', $ilias_lock->getExpires()],
100  'depth' => ['integer', $ilias_lock->getDepth()],
101  'type' => ['text', $ilias_lock->getType()],
102  'scope' => ['integer', $ilias_lock->getScope()]
103  ]);
104  }
105 
106  public function removeLockWithTokenFromDB(string $token): int
107  {
108  return $this->db->manipulate(
109  "DELETE FROM $this->lock_table WHERE token = " . $this->db->quote($token, "integer")
110  );
111  }
112 
113  public function purgeExpiredLocksFromDB(): int
114  {
115  return $this->db->manipulate(
116  "DELETE FROM $this->lock_table WHERE expires < " . $this->db->quote(time(), 'integer')
117  );
118  }
119 
120  public function updateLocks(int $old_obj_id, int $new_obj_id): int
121  {
122  return $this->db->update(
123  $this->lock_table,
124  ["obj_id" => ["integer", $new_obj_id]],
125  ["obj_id" => ["integer", $old_obj_id]]
126  );
127  }
128 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(protected ilDBInterface $db)
$token
Definition: xapitoken.php:70
updateLocks(int $old_obj_id, int $new_obj_id)
saveLockToDB(ilWebDAVLockObject $ilias_lock)