ILIAS  release_8 Revision v8.23
class.ilWebDAVLocksBackend.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
25 
29 class ilWebDAVLocksBackend extends AbstractBackend
30 {
35  protected ilObjUser $user;
36 
37  public function __construct(
38  ilWebDAVLocksRepository $wedav_locks_repository,
39  ilWebDAVRepositoryHelper $webdav_repository_helper,
40  ilWebDAVObjFactory $webdav_object_factory,
41  ilWebDAVLockUriPathResolver $webdav_path_resolver,
42  ilObjUser $user
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 }
ilWebDAVLockUriPathResolver $webdav_path_resolver
ilWebDAVLocksRepository $wedav_locks_repository
ilWebDAVRepositoryHelper $webdav_repository_helper
getLocksRecursive(array $sabre_locks, int $ref_id, string $uri)
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilWebDAVObjFactory $webdav_object_factory
lock($uri, LockInfo $lock_info)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLocks($uri, $returnChildLocks)
unlock($uri, LockInfo $lockInfo)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilWebDAVLocksRepository $wedav_locks_repository, ilWebDAVRepositoryHelper $webdav_repository_helper, ilWebDAVObjFactory $webdav_object_factory, ilWebDAVLockUriPathResolver $webdav_path_resolver, ilObjUser $user)