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

Public Member Functions

 __construct (private int $storage_type, private bool $path_conversion, private int $container_id)
 Constructor. More...
 
 fileExists (string $a_absolute_path)
 
 getContainerId ()
 
 writeToFile (string $a_data, $a_absolute_path)
 
 copyFile (string $a_from, string $a_to)
 
 create ()
 
 getAbsolutePath ()
 Calculates the full path on the filesystem. More...
 
 delete ()
 
 deleteDirectory (string $a_abs_name)
 
 deleteFile (string $a_abs_name)
 
 appendToPath (string $a_appendix)
 
 getStorageType ()
 
 getPath ()
 

Static Public Member Functions

static createPathFromId (int $a_container_id, string $a_name)
 
static _copyDirectory (string $a_sdir, string $a_tdir)
 

Data Fields

const STORAGE_WEB = 1
 
const STORAGE_DATA = 2
 
const STORAGE_SECURED = 3
 

Protected Member Functions

 getLegacyFullAbsolutePath (string $relative_path)
 
 getFileSystemService ()
 
 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get directory name. More...
 
 getLegacyAbsolutePath ()
 Calculates the absolute filesystem storage location. More...
 
 init ()
 

Protected Attributes

string $path = null
 
Filesystems $file_system_service
 

Private Member Functions

 createRelativePathForFileSystem (string $a_absolute_path)
 

Private Attributes

const FACTOR = 100
 
const MAX_EXPONENT = 3
 
const SECURED_DIRECTORY = "sec"
 

Detailed Description

Deprecated:
Will be removed in ILIAS 10. Use ILIAS ResourceStorageService as replacement.

Definition at line 27 of file class.ilFileSystemAbstractionStorage.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileSystemAbstractionStorage::__construct ( private int  $storage_type,
private bool  $path_conversion,
private int  $container_id 
)

Constructor.

Parameters
$a_storage_typeint storage type
$a_path_conversionbool En/Disable automatic path conversion. If enabled files with id 123 will be stored in directory files/1/file_123 object id of container
$a_container_idint (e.g file_id or mob_id)

Definition at line 48 of file class.ilFileSystemAbstractionStorage.php.

49 {
50 global $DIC;
51 $this->file_system_service = $DIC->filesystem();
52
53 // Get path info
54 $this->init();
55 }
global $DIC
Definition: shib_login.php:26

References $DIC, and init().

+ Here is the call graph for this function:

Member Function Documentation

◆ _copyDirectory()

static ilFileSystemAbstractionStorage::_copyDirectory ( string  $a_sdir,
string  $a_tdir 
)
static

Definition at line 238 of file class.ilFileSystemAbstractionStorage.php.

238 : bool
239 {
240 try {
241 $sourceFS = LegacyPathHelper::deriveFilesystemFrom($a_sdir);
242 $targetFS = LegacyPathHelper::deriveFilesystemFrom($a_tdir);
243
244 $sourceDir = LegacyPathHelper::createRelativePath($a_sdir);
245 $targetDir = LegacyPathHelper::createRelativePath($a_tdir);
246
247 // check if arguments are directories
248 if (!$sourceFS->hasDir($sourceDir)) {
249 return false;
250 }
251
252 $sourceList = $sourceFS->listContents($sourceDir, true);
253
254 foreach ($sourceList as $item) {
255 if ($item->isDir()) {
256 continue;
257 }
258
259 $itemPath = $targetDir . '/' . substr($item->getPath(), strlen($sourceDir));
260 $stream = $sourceFS->readStream($sourceDir);
261 $targetFS->writeStream($itemPath, $stream);
262 }
263
264 return true;
265 } catch (\Exception) {
266 return false;
267 }
268 }

Referenced by ilFSStorageCourse\_clone().

+ Here is the caller graph for this function:

◆ appendToPath()

ilFileSystemAbstractionStorage::appendToPath ( string  $a_appendix)

Definition at line 270 of file class.ilFileSystemAbstractionStorage.php.

270 : void
271 {
272 $this->path .= $a_appendix;
273 }

Referenced by ilFSStorageMail\__construct().

+ Here is the caller graph for this function:

◆ copyFile()

ilFileSystemAbstractionStorage::copyFile ( string  $a_from,
string  $a_to 
)
Deprecated:
Please use StorageService or FilesystemService for all file opertion

Definition at line 128 of file class.ilFileSystemAbstractionStorage.php.

128 : bool
129 {
130 if (@file_exists($a_from)) {
131 @copy($a_from, $a_to);
132 return true;
133 }
134 return false;
135 }

◆ create()

ilFileSystemAbstractionStorage::create ( )

Reimplemented in ilIndividualAssessmentFileStorage, ilTestProcessLockFileStorage, and ilAssQuestionProcessLockFileStorage.

Definition at line 150 of file class.ilFileSystemAbstractionStorage.php.

150 : void
151 {
152 if (!$this->getFileSystemService()->has($this->path)) {
153 $this->getFileSystemService()->createDir($this->path);
154 }
155 }
has(string $class_name)

References getFileSystemService(), and ILIAS\GlobalScreen\has().

Referenced by ilLearningSequenceFilesystem\__construct(), and ilRestFileStorage\init().

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

◆ createPathFromId()

static ilFileSystemAbstractionStorage::createPathFromId ( int  $a_container_id,
string  $a_name 
)
static

Definition at line 87 of file class.ilFileSystemAbstractionStorage.php.

87 : string
88 {
89 $path = [];
90 $found = false;
91 $num = $a_container_id;
92 $path_string = '';
93 for ($i = self::MAX_EXPONENT; $i > 0; $i--) {
94 $factor = self::FACTOR ** $i;
95 if (($tmp = (int) ($num / $factor)) or $found) {
96 $path[] = $tmp;
97 $num %= $factor;
98 $found = true;
99 }
100 }
101
102 if ($path !== []) {
103 $path_string = (implode('/', $path) . '/');
104 }
105
106 return $path_string . $a_name . '_' . $a_container_id;
107 }

References $path.

Referenced by ilExerciseInstructionFilesMigration\buildAbsolutPath(), ilExerciseSampleSolutionMigration\buildAbsolutPath(), ilExercisePeerFeedbackMigration\buildAbsolutPath(), ilExerciseSubmissionMigration\buildAbsolutPath(), ilExerciseTutorFeedbackFileMigration\buildAbsolutPath(), ilExerciseTutorTeamFeedbackFileMigration\buildAbsolutPath(), ilBookingManagerBookingInfoMigration\buildAbsolutPath(), ilBookingManagerObjectInfoMigration\buildAbsolutPath(), ilPollImagesMigration\getLegacyPath(), init(), and ilExerciseManagementGUI\openSubmissionViewObject().

+ Here is the caller graph for this function:

◆ createRelativePathForFileSystem()

ilFileSystemAbstractionStorage::createRelativePathForFileSystem ( string  $a_absolute_path)
private

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

285 : string
286 {
287 $relative_path = LegacyPathHelper::createRelativePath($a_absolute_path);
288
289 return $relative_path;
290 }

Referenced by deleteDirectory(), deleteFile(), and fileExists().

+ Here is the caller graph for this function:

◆ delete()

ilFileSystemAbstractionStorage::delete ( )

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

213 : bool
214 {
215 try {
216 $this->getFileSystemService()->deleteDir($this->getAbsolutePath());
217 } catch (Exception) {
218 return false;
219 }
220
221 return true;
222 }
getAbsolutePath()
Calculates the full path on the filesystem.

References getAbsolutePath(), and getFileSystemService().

+ Here is the call graph for this function:

◆ deleteDirectory()

ilFileSystemAbstractionStorage::deleteDirectory ( string  $a_abs_name)

Definition at line 224 of file class.ilFileSystemAbstractionStorage.php.

224 : bool
225 {
226 $path = $this->createRelativePathForFileSystem($a_abs_name);
227 $this->getFileSystemService()->deleteDir($path);
228 return !$this->getFileSystemService()->has($path);
229 }

References $path, createRelativePathForFileSystem(), and getFileSystemService().

+ Here is the call graph for this function:

◆ deleteFile()

ilFileSystemAbstractionStorage::deleteFile ( string  $a_abs_name)

Definition at line 231 of file class.ilFileSystemAbstractionStorage.php.

231 : bool
232 {
233 $path = $this->createRelativePathForFileSystem($a_abs_name);
234 $this->getFileSystemService()->delete($path);
235 return !$this->getFileSystemService()->has($path);
236 }

References $path, createRelativePathForFileSystem(), and getFileSystemService().

Referenced by ilIndividualAssessmentFileStorage\deleteAllFilesBut(), ilFSStorageCourse\deleteMemberExportFile(), ilFSStorageGroup\deleteMemberExportFile(), and ilFSStoragePRG\deleteMemberExportFile().

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

◆ fileExists()

ilFileSystemAbstractionStorage::fileExists ( string  $a_absolute_path)

Definition at line 57 of file class.ilFileSystemAbstractionStorage.php.

57 : bool
58 {
59 return $this->getFileSystemService()->has($this->createRelativePathForFileSystem($a_absolute_path));
60 }

References createRelativePathForFileSystem(), and getFileSystemService().

Referenced by ilFSStorageCourse\hasMemberExportFile(), ilFSStorageGroup\hasMemberExportFile(), and ilFSStoragePRG\hasMemberExportFile().

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

◆ getAbsolutePath()

ilFileSystemAbstractionStorage::getAbsolutePath ( )

Calculates the full path on the filesystem.

This method is filesystem aware and will create the absolute path if it's not already existing.

Returns
string Absolute filesystem path.
Exceptions
IOExceptionThrown if the absolute path could not be created.

Reimplemented in ilIndividualAssessmentFileStorage.

Definition at line 166 of file class.ilFileSystemAbstractionStorage.php.

166 : string
167 {
168 return rtrim($this->getLegacyAbsolutePath(), "/");
169 }
getLegacyAbsolutePath()
Calculates the absolute filesystem storage location.

References getLegacyAbsolutePath().

Referenced by ilLearningSequenceFilesystem\__construct(), delete(), ilFSStorageCourse\getInfoDirectory(), ilFSStorageCourse\getMemberExportDirectory(), ilFSStorageGroup\getMemberExportDirectory(), ilFSStoragePRG\getMemberExportDirectory(), and ilFSStorageMail\getRelativePathExMailDirectory().

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

◆ getContainerId()

ilFileSystemAbstractionStorage::getContainerId ( )

Definition at line 82 of file class.ilFileSystemAbstractionStorage.php.

82 : int
83 {
84 return $this->container_id;
85 }

Referenced by ilFSStorageCourse\getMemberExportFiles(), ilFSStorageGroup\getMemberExportFiles(), and ilFSStoragePRG\getMemberExportFiles().

+ Here is the caller graph for this function:

◆ getFileSystemService()

ilFileSystemAbstractionStorage::getFileSystemService ( )
protected

Definition at line 69 of file class.ilFileSystemAbstractionStorage.php.

70 {
71 switch ($this->getStorageType()) {
73 return $this->file_system_service->storage();
77 return $this->file_system_service->web();
78 }
79 throw new LogicException('cannot determine correct filesystem');
80 }
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37

References getStorageType(), SECURED_DIRECTORY, STORAGE_DATA, STORAGE_SECURED, and STORAGE_WEB.

Referenced by create(), ilTestProcessLockFileStorage\create(), ilAssQuestionProcessLockFileStorage\create(), delete(), deleteDirectory(), deleteFile(), fileExists(), getLegacyAbsolutePath(), and getLegacyFullAbsolutePath().

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

◆ getLegacyAbsolutePath()

ilFileSystemAbstractionStorage::getLegacyAbsolutePath ( )
protected

Calculates the absolute filesystem storage location.

Returns
string The absolute path.
Exceptions
IOExceptionThrown if the directory could not be created.

Definition at line 178 of file class.ilFileSystemAbstractionStorage.php.

178 : string
179 {
180 if (!$this->getFileSystemService()->has($this->path)) {
181 $this->getFileSystemService()->createDir($this->path);
182 }
183
184 if ($this->getStorageType() === self::STORAGE_DATA) {
185 return rtrim(CLIENT_DATA_DIR, '/') . '/' . ltrim((string) $this->path, '/');
186 }
187 return rtrim(CLIENT_WEB_DIR, '/') . '/' . ltrim((string) $this->path, '/');
188 }
const CLIENT_WEB_DIR
Definition: constants.php:47
const CLIENT_DATA_DIR
Definition: constants.php:46

References CLIENT_DATA_DIR, CLIENT_WEB_DIR, getFileSystemService(), getStorageType(), and ILIAS\GlobalScreen\has().

Referenced by getAbsolutePath().

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

◆ getLegacyFullAbsolutePath()

ilFileSystemAbstractionStorage::getLegacyFullAbsolutePath ( string  $relative_path)
protected

Definition at line 62 of file class.ilFileSystemAbstractionStorage.php.

62 : string
63 {
64 $stream = $this->getFileSystemService()->readStream($relative_path);
65
66 return $stream->getMetadata('uri');
67 }

References getFileSystemService().

+ Here is the call graph for this function:

◆ getPath()

ilFileSystemAbstractionStorage::getPath ( )

◆ getPathPostfix()

ilFileSystemAbstractionStorage::getPathPostfix ( )
abstractprotected

Get directory name.

E.g for files => file Only relative path, no trailing slash '_<obj_id>' will be appended automatically

Reimplemented in ilFSStorageBadge, ilFSStorageBadgeImageTemplate, ilFSStorageCourse, ilFSStorageFile, ilFSStorageGroup, ilIndividualAssessmentFileStorage, ilLearningSequenceFilesystem, ilFSStorageMail, ilFSStoragePRG, ilTestProcessLockFileStorage, ilAssQuestionProcessLockFileStorage, ilVerificationStorageFile, and ilRestFileStorage.

Referenced by init().

+ Here is the caller graph for this function:

◆ getPathPrefix()

ilFileSystemAbstractionStorage::getPathPrefix ( )
abstractprotected

Get path prefix.

Prefix that will be prepended to the path No trailing slash. E.g ilFiles for files

Reimplemented in ilFSStorageBadge, ilFSStorageBadgeImageTemplate, ilFSStorageCourse, ilFSStorageFile, ilFSStorageGroup, ilIndividualAssessmentFileStorage, ilLearningSequenceFilesystem, ilFSStorageMail, ilFSStoragePRG, ilTestProcessLockFileStorage, ilAssQuestionProcessLockFileStorage, ilVerificationStorageFile, and ilRestFileStorage.

Referenced by init().

+ Here is the caller graph for this function:

◆ getStorageType()

ilFileSystemAbstractionStorage::getStorageType ( )

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

275 : int
276 {
277 return $this->storage_type;
278 }

Referenced by getFileSystemService(), getLegacyAbsolutePath(), and ilFSStorageMail\getRelativePathExMailDirectory().

+ Here is the caller graph for this function:

◆ init()

ilFileSystemAbstractionStorage::init ( )
protected

Reimplemented in ilRestFileStorage.

Definition at line 190 of file class.ilFileSystemAbstractionStorage.php.

190 : bool
191 {
192 switch ($this->storage_type) {
195 break;
197 $this->path = rtrim($this->path ?? '', '/') . '/' . self::SECURED_DIRECTORY . '/';
198 break;
199 }
200
201 // Append path prefix
202 $this->path .= ($this->getPathPrefix() . '/');
203
204 if ($this->path_conversion) {
205 $this->path .= self::createPathFromId($this->container_id, $this->getPathPostfix());
206 } else {
207 $this->path .= ($this->getPathPostfix() . '_' . $this->container_id);
208 }
209
210 return true;
211 }
static createPathFromId(int $a_container_id, string $a_name)
getPathPrefix()
Get path prefix.
getPathPostfix()
Get directory name.

References createPathFromId(), getPathPostfix(), getPathPrefix(), STORAGE_DATA, STORAGE_SECURED, and STORAGE_WEB.

Referenced by __construct().

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

◆ writeToFile()

ilFileSystemAbstractionStorage::writeToFile ( string  $a_data,
  $a_absolute_path 
)
Deprecated:
Please use StorageService or FilesystemService for all file opertion

Definition at line 112 of file class.ilFileSystemAbstractionStorage.php.

113 {
114 if (!$fp = @fopen($a_absolute_path, 'w+')) {
115 return false;
116 }
117 if (@fwrite($fp, $a_data) === false) {
118 @fclose($fp);
119 return false;
120 }
121 @fclose($fp);
122 return true;
123 }

Referenced by ilFSStorageCourse\addMemberExportFile(), ilFSStoragePRG\addMemberExportFile(), and ilFSStorageGroup\addMemberExportFile().

+ Here is the caller graph for this function:

Field Documentation

◆ $file_system_service

Filesystems ilFileSystemAbstractionStorage::$file_system_service
protected

Definition at line 36 of file class.ilFileSystemAbstractionStorage.php.

◆ $path

◆ FACTOR

const ilFileSystemAbstractionStorage::FACTOR = 100
private

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

◆ MAX_EXPONENT

const ilFileSystemAbstractionStorage::MAX_EXPONENT = 3
private

Definition at line 33 of file class.ilFileSystemAbstractionStorage.php.

◆ SECURED_DIRECTORY

const ilFileSystemAbstractionStorage::SECURED_DIRECTORY = "sec"
private

Definition at line 34 of file class.ilFileSystemAbstractionStorage.php.

Referenced by getFileSystemService().

◆ STORAGE_DATA

◆ STORAGE_SECURED

const ilFileSystemAbstractionStorage::STORAGE_SECURED = 3

Definition at line 31 of file class.ilFileSystemAbstractionStorage.php.

Referenced by getFileSystemService(), and init().

◆ STORAGE_WEB

const ilFileSystemAbstractionStorage::STORAGE_WEB = 1

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