ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebDAVLockUriPathResolver.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Sabre\DAV\Exception\BadRequest;
22use Sabre\DAV\Exception\NotFound;
23
28{
29 public function __construct(protected ilWebDAVRepositoryHelper $webdav_repository_helper)
30 {
31 }
32
33 public function getRefIdForWebDAVPath(string $uri): int
34 {
35 $uri = trim($uri, '/');
36
37 $split_path = explode('/', $uri, 2);
38
39 if (!isset($split_path[0])
40 || $split_path[0] === ''
41 || $split_path[0] !== CLIENT_ID) {
42 throw new BadRequest('Invalid client id given');
43 }
44
45 $path_inside_of_mountpoint = $split_path[1] ?? '';
46 $mountpoint = '';
47
48 if ($path_inside_of_mountpoint !== ''
49 && str_starts_with($path_inside_of_mountpoint, 'ref_')) {
50 $split_path = explode('/', $path_inside_of_mountpoint, 2);
51 $mountpoint = $split_path[0];
52 $path_inside_of_mountpoint = $split_path[1] ?? '';
53 }
54
55 if ($mountpoint !== '') {
56 return $this->getRefIdFromPathInRefMount($mountpoint, $path_inside_of_mountpoint);
57 }
58
59 return $this->getRefIdFromPathInRepositoryMount($path_inside_of_mountpoint);
60 }
61
62 protected function getRefIdFromPathInRepositoryMount(string $path_inside_of_mountpoint): int
63 {
64 if ($path_inside_of_mountpoint === '') {
65 return ROOT_FOLDER_ID;
66 }
67
68 return $this->getRefIdFromGivenParentRefAndTitlePath(ROOT_FOLDER_ID, explode('/', $path_inside_of_mountpoint));
69 }
70
71 protected function getRefIdFromPathInRefMount(string $repository_mountpoint, string $path_inside_of_mountpoint): int
72 {
73 $relative_mountpoint_ref_id = (int) explode('_', $repository_mountpoint)[1];
74
75 if ($relative_mountpoint_ref_id < 1) {
76 throw new NotFound('Mount point not found');
77 }
78
79 if ($path_inside_of_mountpoint === '') {
80 return $relative_mountpoint_ref_id;
81 }
82
84 $relative_mountpoint_ref_id,
85 explode('/', $path_inside_of_mountpoint)
86 );
87 }
88
92 protected function getRefIdFromGivenParentRefAndTitlePath(int $a_parent_ref, array $current_path_array): int
93 {
94 $current_ref_id = $a_parent_ref;
95 while (count($current_path_array) >= 1) {
96 $next_searched_title = array_shift($current_path_array);
97 if ($next_searched_title !== '') {
98 try {
99 $current_ref_id = $this->getChildRefIdByGivenTitle($current_ref_id, $next_searched_title);
100 } catch (NotFound) {
101 if ($current_path_array === []) {
102 /* This is a really special case. It occurs, if the lock is meant for an object that does not
103 exist yet (so called NullRessources) since we can't and won't lock non existing objects, we
104 set the Exception code to -1. The receiving class SHOULD handle what to do with this value */
105 throw new NotFound('Last node not found', -1);
106 }
107
108 throw new NotFound('Node not found', 0);
109 }
110 }
111 }
112 return $current_ref_id;
113 }
114
115 protected function getChildRefIdByGivenTitle(int $a_parent_ref_id, string $a_searched_title): int
116 {
117 $ref_to_return = null;
118
119 foreach ($this->webdav_repository_helper->getChildrenOfRefId($a_parent_ref_id) as $child_ref) {
120 $child_title = $this->webdav_repository_helper->getObjectTitleFromRefId($child_ref, true);
121 if ($a_searched_title === $child_title) {
122 $ref_to_return = $child_ref;
123 }
124 }
125
126 if (!is_null($ref_to_return)) {
127 return $ref_to_return;
128 }
129
130 throw new NotFound('Node not found');
131 }
132}
__construct(protected ilWebDAVRepositoryHelper $webdav_repository_helper)
getChildRefIdByGivenTitle(int $a_parent_ref_id, string $a_searched_title)
getRefIdFromPathInRefMount(string $repository_mountpoint, string $path_inside_of_mountpoint)
getRefIdFromPathInRepositoryMount(string $path_inside_of_mountpoint)
getRefIdFromGivenParentRefAndTitlePath(int $a_parent_ref, array $current_path_array)
const CLIENT_ID
Definition: constants.php:41
const ROOT_FOLDER_ID
Definition: constants.php:32