ILIAS  release_7 Revision v7.30-3-g800a261c036
ilObjFileDAV Class Reference

Class ilObjFileDAV. More...

+ Inheritance diagram for ilObjFileDAV:
+ Collaboration diagram for ilObjFileDAV:

Public Member Functions

 __construct (ilObjFile $a_obj, ilWebDAVRepositoryHelper $repo_helper, ilWebDAVObjDAVHelper $dav_helper)
 ilObjFileDAV represents the WebDAV-Interface to an ILIAS-Object More...
 
 put ($data)
 Replaces the contents of the file. More...
 
 get ()
 Returns the data. More...
 
 getName ()
 Returns title of file object. More...
 
 getContentType ()
 Returns the mime-type for a file. More...
 
 getETag ()
 Returns the ETag for a file. More...
 
 getSize ()
 Returns the size of the node, in bytes. More...
 
 setName ($a_name)
 
 handleFileUpload ($a_data, $a_file_action)
 Handle uploaded file. More...
 
- Public Member Functions inherited from ilObjectDAV
 __construct (ilObject $a_obj, ilWebDAVRepositoryHelper $repo_helper, ilWebDAVObjDAVHelper $dav_helper)
 Constructor for DAV Object. More...
 
 getRefId ()
 Returns the ref id of this object. More...
 
 getObjectId ()
 Returns the object id of this object. More...
 
 getLastModified ()
 Returns the last modification time as a unix timestamp. More...
 
 delete ()
 Deletes the current node. More...
 
 setName ($a_name)
 Renames the node. More...
 
 getName ()
 SabreDAV interface function . More...
 
 getObject ()
 Returns ILIAS Object. More...
 

Protected Member Functions

 getPathToDirectory ()
 
 getPathToFile ()
 This method only exists for legacy reasons. More...
 
 checkForVirus (string $file_dest_path)
 
 createHistoryAndNotificationForObjUpdate ($a_action)
 Create history entry and a news notification for file object update. More...
 
 deleteObjOrVersion ()
 Delete an object if there is no other version in it otherwise delete version. More...
 

Protected Attributes

 $resource_manager
 
 $resource_consumer
 
 $request
 
 $versioning_enabled
 
- Protected Attributes inherited from ilObjectDAV
 $ref_id
 
 $obj
 
 $request
 
 $repo_helper
 
 $dav_helper
 

Detailed Description

Class ilObjFileDAV.

Implementation for ILIAS File Objects represented as WebDAV File Objects

Author
Raphael Heer rapha.nosp@m.el.h.nosp@m.eer@h.nosp@m.slu..nosp@m.ch $Id$

\DAV\IFile

Definition at line 19 of file class.ilObjFileDAV.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjFileDAV::__construct ( ilObjFile  $a_obj,
ilWebDAVRepositoryHelper  $repo_helper,
ilWebDAVObjDAVHelper  $dav_helper 
)

ilObjFileDAV represents the WebDAV-Interface to an ILIAS-Object

So an ILIAS is needed in the constructor. Otherwise this object would be useless.

Parameters
ilObjFile$a_obj
ilWebDAVRepositoryHelper$repo_helper
ilWebDAVObjDAVHelper$dav_helper

Definition at line 42 of file class.ilObjFileDAV.php.

43 {
44 global $DIC;
45 $settings = new ilSetting('webdav');
46 $this->resource_manager = $DIC->resourceStorage()->manage();
47 $this->resource_consumer = $DIC->resourceStorage()->consume();
48 $this->versioning_enabled = (bool) $settings->get('webdav_versioning_enabled', true);
50 }
ILIAS Setting Class.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ilObjectDAV\$dav_helper, $DIC, ilObjectDAV\$repo_helper, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkForVirus()

ilObjFileDAV::checkForVirus ( string  $file_dest_path)
protected

Definition at line 285 of file class.ilObjFileDAV.php.

286 {
287 $vrs = ilUtil::virusHandling($file_dest_path, '', true);
288 // If vrs[0] == false -> virus found
289 if ($vrs[0] == false) {
290 ilLoggerFactory::getLogger('WebDAV')->error(get_class($this) . ' ' . $this->obj->getTitle() . " -> virus found on '$file_dest_path'!");
291 throw new Exception\Forbidden('Virus found!');
292 }
293 }
static getLogger($a_component_id)
Get component logger.
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible

References ilLoggerFactory\getLogger(), and ilUtil\virusHandling().

+ Here is the call graph for this function:

◆ createHistoryAndNotificationForObjUpdate()

ilObjFileDAV::createHistoryAndNotificationForObjUpdate (   $a_action)
protected

Create history entry and a news notification for file object update.

Parameters
$a_action

Definition at line 300 of file class.ilObjFileDAV.php.

301 {
302 // Add history entry and notification for new file version (stolen from ilObjFile->addFileVersion)
303 switch ($a_action) {
304 case "new_version":
305 case "replace":
306 ilHistory::_createEntry($this->obj->getId(), $a_action, $this->obj->getTitle() . "," . $this->obj->getVersion() . "," . $this->obj->getMaxVersion());
307 break;
308 }
309
310 $this->obj->notifyUpdate($this->obj->getId());
311 }
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.

References ilHistory\_createEntry().

Referenced by handleFileUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteObjOrVersion()

ilObjFileDAV::deleteObjOrVersion ( )
protected

Delete an object if there is no other version in it otherwise delete version.

Definition at line 316 of file class.ilObjFileDAV.php.

317 {
318 if ($this->obj->getVersion() > 1) {
319 $version_dir = $this->obj->getDirectory($this->obj->getVersion());
320 ilUtil::delDir($version_dir);
321 } else {
322 $this->obj->deleteVersions();
323 $this->obj->delete();
324 }
325 }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

References ilUtil\delDir().

+ Here is the call graph for this function:

◆ get()

ilObjFileDAV::get ( )

Returns the data.

This method may either return a string or a readable stream resource

Returns
mixed
Exceptions
Forbidden

We need this to satisfy the create process on MacOS. MacOS first posts a 0 size file and then reads it again, before then going on to post the real file.

Definition at line 95 of file class.ilObjFileDAV.php.

96 {
97 if ($this->repo_helper->checkAccess("read", $this->obj->getRefId())) {
102 if ($this->getSize() === 0) {
103 return "";
104 }
105
106 if (($r_id = $this->obj->getResourceId()) &&
107 ($identification = $this->resource_manager->find($r_id))) {
108 return $this->resource_consumer->stream($identification)->getStream()->getContents();
109 }
110
111 /*
112 * @todo: This is legacy and should be removed with ILIAS 8
113 */
114 if (file_exists($file = $this->getPathToFile())) {
115 return fopen($file, 'r');
116 }
117
118 throw new Exception\NotFound("File not found");
119 }
120
121 throw new Exception\Forbidden("Permission denied. No read access for this file");
122 }
getSize()
Returns the size of the node, in bytes.
getPathToFile()
This method only exists for legacy reasons.

References getPathToFile(), and getSize().

+ Here is the call graph for this function:

◆ getContentType()

ilObjFileDAV::getContentType ( )

Returns the mime-type for a file.

If null is returned, we'll assume application/octet-stream

Returns
string|null

Definition at line 141 of file class.ilObjFileDAV.php.

142 {
143 return $this->obj->getFileType();
144 }

◆ getETag()

ilObjFileDAV::getETag ( )

Returns the ETag for a file.

An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.

Return null if the ETag can not effectively be determined.

The ETag must be surrounded by double-quotes, so something like this would make a valid ETag:

return '"someetag"';

Returns
string|null

Definition at line 160 of file class.ilObjFileDAV.php.

161 {
162 if (file_exists($path = $this->getPathToFile())) {
163 return '"' . sha1(
164 fileinode($path) .
165 filesize($path) .
166 filemtime($path)
167 ) . '"';
168 }
169
170 if ($this->getSize() > 0) {
171 return '"' . sha1(
172 $this->getSize() .
173 $this->getName() .
174 $this->obj->getCreateDate()
175 ) . '"';
176 }
177
178 return null;
179 }
getName()
Returns title of file object.

References getName(), getPathToFile(), and getSize().

Referenced by handleFileUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getName()

ilObjFileDAV::getName ( )

Returns title of file object.

If it has a forbidden file extension -> ".sec" will be added

Returns
string

Reimplemented from ilObjectDAV.

Definition at line 129 of file class.ilObjFileDAV.php.

130 {
131 return ilFileUtils::getValidFilename($this->obj->getTitle());
132 }
static getValidFilename($a_filename)
Get valid filename.

References ilFileUtils\getValidFilename().

Referenced by getETag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPathToDirectory()

ilObjFileDAV::getPathToDirectory ( )
protected

Definition at line 262 of file class.ilObjFileDAV.php.

263 {
264 return $this->obj->getDirectory($this->obj->getVersion());
265 }

Referenced by getPathToFile().

+ Here is the caller graph for this function:

◆ getPathToFile()

ilObjFileDAV::getPathToFile ( )
protected

This method only exists for legacy reasons.

Deprecated:
Exceptions
ilFileUtilsException
Returns
string

Definition at line 275 of file class.ilObjFileDAV.php.

276 {
277 // ilObjFile delivers the filename like it was on the upload. But if the file-extension is forbidden, the file
278 // will be safed as .sec-file. In this case ->getFileName returns the wrong file name
279 $path = $this->getPathToDirectory() . "/" . $this->obj->getFileName();
280
281 // For the case of forbidden file-extensions, ::getValidFilename($path) returns the path with the .sec extension
282 return ilFileUtils::getValidFilename($path);
283 }

References getPathToDirectory(), and ilFileUtils\getValidFilename().

Referenced by get(), getETag(), and handleFileUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSize()

ilObjFileDAV::getSize ( )

Returns the size of the node, in bytes.

Returns
int

Definition at line 186 of file class.ilObjFileDAV.php.

186 : int
187 {
188 return $this->obj->getFileSize();
189 }

Referenced by get(), and getETag().

+ Here is the caller graph for this function:

◆ handleFileUpload()

ilObjFileDAV::handleFileUpload (   $a_data,
  $a_file_action 
)

Handle uploaded file.

Either it is a new file upload to a directory or it is an upload to replace an existing file.

Given data can be a resource or data (given from the sabreDAV library)

Parameters
string  |  resource$a_data
Exceptions
Forbidden

These are temporary shenanigans for ILIAS 7. Will be removed with ILIAS 8 as it will be expected that migration was run.

Todo:
: Remove with ILIAS 8

Definition at line 213 of file class.ilObjFileDAV.php.

214 {
221 if ($a_file_action != 'create' && file_exists($this->getPathToFile())) {
222 global $DIC;
224 $DIC->fileSystem()->storage(),
225 $DIC->database(),
226 rtrim(CLIENT_DATA_DIR, "/") . '/ilFile/migration_log.csv'
227 );
228 $migration->migrate(new ilFileObjectToStorageDirectory($this->obj->getId(), $this->obj->getDirectory()));
229 }
230
231 $size = (int) $this->request->getHeader('Content-Length')[0];
232
233 if ($size === 0 && $this->request->hasHeader('X-Expected-Entity-Length')) {
234 $size = $this->request->getHeader('X-Expected-Entity-Length')[0];
235 }
236
238 throw new Exception\Forbidden('File is too big');
239 }
240
241 $stream = Streams::ofResource($a_data);
242
243 if ($a_file_action === 'replace') {
244 $this->obj->replaceWithStream($stream, $this->obj->getTitle());
245 } else {
246 $this->obj->appendStream($stream, $this->obj->getTitle());
247 }
248
249 $stream->close();
250
251 // TODO filename is "input" and metadata etc.
252
253 if ($this->obj->update()) {
254 $this->createHistoryAndNotificationForObjUpdate($a_file_action);
255 ilPreview::createPreview($this->obj, true);
256 }
257
258 return $this->getETag();
259 }
$size
Definition: RandomTest.php:84
Class ilFileObjectToStorageDirectory.
createHistoryAndNotificationForObjUpdate($a_action)
Create history entry and a news notification for file object update.
getETag()
Returns the ETag for a file.
static createPreview($a_obj, $a_force=false)
Creates the preview for the object with the specified id.
static getUploadSizeLimitBytes()
const CLIENT_DATA_DIR
Definition: constants.php:44

References $DIC, $size, CLIENT_DATA_DIR, createHistoryAndNotificationForObjUpdate(), ilPreview\createPreview(), getETag(), getPathToFile(), and ilUtil\getUploadSizeLimitBytes().

Referenced by put().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ put()

ilObjFileDAV::put (   $data)

Replaces the contents of the file.

The data argument is a readable stream resource.

After a successful put operation, you may choose to return an ETag. The etag must always be surrounded by double-quotes. These quotes must appear in the actual string you're returning.

Clients may use the ETag from a PUT request to later on make sure that when they update the file, the contents haven't changed in the mean time.

If you don't plan to store the file byte-by-byte, and you return a different object on a subsequent GET you are strongly recommended to not return an ETag, and just return null.

Parameters
resource | string$data
Returns
string|null
Exceptions
Forbidden

Definition at line 73 of file class.ilObjFileDAV.php.

74 {
75 if ($this->repo_helper->checkAccess('write', $this->getRefId())) {
76 if ($this->versioning_enabled === true ||
77 $this->obj->getVersion() === '1' && $this->getSize() === 0) {
78 // Stolen from ilObjFile->addFileVersion
79 return $this->handleFileUpload($data, 'new_version');
80 } else {
81 return $this->handleFileUpload($data, 'replace');
82 }
83 }
84 throw new Exception\Forbidden("Permission denied. No write access for this file");
85 }
handleFileUpload($a_data, $a_file_action)
Handle uploaded file.
$data
Definition: storeScorm.php:23

References $data, and handleFileUpload().

+ Here is the call graph for this function:

◆ setName()

ilObjFileDAV::setName (   $a_name)
Parameters
string$a_name
Exceptions
Forbidden

Reimplemented from ilObjectDAV.

Definition at line 195 of file class.ilObjFileDAV.php.

196 {
197 if ($this->dav_helper->isValidFileNameWithValidFileExtension($a_name)) {
198 parent::setName($a_name);
199 } else {
200 throw new Exception\Forbidden("Invalid file extension");
201 }
202 }

Field Documentation

◆ $request

ilObjFileDAV::$request
protected

Definition at line 23 of file class.ilObjFileDAV.php.

◆ $resource_consumer

ilObjFileDAV::$resource_consumer
protected

Definition at line 22 of file class.ilObjFileDAV.php.

◆ $resource_manager

ilObjFileDAV::$resource_manager
protected

Definition at line 21 of file class.ilObjFileDAV.php.

◆ $versioning_enabled

ilObjFileDAV::$versioning_enabled
protected

Definition at line 30 of file class.ilObjFileDAV.php.


The documentation for this class was generated from the following file: