ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
Backend.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Sabre\DAV\Locks\LockInfo;
24use Sabre\DAV\Locks\Backend\AbstractBackend;
27
31class Backend extends AbstractBackend
32{
33 private int $user_id;
34
35 public function __construct(
36 private Factory $entity_factory,
37 private LocksRepository $locks_repository
38 ) {
39 global $DIC; // TODO remove Service Locator
40 $this->user_id = $DIC->user()->getId();
41 }
42
46 public function getLocks($uri, $returnChildLocks): array
47 {
48 $entity = $this->entity_factory->getByFullPath($uri);
49 if ($entity === null) {
50 return [];
51 }
52
53 $lock_object = $this->locks_repository->maybeGetLockFromObjId($entity->getObjectProxy()->getObjId());
54 if ($lock_object === null) {
55 return [];
56 }
57
58 return [
59 $lock_object->getAsSabreDavLock($uri),
60 ];
61 }
62
63 public function lock($uri, LockInfo $lock_info): bool
64 {
65 $entity = $this->entity_factory->getByFullPath($uri);
66 $obj_id = $entity?->getObjectProxy()->getObjId();
67 if ($obj_id === null) {
68 return false;
69 }
70
71 $ilias_lock = new Lock(
72 $lock_info->token,
73 $obj_id,
74 $this->user_id,
75 $lock_info->owner,
76 time() + 3600,
77 $lock_info->depth,
78 'w',
79 $lock_info->scope
80 );
81 $this->locks_repository->save($ilias_lock);
82
83 $proxy = $entity?->getObjectProxy();
84 if ($proxy !== null && $proxy->getType() === Type::FILE) {
85 $proxy->getStreamHandler()?->publish();
86 }
87 return true;
88 }
89
90 public function unlock($uri, LockInfo $lock_info): bool
91 {
92 $ilias_lock = $this->locks_repository->maybeGetLockFromToken($lock_info->token);
93
94 if ($ilias_lock !== null && $ilias_lock->getIliasOwner() === $this->user_id) {
95 $this->locks_repository->remove($lock_info->token);
96 return true;
97 }
98 return false;
99 }
100}
lock($uri, LockInfo $lock_info)
Definition: Backend.php:63
__construct(private Factory $entity_factory, private LocksRepository $locks_repository)
Definition: Backend.php:35
getLocks($uri, $returnChildLocks)
Definition: Backend.php:46
unlock($uri, LockInfo $lock_info)
Definition: Backend.php:90
global $DIC
Definition: shib_login.php:26