ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilProblemInfoFileDAV.php
Go to the documentation of this file.
1<?php
2
3use Sabre\DAV\Exception\Forbidden;
4
6{
7 const PROBLEM_INFO_FILE_NAME = '#!_WEBDAV_INFORMATION.txt';
8
9 const PROBLEM_DUPLICATE_OBJECTNAME = 'duplicate';
10 const PROBLEM_FORBIDDEN_CHARACTERS = 'forbidden_characters';
11 const PROBLEM_INFO_NAME_DUPLICATE = 'info_name_duplicate';
12
14 protected $dav_container;
15
17 protected $repo_helper;
18
20 protected $dav_helper;
21
22 public function __construct(
23 ilObjContainerDAV $a_dav_container,
24 ilWebDAVRepositoryHelper $a_repo_helper,
25 ilWebDAVObjDAVHelper $a_dav_helper
26 ) {
27 $this->dav_container = $a_dav_container;
28 $this->repo_helper = $a_repo_helper;
29 $this->dav_helper = $a_dav_helper;
30 }
31
39 public function put($data)
40 {
41 throw new Forbidden("The error info file is virtual and can therefore not be overwritten");
42 }
43
49 public function get()
50 {
51 $problem_infos = $this->analyseObjectsOfDAVContainer();
52 return $this->createMessageStringFromProblemInfoArray($problem_infos);
53 }
54
60 public function getName()
61 {
63 }
64
70 public function getContentType()
71 {
72 return 'text/plain';
73 }
74
89 public function getETag()
90 {
91 return null;
92 }
93
99 public function getSize()
100 {
101 return 0;
102 }
103
108 public function setName($a_name)
109 {
110 throw new Exception\Forbidden("The error info file cannot be renamed");
111 }
112
118 protected function analyseObjectsOfDAVContainer() : array
119 {
120 // list of titles that were already checked (used for duplicate checking)
121 $already_seen_titles = array();
122
123 // Array with 3 different problem topics
124 $problem_infos = array(
125 self::PROBLEM_DUPLICATE_OBJECTNAME => array(),
126 self::PROBLEM_FORBIDDEN_CHARACTERS => array(),
127 self::PROBLEM_INFO_NAME_DUPLICATE => false // if a file is already named #!_WEBDAV_INFORMATION.txt (should not be the case)
128 );
129
130 // Loop to check every child of the container
131 foreach ($this->repo_helper->getChildrenOfRefId($this->dav_container->getRefId()) as $ref_id) {
132 $type = $this->repo_helper->getObjectTypeFromRefId($ref_id);
133 if ($this->dav_helper->isDAVableObjType($type) && $this->repo_helper->checkAccess('read', $ref_id)) {
134 $title = $this->repo_helper->getObjectTitleFromRefId($ref_id);
135 if (!$this->dav_helper->hasInvalidPrefixInTitle($title)) {
136 // Check if object is a file with the same name as this info file
137 if ($title == self::PROBLEM_INFO_FILE_NAME) {
138 $problem_infos[self::PROBLEM_INFO_NAME_DUPLICATE] = true;
139 }
140 // Check if title contains forbidden characters
141 elseif ($this->dav_helper->hasTitleForbiddenChars($title)) {
142 $problem_infos[self::PROBLEM_FORBIDDEN_CHARACTERS][] = $title;
143 }
144 // Check for duplicates
145 elseif (in_array($title, $already_seen_titles)) {
146 $problem_infos[self::PROBLEM_DUPLICATE_OBJECTNAME][] = $title;
147 } else {
148 $already_seen_titles[] = $title;
149 }
150 }
151 }
152 }
153
154 return $problem_infos;
155 }
156
163 protected function createMessageStringFromProblemInfoArray(array $problem_infos)
164 {
165 global $DIC;
166
167 $lng = $DIC->language();
168 $message_string = "";
169
170 // If there is a file with the same name of the problem info file -> print message about it
171 if ($problem_infos[self::PROBLEM_INFO_NAME_DUPLICATE]) {
172 $message_string .= "# " . $lng->txt('webdav_problem_info_duplicate') . "\n\n";
173 }
174
175 // Print list with duplicate file names
176 $duplicates_list = $problem_infos[self::PROBLEM_DUPLICATE_OBJECTNAME];
177 if (count($duplicates_list) > 0) {
178 $message_string .= "# " . $lng->txt('webdav_duplicate_detected_title') . "\n";
179 foreach ($duplicates_list as $duplicate_title) {
180 $message_string .= $duplicate_title . "\n";
181 }
182 $message_string .= "\n";
183 }
184
185 // Print list of files with forbidden characters
186 $forbidden_character_titles_list = $problem_infos[self::PROBLEM_FORBIDDEN_CHARACTERS];
187 if (count($forbidden_character_titles_list) > 0) {
188 $message_string .= "# " . $lng->txt('webdav_forbidden_chars_title') . "\n";
189 foreach ($forbidden_character_titles_list as $forbidden_character_title) {
190 $message_string .= $forbidden_character_title . "\n";
191 }
192 $message_string .= "\n";
193 }
194
195 // If no problems were found -> create a default message (this happens only if the file is called directly)
196 if (strlen($message_string) == 0) {
197 $message_string = $lng->txt('webdav_problem_free_container');
198 }
199
200 return $message_string;
201 }
202
208 public function delete()
209 {
210 throw new \Sabre\DAV\Exception\Forbidden("It is not possible to delete this file since it is just virtual.");
211 }
212
219 public function getLastModified()
220 {
221 return null;
222 }
223}
An exception for terminatinating execution or to throw for unit testing.
Class ilObjContainerDAV.
getETag()
Returns the ETag for a file.
getName()
Returns the title of the problem info file.
analyseObjectsOfDAVContainer()
Analyses objects of the in the constructor given DAV container.
getSize()
Returns the size of the node, in bytes.
__construct(ilObjContainerDAV $a_dav_container, ilWebDAVRepositoryHelper $a_repo_helper, ilWebDAVObjDAVHelper $a_dav_helper)
put($data)
Since this is a virtual file, put is not possible.
getContentType()
Returns the mime-type for a file which is 'txt/plain'.
getLastModified()
Returns the last modification time, as a unix timestamp.
createMessageStringFromProblemInfoArray(array $problem_infos)
Creates a message string out of the found problems in the DAV container.
Class ilWebDAVObjDAVHelper.
Class ilWebDAVRepositoryHelper.
global $DIC
Definition: goto.php:24
$type
$lng
$data
Definition: storeScorm.php:23