ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilWebDAVLocksBackend.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
30 class ilWebDAVLocksBackend extends AbstractBackend
31 {
32  public function __construct(
33  protected ilWebDAVLocksRepository $wedav_locks_repository,
34  protected ilWebDAVRepositoryHelper $webdav_repository_helper,
35  protected ilWebDAVObjFactory $webdav_object_factory,
36  protected ilWebDAVLockUriPathResolver $webdav_path_resolver,
37  protected ilObjUser $user
38  ) {
39  }
40 
46  public function getLocks($uri, $returnChildLocks): array
47  {
48  $sabre_locks = [];
49 
50  try {
51  $ref_id = $this->webdav_path_resolver->getRefIdForWebDAVPath($uri);
52 
53  $obj_id = $this->webdav_repository_helper->getObjectIdFromRefId($ref_id);
54  $lock_on_obj = $this->getLocksOnObjectId($obj_id);
55 
56  if (!is_null($lock_on_obj)) {
57  $sabre_locks[] = $lock_on_obj->getAsSabreDavLock($uri);
58  }
59 
60  if ($returnChildLocks) {
61  $sabre_locks = $this->getLocksRecursive($sabre_locks, $ref_id, $uri);
62  }
63  } catch (NotFound) {
64  return [];
65  }
66 
67  return $sabre_locks;
68  }
69 
74  protected function getLocksRecursive(array $sabre_locks, int $ref_id, string $uri): array
75  {
76  foreach ($this->webdav_repository_helper->getChildrenOfRefId($ref_id) as $child_ref) {
77  try {
78  $child_obj_id = $this->webdav_repository_helper->getObjectIdFromRefId($child_ref);
79  $child_obj = $this->webdav_object_factory->retrieveDAVObjectByRefID($child_ref);
80 
81  $child_ilias_lock = $this->getLocksOnObjectId($child_obj_id);
82  if (!is_null($child_ilias_lock)) {
83  $sabre_locks[] = $child_ilias_lock->getAsSabreDavLock($uri . '/' . $child_obj->getName());
84  }
85 
86  $sabre_locks = $this->getLocksRecursive($sabre_locks, $child_ref, $uri . $child_obj->getName() . '/');
88  }
89  }
90 
91  return $sabre_locks;
92  }
93 
98  public function unlock($uri, LockInfo $lockInfo): bool
99  {
100  $ilias_lock = $this->wedav_locks_repository->getLockObjectWithTokenFromDB($lockInfo->token);
101 
102  if (!is_null($ilias_lock) && $ilias_lock->getIliasOwner() === $this->user->getId()) {
103  $this->wedav_locks_repository->removeLockWithTokenFromDB($lockInfo->token);
104  return true;
105  }
106  return false;
107 
108  throw new Forbidden();
109  }
110 
116  public function lock($uri, LockInfo $lock_info): bool
117  {
118  try {
119  $ref_id = $this->webdav_path_resolver->getRefIdForWebDAVPath($uri);
120 
121  if ($ref_id > 0 && $this->webdav_repository_helper->checkAccess('write', $ref_id)) {
122  $obj_id = $this->webdav_repository_helper->getObjectIdFromRefId($ref_id);
123  $ilias_lock = new ilWebDAVLockObject(
124  $lock_info->token,
125  $obj_id,
126  $this->user->getId(),
127  $lock_info->owner,
128  time() + 360,
129  $lock_info->depth,
130  'w',
131  $lock_info->scope
132  );
133  $this->wedav_locks_repository->saveLockToDB($ilias_lock);
134  return true;
135  }
136 
137  return false;
138  // throw new Exception\Forbidden();
139  } catch (NotFound $e) {
140  if ($e->getCode() == -1) {
141  return false;
142  }
143 
144  throw $e;
145  }
146  return false;
147  }
148 
149  public function getLocksOnObjectId(int $obj_id): ?ilWebDAVLockObject
150  {
151  // return null;
152  try {
153  return $this->wedav_locks_repository->getLockObjectWithObjIdFromDB($obj_id);
154  } catch (Exception) {
155  }
156  }
157 }
getLocksRecursive(array $sabre_locks, int $ref_id, string $uri)
$ref_id
Definition: ltiauth.php:65
__construct(protected ilWebDAVLocksRepository $wedav_locks_repository, protected ilWebDAVRepositoryHelper $webdav_repository_helper, protected ilWebDAVObjFactory $webdav_object_factory, protected ilWebDAVLockUriPathResolver $webdav_path_resolver, protected ilObjUser $user)
lock($uri, LockInfo $lock_info)
getLocks($uri, $returnChildLocks)
unlock($uri, LockInfo $lockInfo)