ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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.

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

53  {
54  $this->resource_manager = $resource_storage->manage();
55  $this->resource_consumer = $resource_storage->consume();
56  }
+ Here is the call graph for this function:

Member Function Documentation

◆ clearLocks()

ilDAVFile::clearLocks ( )
protected

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

Referenced by put().

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  }
+ Here is the caller graph for this function:

◆ delete()

ilDAVFile::delete ( )

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

217  : void
218  {
219  $this->repo_helper->deleteObject($this->obj->getRefId());
220  }

◆ get()

ilDAVFile::get ( )
Returns
string|resource

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

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

◆ getContentType()

ilDAVFile::getContentType ( )

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

168  : ?string
169  {
170  return $this->obj->getFileType();
171  }

◆ getETag()

ilDAVFile::getETag ( )

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

References getName(), and getSize().

Referenced by put().

173  : ?string
174  {
175  if ($this->getSize() > 0) {
176  return '"'
177  . sha1(
178  (string) $this->getSize() .
179  $this->getName() .
180  $this->obj->getCreateDate()
181  )
182  . '"';
183  }
184 
185  return null;
186  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastModified()

ilDAVFile::getLastModified ( )

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

222  : ?int
223  {
224  return $this->retrieveLastModifiedAsIntFromObjectLastUpdateString($this->obj->getLastUpdateDate());
225  }

◆ getName()

ilDAVFile::getName ( )

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

References ensureSuffix(), and extractSuffixFromFilename().

Referenced by getETag(), and put().

153  : string
154  {
155  $title = $this->obj->getTitle();
156  $suffix = empty($this->obj->getFileExtension())
157  ? $this->extractSuffixFromFilename($title)
158  : $this->obj->getFileExtension();
159 
160  $return_title = $this->ensureSuffix(
161  $title,
162  $suffix
163  );
164 
165  return $return_title;
166  }
extractSuffixFromFilename(string $filename)
ensureSuffix(string $title, ?string $suffix=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSize()

ilDAVFile::getSize ( )

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

Referenced by getETag(), and put().

188  : int
189  {
190  try {
191  return $this->obj->getFileSize();
192  } catch (Throwable) {
193  return -1;
194  }
195  }
+ Here is the caller graph for this function:

◆ noSizeCheckNeeded()

ilDAVFile::noSizeCheckNeeded ( )

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

197  : void
198  {
199  $this->needs_size_check = false;
200  }

◆ put()

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

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

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

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  $this->delete();
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  $version = $this->obj->getVersion(true);
112  if ($this->versioning_enabled || $version === 0) {
113  // stream may be a temp-file (due to chunked upload). we must impoort it directly
114  $uri = $stream->getMetadata('uri');
115  if ($uri === 'php://temp') {
116  $version = $this->obj->appendStream($stream, $name);
117  } elseif (($stream_content = (string) $stream) !== '') { // this may be a problem with large files
118  $version = $this->obj->appendStream(
119  Streams::ofString($stream_content),
120  $name
121  );
122  }
123  } else {
124  $version = $this->obj->replaceWithStream($stream, $name);
125  }
126 
127  $stream->close();
128  $this->clearLocks();
129 
130  if ($version > 0) {
131  // $this->obj->publish();
132  return $this->getETag();
133  }
134  return null;
135  }
Stream factory which enables the user to create streams without the knowledge of the concrete class...
Definition: Streams.php:31
$version
Definition: plugin.php:25
extractSuffixFromFilename(string $filename)
static getPhpUploadSizeLimitInBytes()
ensureSuffix(string $title, ?string $suffix=null)
+ Here is the call graph for this function:

◆ setName()

ilDAVFile::setName (   $name)

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

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

202  : void
203  {
204  if (!$this->repo_helper->checkAccess("write", $this->obj->getRefId())) {
205  throw new Forbidden('Permission denied');
206  }
207 
208  if ($this->isDAVableObjTitle($name) &&
209  $name === $this->obj->checkFileExtension($this->getName(), $name)) {
210  $this->obj->setTitle($this->ensureSuffix($name, $this->extractSuffixFromFilename($name)));
211  $this->obj->update();
212  } else {
214  }
215  }
extractSuffixFromFilename(string $filename)
ensureSuffix(string $title, ?string $suffix=null)
+ 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: