ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilDAVFile Class Reference
+ Inheritance diagram for ilDAVFile:
+ Collaboration diagram for ilDAVFile:

Public Member Functions

 __construct (protected ilObjFile $obj, protected ilWebDAVRepositoryHelper $repo_helper, Services $resource_storage, protected RequestInterface $request, protected ilWebDAVObjFactory $dav_factory, protected bool $versioning_enabled)
 
 put ($data, ?string $name=null)
 
 get ()
 
 getName ()
 
 getContentType ()
 
 getETag ()
 
 getSize ()
 
 noSizeCheckNeeded ()
 
 setName ($name)
 
 delete ()
 
 getLastModified ()
 

Protected Member Functions

 clearLocks ()
 

Protected Attributes

Manager $resource_manager
 
Consumers $resource_consumer
 
bool $needs_size_check = true
 
int $temporary_size = null
 

Detailed Description

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

Definition at line 32 of file class.ilDAVFile.php.

Constructor & Destructor Documentation

◆ __construct()

ilDAVFile::__construct ( protected ilObjFile  $obj,
protected ilWebDAVRepositoryHelper  $repo_helper,
Services  $resource_storage,
protected RequestInterface  $request,
protected ilWebDAVObjFactory  $dav_factory,
protected bool  $versioning_enabled 
)

Definition at line 46 of file class.ilDAVFile.php.

53 {
54 $this->resource_manager = $resource_storage->manage();
55 $this->resource_consumer = $resource_storage->consume();
56 }

References ILIAS\ResourceStorage\Services\consume(), and ILIAS\ResourceStorage\Services\manage().

+ Here is the call graph for this function:

Member Function Documentation

◆ clearLocks()

ilDAVFile::clearLocks ( )
protected

Definition at line 58 of file class.ilDAVFile.php.

58 : void
59 {
60 $this->repo_helper->locks()->purgeExpiredLocksFromDB();
61 $lock = $this->repo_helper->locks()->getLockObjectWithObjIdFromDB($this->obj->getId());
62 if ($lock !== null) {
63 $this->repo_helper->locks()->removeLockWithTokenFromDB($lock->getToken());
64 }
65 }

Referenced by put().

+ Here is the caller graph for this function:

◆ delete()

ilDAVFile::delete ( )

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

213 : void
214 {
215 $this->repo_helper->deleteObject($this->obj->getRefId());
216 }

◆ get()

ilDAVFile::get ( )
Returns
string|resource

Definition at line 136 of file class.ilDAVFile.php.

137 {
138 if (!$this->repo_helper->checkAccess("read", $this->obj->getRefId())) {
139 throw new Forbidden("Permission denied. No read access for this file");
140 }
141
142 if (($r_id = $this->obj->getResourceId()) &&
143 ($identification = $this->resource_manager->find($r_id))) {
144 return $this->resource_consumer->stream($identification)->getStream()->getContents();
145 }
146 return '';
147 }

◆ getContentType()

ilDAVFile::getContentType ( )

Definition at line 164 of file class.ilDAVFile.php.

164 : ?string
165 {
166 return $this->obj->getFileType();
167 }

◆ getETag()

ilDAVFile::getETag ( )

Definition at line 169 of file class.ilDAVFile.php.

169 : ?string
170 {
171 if ($this->getSize() > 0) {
172 return '"'
173 . sha1(
174 (string) $this->getSize() .
175 $this->getName() .
176 $this->obj->getCreateDate()
177 )
178 . '"';
179 }
180
181 return null;
182 }

References getName(), and getSize().

Referenced by put().

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

◆ getLastModified()

ilDAVFile::getLastModified ( )

Definition at line 218 of file class.ilDAVFile.php.

218 : ?int
219 {
220 return $this->retrieveLastModifiedAsIntFromObjectLastUpdateString($this->obj->getLastUpdateDate());
221 }

◆ getName()

ilDAVFile::getName ( )

Definition at line 149 of file class.ilDAVFile.php.

149 : string
150 {
151 $title = $this->obj->getTitle();
152 $suffix = empty($this->obj->getFileExtension())
153 ? $this->extractSuffixFromFilename($title)
154 : $this->obj->getFileExtension();
155
156 $return_title = $this->ensureSuffix(
157 $title,
158 $suffix
159 );
160
161 return $return_title;
162 }
ensureSuffix(string $title, ?string $suffix=null)
extractSuffixFromFilename(string $filename)

References ensureSuffix(), and extractSuffixFromFilename().

Referenced by getETag(), and put().

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

◆ getSize()

ilDAVFile::getSize ( )

Definition at line 184 of file class.ilDAVFile.php.

184 : int
185 {
186 try {
187 return $this->obj->getFileSize();
188 } catch (Throwable) {
189 return -1;
190 }
191 }

Referenced by getETag(), and put().

+ Here is the caller graph for this function:

◆ noSizeCheckNeeded()

ilDAVFile::noSizeCheckNeeded ( )

Definition at line 193 of file class.ilDAVFile.php.

193 : void
194 {
195 $this->needs_size_check = false;
196 }

◆ put()

ilDAVFile::put (   $data,
?string  $name = null 
)
Parameters
string | resource$data

Definition at line 70 of file class.ilDAVFile.php.

70 : ?string
71 {
72 if (!$this->repo_helper->checkAccess('write', $this->obj->getRefId())) {
73 throw new Forbidden("Permission denied. No write access for this file");
74 }
75 if ($name === null) {
76 $name = $this->getName();
77 }
78 $size = 0;
79 $name ??= $this->getName();
80 $name = $this->ensureSuffix($name, $this->extractSuffixFromFilename($name));
81
82 $stream = is_resource($data) ? Streams::ofResource($data) : Streams::ofString($data);
83 $stream_size = $stream->getSize();
84
85 if ($this->request->hasHeader("Content-Length")) {
86 $size = (int) $this->request->getHeader("Content-Length")[0];
87 }
88 if ($size === 0 && $this->request->hasHeader('X-Expected-Entity-Length')) {
89 $size = (int) $this->request->getHeader('X-Expected-Entity-Length')[0];
90 }
91
93 // remove already created file?
94 throw new Forbidden('File is too big');
95 }
96
97 if ($this->needs_size_check && $this->getSize() === 0) {
98 $parent_ref_id = $this->repo_helper->getParentOfRefId($this->obj->getRefId());
99 $file_dav = $this->dav_factory->createDAVObject($this->obj, $parent_ref_id);
100 $file_dav->noSizeCheckNeeded();
101
102 return $file_dav->put($data);
103 }
104
105 $resource = $stream->detach();
106 if ($resource === null) {
107 return null;
108 }
109 $stream = Streams::ofResource($resource);
110
111 if ($this->versioning_enabled) {
112 $version = $this->obj->getVersion(true);
113 if (($stream_content = (string) $stream) !== '') {
114 $version = $this->obj->appendStream(
115 Streams::ofString($stream_content),
116 $name
117 );
118 }
119 } else {
120 $version = $this->obj->replaceWithStream($stream, $name);
121 }
122
123 $stream->close();
124 $this->clearLocks();
125
126 if ($version > 0) {
127 // $this->obj->publish();
128 return $this->getETag();
129 }
130 return null;
131 }
$version
Definition: plugin.php:24
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static getPhpUploadSizeLimitInBytes()

References $data, $version, clearLocks(), ensureSuffix(), extractSuffixFromFilename(), getETag(), getName(), ilFileUtils\getPhpUploadSizeLimitInBytes(), getSize(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ setName()

ilDAVFile::setName (   $name)

Definition at line 198 of file class.ilDAVFile.php.

198 : void
199 {
200 if (!$this->repo_helper->checkAccess("write", $this->obj->getRefId())) {
201 throw new Forbidden('Permission denied');
202 }
203
204 if ($this->isDAVableObjTitle($name) &&
205 $name === $this->obj->checkFileExtension($this->getName(), $name)) {
206 $this->obj->setTitle($this->ensureSuffix($name, $this->extractSuffixFromFilename($name)));
207 $this->obj->update();
208 } else {
210 }
211 }

References ensureSuffix(), extractSuffixFromFilename(), and ilWebDAVNotDavableException\OBJECT_TITLE_NOT_DAVABLE.

+ Here is the call graph for this function:

Field Documentation

◆ $needs_size_check

bool ilDAVFile::$needs_size_check = true
protected

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

◆ $resource_consumer

Consumers ilDAVFile::$resource_consumer
protected

Definition at line 40 of file class.ilDAVFile.php.

◆ $resource_manager

Manager ilDAVFile::$resource_manager
protected

Definition at line 39 of file class.ilDAVFile.php.

◆ $temporary_size

int ilDAVFile::$temporary_size = null
protected

Definition at line 44 of file class.ilDAVFile.php.


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