ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDAVProblemInfoFile.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
25 {
26  public const PROBLEM_INFO_FILE_NAME = '#!_WEBDAV_INFORMATION.txt';
27 
28  public const PROBLEM_DUPLICATE_OBJECTNAME = 'duplicate';
29  public const PROBLEM_FORBIDDEN_CHARACTERS = 'forbidden_characters';
30  public const PROBLEM_INFO_NAME_DUPLICATE = 'info_name_duplicate';
31 
32  protected int $container_ref_id;
35  protected ilLanguage $language;
36 
37  public function __construct(
38  int $container_ref_id,
39  ilWebDAVRepositoryHelper $repo_helper,
40  ilWebDAVObjFactory $dav_object_factory,
41  ilLanguage $language
42  ) {
43  $this->container_ref_id = $container_ref_id;
44  $this->repo_helper = $repo_helper;
45  $this->dav_object_factory = $dav_object_factory;
46  $this->language = $language;
47  }
48 
49  public function put($data)
50  {
51  throw new Forbidden("The error info file is virtual and can therefore not be overwritten");
52  }
53 
54  public function get()
55  {
56  $problem_infos = $this->analyseObjectsOfDAVContainer();
57  return $this->createMessageStringFromProblemInfoArray($problem_infos);
58  }
59 
60  public function getName()
61  {
62  return self::PROBLEM_INFO_FILE_NAME;
63  }
64 
65  public function getContentType()
66  {
67  return 'text/plain';
68  }
69 
70  public function getETag()
71  {
72  return null;
73  }
74 
75  public function getSize(): int
76  {
77  return 0;
78  }
79 
80  public function setName($a_name): void
81  {
82  throw new Forbidden("The error info file cannot be renamed");
83  }
84 
88  protected function analyseObjectsOfDAVContainer(): array
89  {
90  $already_seen_titles = array();
91 
92  $problem_infos = array(
93  self::PROBLEM_DUPLICATE_OBJECTNAME => array(),
94  self::PROBLEM_FORBIDDEN_CHARACTERS => array(),
95  self::PROBLEM_INFO_NAME_DUPLICATE => false
96  );
97 
98  foreach ($this->repo_helper->getChildrenOfRefId($this->container_ref_id) as $ref_id) {
99  try {
100  $dav_object = $this->dav_object_factory->retrieveDAVObjectByRefID($ref_id);
101 
102  $title = $dav_object->getName();
103 
104  if ($title === self::PROBLEM_INFO_FILE_NAME) {
105  $problem_infos[self::PROBLEM_INFO_NAME_DUPLICATE] = true;
106  } elseif (in_array($title, $already_seen_titles)) {
107  $problem_infos[self::PROBLEM_DUPLICATE_OBJECTNAME][] = $title;
108  } else {
109  $already_seen_titles[] = $title;
110  }
111  } catch (ilWebDAVNotDavableException $e) {
113  $title = $this->repo_helper->getObjectTitleFromRefId($ref_id);
114  $problem_infos[self::PROBLEM_FORBIDDEN_CHARACTERS][] = $title;
115  }
116  } catch (Forbidden | NotFound | RuntimeException $e) {
117  }
118  }
119 
120  return $problem_infos;
121  }
122 
126  protected function createMessageStringFromProblemInfoArray(array $problem_infos): string
127  {
128  $message_string = "";
129 
130  if ($problem_infos[self::PROBLEM_INFO_NAME_DUPLICATE]) {
131  $message_string .= "# " . $this->language->txt('webdav_problem_info_duplicate') . "\n\n";
132  }
133 
134  $duplicates_list = $problem_infos[self::PROBLEM_DUPLICATE_OBJECTNAME];
135  if (count($duplicates_list) > 0) {
136  $message_string .= "# " . $this->language->txt('webdav_duplicate_detected_title') . "\n";
137  foreach ($duplicates_list as $duplicate_title) {
138  $message_string .= $duplicate_title . "\n";
139  }
140  $message_string .= "\n";
141  }
142 
143  $forbidden_character_titles_list = $problem_infos[self::PROBLEM_FORBIDDEN_CHARACTERS];
144  if (count($forbidden_character_titles_list) > 0) {
145  $message_string .= "# " . $this->language->txt('webdav_forbidden_chars_title') . "\n";
146  foreach ($forbidden_character_titles_list as $forbidden_character_title) {
147  $message_string .= $forbidden_character_title . "\n";
148  }
149  $message_string .= "\n";
150  }
151 
152  if (strlen($message_string) === 0) {
153  $message_string = $this->language->txt('webdav_problem_free_container');
154  }
155 
156  return $message_string;
157  }
158 
159  public function delete(): void
160  {
161  throw new Forbidden("It is not possible to delete this file since it is just virtual.");
162  }
163 
164  public function getLastModified()
165  {
166  return time();
167  }
168 }
__construct(int $container_ref_id, ilWebDAVRepositoryHelper $repo_helper, ilWebDAVObjFactory $dav_object_factory, ilLanguage $language)
ilWebDAVRepositoryHelper $repo_helper
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createMessageStringFromProblemInfoArray(array $problem_infos)
$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 $dav_object_factory