ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjFileImplementationStorage.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9
15{
19 protected $resource;
23 protected $storage;
31 protected $obj_id;
36 public function __construct(StorableResource $resource, int $obj_id)
37 {
38 global $DIC;
42 $this->resource = $resource;
43 $this->obj_id = $obj_id;
44 $this->storage = $DIC->resourceStorage();
45 $this->download_with_uploaded_filename = (bool) $DIC->clientIni()->readVariable(
46 'file_access',
47 'download_with_uploaded_filename'
48 );
49 }
50
51 private function debug() : void
52 {
53 // debug
54 $stream = $this->storage->consume()->stream($this->resource->getIdentification())->getStream();
55 $container = dirname($stream->getMetadata('uri'), 2);
56
57 $dir_reader = function (string $path) {
58 $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
59
60 $files = array();
61 foreach ($rii as $file) {
62 if (!$file->isDir()) {
63 $files[] = $file->getPathname();
64 }
65 }
66
67 return $files;
68 };
69
70 ilUtil::sendInfo('<pre>' . print_r($dir_reader($container), true) . '</pre>');
71 }
72
73 public function handleChangedObjectTitle(string $new_title)
74 {
75 $current_revision = $this->resource->getCurrentRevision();
76 $current_revision->setTitle($new_title);
77 $this->storage->manage()->updateRevision($current_revision);
78 }
79
83 public function getFile($a_hist_entry_id = null)
84 {
85 $stream = $this->storage->consume()->stream($this->resource->getIdentification());
86 if ($a_hist_entry_id) {
87 $stream = $stream->setRevisionNumber($a_hist_entry_id);
88 }
89 return $stream->getStream()->getMetadata('uri');
90 }
91
95 public function getFileType()
96 {
97 return $this->resource->getCurrentRevision()->getInformation()->getMimeType();
98 }
99
103 public function getDirectory($a_version = 0)
104 {
105 $consumer = $this->storage->consume()->stream($this->resource->getIdentification());
106 if ($a_version) {
107 $consumer->setRevisionNumber($a_version);
108 }
109 $stream = $consumer->getStream();
110
111 return dirname($stream->getMetadata('uri'));
112 }
113
117 public function sendFile($a_hist_entry_id = null)
118 {
119 if ($this->isInline($a_hist_entry_id)) {
120 $consumer = $this->storage->consume()->inline($this->resource->getIdentification());
121 } else {
122 $consumer = $this->storage->consume()->download($this->resource->getIdentification());
123 }
124
125
126 if ($a_hist_entry_id) {
127 $revision = $this->resource->getSpecificRevision($a_hist_entry_id);
128 $consumer->setRevisionNumber($a_hist_entry_id);
129 } else {
130 $revision = $this->resource->getCurrentRevision();
131 }
132
133 if ($this->download_with_uploaded_filename) {
134 $consumer->overrideFileName($revision->getInformation()->getTitle());
135 } else {
136 $consumer->overrideFileName($revision->getTitle());
137 }
138
139 $consumer->run();
140 }
141
146 private function isInline($a_hist_entry_id = null)
147 {
148 try {
149 $revision = $a_hist_entry_id ?
150 $this->resource->getSpecificRevision($a_hist_entry_id) :
151 $this->resource->getCurrentRevision();
152 return \ilObjFileAccess::_isFileInline($revision->getTitle());
153 } catch (Exception $e) {
154 return false;
155 }
156 }
157
161 public function deleteVersions($a_hist_entry_ids = null)
162 {
163 if (is_array($a_hist_entry_ids)) {
164 foreach ($a_hist_entry_ids as $id) {
165 $this->storage->manage()->removeRevision($this->resource->getIdentification(), $id);
166 }
167 }
168 }
169
173 public function getFileExtension()
174 {
175 return $this->resource->getCurrentRevision()->getInformation()->getSuffix();
176 }
177
181 public function getVersions($version_ids = null) : array
182 {
183 $versions = [];
184 foreach ($this->resource->getAllRevisions() as $revision) {
185 if (is_array($version_ids) && !in_array($revision->getVersionNumber(), $version_ids)) {
186 continue;
187 }
188 $information = $revision->getInformation();
189 $v = new ilObjFileVersion();
190 $v->setVersion($revision->getVersionNumber());
191 $v->setHistEntryId($revision->getVersionNumber());
192 $v->setFilename($information->getTitle());
193 $v->setAction($revision->getVersionNumber() === 1 ? 'create' : 'new_version');
194 $v->setTitle($revision->getTitle());
195 $v->setDate($information->getCreationDate()->format(DATE_ATOM));
196 $v->setUserId($revision->getOwnerId() !== 0 ? $revision->getOwnerId() : 6);
197 $v->setSize($information->getSize());
198
199 $versions[] = $v;
200 }
201
202 return $versions;
203 }
204
205 public function export(string $target_dir) : void
206 {
207 global $DIC;
208 $relative_dir = LegacyPathHelper::createRelativePath($target_dir);
209 $filesystem = LegacyPathHelper::deriveFilesystemFrom($target_dir);
210
211 if ($filesystem->has($target_dir)) {
212 $directory = $relative_dir . '/objects/il_' . IL_INST_ID . "_file_" . $this->obj_id;
213 $filesystem->createDir($directory);
214 $stream = $DIC->resourceStorage()->consume()->stream($this->resource->getIdentification())->getStream();
215 $filesystem->writeStream(
216 $directory . '/' . $this->resource->getCurrentRevision()->getInformation()->getTitle(),
217 $stream
218 );
219 }
220 }
221
222 public function getStorageID() : ?string
223 {
224 return $this->resource->getStorageID();
225 }
226}
An exception for terminatinating execution or to throw for unit testing.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:19
Class LegacyPathHelper The legacy path helper provides convenient functions for the integration of th...
This exception indicates that an UI component was accepted by the JF but is not backed by a real impl...
Class ilObjFileImplementationAbstract.
Class ilObjFileImplementationStorage.
deleteVersions($a_hist_entry_ids=null)
@inheritDoc
Class ilObjFileVersion.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
Interface ilObjFileImplementationInterface.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$container
Definition: wac.php:13