ILIAS  release_8 Revision v8.24
class.ilWebDAVLocksBackend.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use Sabre\DAV\Exception\NotFound;
22use Sabre\DAV\Locks\Backend\AbstractBackend;
23use Sabre\DAV\Exception;
24use Sabre\DAV\Locks\LockInfo;
25
29class ilWebDAVLocksBackend extends AbstractBackend
30{
35 protected ilObjUser $user;
36
37 public function __construct(
43 ) {
44 $this->wedav_locks_repository = $wedav_locks_repository;
45 $this->webdav_repository_helper = $webdav_repository_helper;
46 $this->webdav_object_factory = $webdav_object_factory;
47 $this->webdav_path_resolver = $webdav_path_resolver;
48 $this->user = $user;
49 }
50
56 public function getLocks($uri, $returnChildLocks): array
57 {
58 $sabre_locks = [];
59
60 try {
61 $ref_id = $this->webdav_path_resolver->getRefIdForWebDAVPath($uri);
62
63 $obj_id = $this->webdav_repository_helper->getObjectIdFromRefId($ref_id);
64 $lock_on_obj = $this->getLocksOnObjectId($obj_id);
65
66 if (!is_null($lock_on_obj)) {
67 $sabre_locks[] = $lock_on_obj->getAsSabreDavLock($uri);
68 }
69
70 if ($returnChildLocks) {
71 $sabre_locks = $this->getLocksRecursive($sabre_locks, $ref_id, $uri);
72 }
73 } catch (Exception\NotFound $e) {
74 }
75
76 return $sabre_locks;
77 }
78
83 protected function getLocksRecursive(array $sabre_locks, int $ref_id, string $uri): array
84 {
85 foreach ($this->webdav_repository_helper->getChildrenOfRefId($ref_id) as $child_ref) {
86 try {
87 $child_obj_id = $this->webdav_repository_helper->getObjectIdFromRefId($child_ref);
88 $child_obj = $this->webdav_object_factory->retrieveDAVObjectByRefID($child_ref);
89
90 $child_ilias_lock = $this->getLocksOnObjectId($child_obj_id);
91 if (!is_null($child_ilias_lock)) {
92 $sabre_locks[] = $child_ilias_lock->getAsSabreDavLock($uri . '/' . $child_obj->getName());
93 }
94
95 $sabre_locks = $this->getLocksRecursive($sabre_locks, $child_ref, $uri . $child_obj->getName() . '/');
96 } catch (ilWebDAVNotDavableException | NotFound | RuntimeException $e) {
97 }
98 }
99
100 return $sabre_locks;
101 }
102
107 public function unlock($uri, LockInfo $lockInfo): bool
108 {
109 $ilias_lock = $this->wedav_locks_repository->getLockObjectWithTokenFromDB($lockInfo->token);
110
111 if (!is_null($ilias_lock) && $ilias_lock->getIliasOwner() == $this->user->getId()) {
112 $this->wedav_locks_repository->removeLockWithTokenFromDB($lockInfo->token);
113 return true;
114 } else {
115 throw new Exception\Forbidden();
116 }
117 }
118
124 public function lock($uri, LockInfo $lock_info): bool
125 {
126 try {
127 $ref_id = $this->webdav_path_resolver->getRefIdForWebDAVPath($uri);
128
129 if ($ref_id > 0 && $this->webdav_repository_helper->checkAccess('write', $ref_id)) {
130 $obj_id = $this->webdav_repository_helper->getObjectIdFromRefId($ref_id);
131 $ilias_lock = new ilWebDAVLockObject(
132 $lock_info->token,
133 $obj_id,
134 $this->user->getId(),
135 $lock_info->owner,
136 time() + 360,
137 $lock_info->depth,
138 'w',
139 $lock_info->scope
140 );
141 $this->wedav_locks_repository->saveLockToDB($ilias_lock);
142 return true;
143 } else {
144 throw new Exception\Forbidden();
145 }
146 } catch (Exception\NotFound $e) {
147 if ($e->getCode() == -1) {
148 return false;
149 } else {
150 throw $e;
151 }
152 }
153 }
154
155 public function getLocksOnObjectId(int $obj_id): ?ilWebDAVLockObject
156 {
157 try {
158 return $this->wedav_locks_repository->getLockObjectWithObjIdFromDB($obj_id);
159 } catch (Exception $e) {
160 }
161 }
162}
User class.
ilWebDAVLocksRepository $wedav_locks_repository
unlock($uri, LockInfo $lockInfo)
ilWebDAVLockUriPathResolver $webdav_path_resolver
ilWebDAVObjFactory $webdav_object_factory
getLocksRecursive(array $sabre_locks, int $ref_id, string $uri)
__construct(ilWebDAVLocksRepository $wedav_locks_repository, ilWebDAVRepositoryHelper $webdav_repository_helper, ilWebDAVObjFactory $webdav_object_factory, ilWebDAVLockUriPathResolver $webdav_path_resolver, ilObjUser $user)
ilWebDAVRepositoryHelper $webdav_repository_helper
lock($uri, LockInfo $lock_info)
getLocks($uri, $returnChildLocks)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67