ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilWebDAVLockBackend.php
Go to the documentation of this file.
1<?php
2use Sabre\DAV\Locks;
3use Sabre\DAV\Exception;
4
16class ilWebDAVLockBackend extends Sabre\DAV\Locks\Backend\AbstractBackend
17{
19 protected $db_manager;
20
22 protected $repo_helper;
23
25 protected $obj_dav_helper;
26
29
36 {
37 global $DIC;
38
39 $this->db_manager = $db_manager == null ? new ilWebDAVDBManager($DIC->database()) : $db_manager;
40 $this->repo_helper = $repo_helper == null ? new ilWebDAVRepositoryHelper($DIC->access(), $DIC->repositoryTree()) : $repo_helper;
41 $this->obj_dav_helper = new ilWebDAVObjDAVHelper($this->repo_helper);
42 $this->uri_path_resolver = new ilWebDAVUriPathResolver($this->repo_helper);
43 $this->user = $DIC->user();
44 }
45
53 public function getLocks($uri, $returnChildLocks)
54 {
55 $sabre_locks = array();
56
57 // Get locks on given uri
58 try {
59 $ref_id = $this->uri_path_resolver->getRefIdForWebDAVPath($uri);
60
61 $obj_id = $this->repo_helper->getObjectIdFromRefId($ref_id);
62 $lock_on_obj = $this->getLocksOnObjectId($obj_id);
63
64 if ($lock_on_obj != false) {
65 $sabre_locks[] = $lock_on_obj->getAsSabreDavLock($uri);
66 }
67
68 // Get locks on childs
69 if ($returnChildLocks) {
70 $sabre_locks = $this->getLocksRecursive($sabre_locks, $ref_id, $uri);
71 }
72 } catch (Exception\NotFound $e) {
73 return $sabre_locks;
74 }
75
76 return $sabre_locks;
77 }
78
87 protected function getLocksRecursive($sabre_locks, $ref_id, $uri)
88 {
89 foreach ($this->repo_helper->getChildrenOfRefId($ref_id) as $child_ref) {
90 // Only get locks of DAVable objects. Because not DAVable objects won't be lockable anyway
91 $child_obj_id = $this->repo_helper->getObjectIdFromRefId($child_ref);
92 if ($this->obj_dav_helper->isDAVableObject($child_obj_id, false)) {
93 // Get Locks of this object
94 $title = $this->repo_helper->getObjectTitleFromObjId($child_obj_id, true);
95 $child_ilias_locks = $this->getLocksOnObjectId($child_obj_id);
96 if ($child_ilias_locks != false) {
97 foreach ($child_ilias_locks as $lock) {
98 $sabre_locks[] = $lock->getAsSabreDavLock($uri . '/' . $title);
99 }
100 }
101
102 // Get locks of child objects
103 $sabre_locks = $this->getLocksRecursive($sabre_locks, $child_ref, $uri . $title . '/');
104 }
105 }
106
107 return $sabre_locks;
108 }
109
114 public function unlock($uri, Sabre\DAV\Locks\LockInfo $lockInfo)
115 {
116 $ilias_lock = $this->db_manager->getLockObjectWithTokenFromDB($lockInfo->token);
117
118 if ($ilias_lock && $ilias_lock->getIliasOwner() == $this->user->getId()) {
119 $this->db_manager->removeLockWithTokenFromDB($lockInfo->token);
120 } else {
121 throw new Exception\Forbidden();
122 }
123 }
124
131 public function lock($uri, Sabre\DAV\Locks\LockInfo $lock_info)
132 {
133 try {
134 $ref_id = $this->uri_path_resolver->getRefIdForWebDAVPath($uri);
135
136 if ($ref_id > 0 && $this->repo_helper->checkAccess('write', $ref_id)) {
137 $obj_id = $this->repo_helper->getObjectIdFromRefId($ref_id);
138 $ilias_lock = ilWebDAVLockObject::createFromSabreLock($lock_info, $obj_id);
139 $this->db_manager->saveLockToDB($ilias_lock);
140 } else {
141 throw new Exception\Forbidden();
142 }
143 } catch (Exception\NotFound $e) {
144 if ($e->getCode() == -1) {
145 return;
146 } else {
147 throw $e;
148 }
149 }
150 }
151
152
159 public function getLocksOnObjectId(int $obj_id)
160 {
161 try {
162 return $this->db_manager->getLockObjectWithObjIdFromDB($obj_id);
163 } catch (Exception $e) {
164 }
165 }
166}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Class ilWebDAVDBManager.
Class ilWebDAVLockBackend.
getLocksOnObjectId(int $obj_id)
Returns lock on given object.
lock($uri, Sabre\DAV\Locks\LockInfo $lock_info)
Function for the sabreDAV interface.
getLocks($uri, $returnChildLocks)
This function returns all locks and child locks as SabreDAV lock objects It is needed for sabreDAV to...
getLocksRecursive($sabre_locks, $ref_id, $uri)
Iterates recursive through the ilias tree to search for locked objects.
unlock($uri, Sabre\DAV\Locks\LockInfo $lockInfo)
__construct($db_manager=null, ilWebDAVRepositoryHelper $repo_helper=null)
Constructor with dependency injection.
static createFromSabreLock(Sabre\DAV\Locks\LockInfo $lock_info, $obj_id)
Creates an ILIAS lock object from a sabreDAV lock object.
Class ilWebDAVObjDAVHelper.
Class ilWebDAVRepositoryHelper.
Class ilWebDAVUriPathResolver.
global $DIC
Definition: goto.php:24