ILIAS  release_8 Revision v8.24
class.ilDAVProblemInfoFile.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use Sabre\DAV\Exception\Forbidden;
22use Sabre\DAV\Exception\NotFound;
23
24class ilDAVProblemInfoFile implements Sabre\DAV\IFile
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;
36
37 public function __construct(
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 {
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 }
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}
createMessageStringFromProblemInfoArray(array $problem_infos)
__construct(int $container_ref_id, ilWebDAVRepositoryHelper $repo_helper, ilWebDAVObjFactory $dav_object_factory, ilLanguage $language)
ilWebDAVRepositoryHelper $repo_helper
ilWebDAVObjFactory $dav_object_factory
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67