ILIAS  release_8 Revision v8.23
class.ilWebDAVLockUriPathResolver.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
28 {
30 
31  public function __construct(ilWebDAVRepositoryHelper $webdav_repository_helper)
32  {
33  $this->webdav_repository_helper = $webdav_repository_helper;
34  }
35 
36  public function getRefIdForWebDAVPath(string $uri): int
37  {
38  $uri = trim($uri, '/');
39 
40  $split_path = explode('/', $uri, 2);
41 
42  if (!isset($split_path[0])
43  || $split_path[0] === ''
44  || $split_path[0] !== CLIENT_ID) {
45  throw new BadRequest('Invalid client id given');
46  }
47 
48  $path_inside_of_mountpoint = isset($split_path[1]) ? $split_path[1] : '';
49  $mountpoint = '';
50 
51  if ($path_inside_of_mountpoint !== ''
52  && substr($path_inside_of_mountpoint, 0, 4) === 'ref_') {
53  $split_path = explode('/', $path_inside_of_mountpoint, 2);
54  $mountpoint = $split_path[0];
55  $path_inside_of_mountpoint = isset($split_path[1]) ? $split_path[1] : '';
56  }
57 
58  if ($mountpoint !== '') {
59  return $this->getRefIdFromPathInRefMount($mountpoint, $path_inside_of_mountpoint);
60  }
61 
62  return $this->getRefIdFromPathInRepositoryMount($path_inside_of_mountpoint);
63  }
64 
65  protected function getRefIdFromPathInRepositoryMount(string $path_inside_of_mountpoint): int
66  {
67  if ($path_inside_of_mountpoint === '') {
68  return ROOT_FOLDER_ID;
69  }
70 
71  return $this->getRefIdFromGivenParentRefAndTitlePath(ROOT_FOLDER_ID, explode('/', $path_inside_of_mountpoint));
72  }
73 
74  protected function getRefIdFromPathInRefMount(string $repository_mountpoint, string $path_inside_of_mountpoint): int
75  {
76  $relative_mountpoint_ref_id = (int) explode('_', $repository_mountpoint)[1];
77 
78  if ($relative_mountpoint_ref_id < 1) {
79  throw new NotFound('Mount point not found');
80  }
81 
82  if ($path_inside_of_mountpoint === '') {
83  return $relative_mountpoint_ref_id;
84  }
85 
86  return $this->getRefIdFromGivenParentRefAndTitlePath($relative_mountpoint_ref_id, explode('/', $path_inside_of_mountpoint));
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 $e) {
101  if (count($current_path_array) === 0) {
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 }
ilWebDAVRepositoryHelper $webdav_repository_helper
const ROOT_FOLDER_ID
Definition: constants.php:32
getRefIdFromPathInRepositoryMount(string $path_inside_of_mountpoint)
getChildRefIdByGivenTitle(int $a_parent_ref_id, string $a_searched_title)
__construct(ilWebDAVRepositoryHelper $webdav_repository_helper)
const CLIENT_ID
Definition: constants.php:41
getRefIdFromGivenParentRefAndTitlePath(int $a_parent_ref, array $current_path_array)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRefIdFromPathInRefMount(string $repository_mountpoint, string $path_inside_of_mountpoint)