ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWebDAVLockBackend.php
Go to the documentation of this file.
1<?php
4
5require_once 'libs/composer/vendor/autoload.php';
6
7require_once 'Services/WebDAV/classes/lock/class.ilWebDAVLockObject.php';
8require_once 'Services/WebDAV/classes/db/class.ilWebDAVDBManager.php';
9require_once 'Services/WebDAV/classes/tree/class.ilWebDAVUriPathResolver.php';
10require_once 'Services/WebDAV/classes/class.ilWebDAVRepositoryHelper.php';
11require_once 'Services/WebDAV/classes/class.ilWebDAVObjDAVHelper.php';
12
25{
27 protected $db_manager;
28
30 protected $repo_helper;
31
33 protected $obj_dav_helper;
34
37
44 {
45 global $DIC;
46
47 $this->db_manager = $db_manager == null ? new ilWebDAVDBManager($DIC->database()) : $db_manager;
48 $this->repo_helper = $repo_helper == null ? new ilWebDAVRepositoryHelper($DIC->access(), $DIC->repositoryTree()) : $repo_helper;
49 $this->obj_dav_helper = new ilWebDAVObjDAVHelper($this->repo_helper);
50 $this->uri_path_resolver = new ilWebDAVUriPathResolver($this->repo_helper);
51 $this->user = $DIC->user();
52 }
53
61 public function getLocks($uri, $returnChildLocks)
62 {
63 $sabre_locks = array();
64
65 // Get locks on given uri
66 try {
67 $ref_id = $this->uri_path_resolver->getRefIdForWebDAVPath($uri);
68
69 $obj_id = $this->repo_helper->getObjectIdFromRefId($ref_id);
70 $lock_on_obj = $this->getLocksOnObjectId($obj_id);
71
72 if ($lock_on_obj != false) {
73 $sabre_locks[] = $lock_on_obj->getAsSabreDavLock($uri);
74 }
75
76 // Get locks on childs
77 if ($returnChildLocks) {
78 $sabre_locks = $this->getLocksRecursive($sabre_locks, $ref_id, $uri);
79 }
80 } catch (Exception\NotFound $e) {
81 return $sabre_locks;
82 }
83
84 return $sabre_locks;
85 }
86
95 protected function getLocksRecursive($sabre_locks, $ref_id, $uri)
96 {
97 foreach ($this->repo_helper->getChildrenOfRefId($ref_id) as $child_ref) {
98 // Only get locks of DAVable objects. Because not DAVable objects won't be lockable anyway
99 $child_obj_id = $this->repo_helper->getObjectIdFromRefId($child_ref);
100 if ($this->obj_dav_helper->isDAVableObject($child_obj_id, false)) {
101 // Get Locks of this object
102 $title = $this->repo_helper->getObjectTitleFromObjId($child_obj_id, true);
103 $child_ilias_locks = $this->getLocksOnObjectId($child_obj_id);
104 if ($child_ilias_locks != false) {
105 foreach ($child_ilias_locks as $lock) {
106 $sabre_locks[] = $lock->getAsSabreDavLock($uri . '/' . $title);
107 }
108 }
109
110 // Get locks of child objects
111 $sabre_locks = $this->getLocksRecursive($sabre_locks, $child_ref, $uri . $title . '/');
112 }
113 }
114
115 return $sabre_locks;
116 }
117
122 public function unlock($uri, Sabre\DAV\Locks\LockInfo $lockInfo)
123 {
124 $ilias_lock = $this->db_manager->getLockObjectWithTokenFromDB($lockInfo->token);
125
126 if ($ilias_lock && $ilias_lock->getIliasOwner() == $this->user->getId()) {
127 $this->db_manager->removeLockWithTokenFromDB($lockInfo->token);
128 } else {
129 throw new Exception\Forbidden();
130 }
131 }
132
139 public function lock($uri, Sabre\DAV\Locks\LockInfo $lock_info)
140 {
141 try {
142 $ref_id = $this->uri_path_resolver->getRefIdForWebDAVPath($uri);
143
144 if ($ref_id > 0 && $this->repo_helper->checkAccess('write', $ref_id)) {
145 $obj_id = $this->repo_helper->getObjectIdFromRefId($ref_id);
146 $ilias_lock = ilWebDAVLockObject::createFromSabreLock($lock_info, $obj_id);
147 $this->db_manager->saveLockToDB($ilias_lock);
148 } else {
149 throw new Exception\Forbidden();
150 }
151 } catch (Exception\NotFound $e) {
152 if ($e->getCode() == -1) {
153 return;
154 } else {
155 throw $e;
156 }
157 }
158 }
159
160
167 public function getLocksOnObjectId(int $obj_id)
168 {
169 try {
170 return $this->db_manager->getLockObjectWithObjIdFromDB($obj_id);
171 } catch (Exception $e) {
172 }
173 }
174}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Main Exception class.
Definition: Exception.php:18
This is an Abstract clas for lock backends.
LockInfo class.
Definition: LockInfo.php:15
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: saml.php:7