ILIAS  release_8 Revision v8.24
ilFileSystemAbstractionStorage Class Reference
+ Inheritance diagram for ilFileSystemAbstractionStorage:
+ Collaboration diagram for ilFileSystemAbstractionStorage:

Public Member Functions

 __construct (int $a_storage_type, bool $a_path_conversion, int $a_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
 
ILIAS Filesystem 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"
 
int $container_id
 
int $storage_type
 
bool $path_conversion = false
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilFileSystemAbstractionStorage::__construct ( int  $a_storage_type,
bool  $a_path_conversion,
int  $a_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 50 of file class.ilFileSystemAbstractionStorage.php.

51 {
52 global $DIC;
53 $this->storage_type = $a_storage_type;
54 $this->path_conversion = $a_path_conversion;
55 $this->container_id = $a_container_id;
56 $this->file_system_service = $DIC->filesystem();
57
58 // Get path info
59 $this->init();
60 }
global $DIC
Definition: feed.php:28

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 243 of file class.ilFileSystemAbstractionStorage.php.

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

Referenced by ilFSStorageCourse\_clone().

+ Here is the caller graph for this function:

◆ appendToPath()

ilFileSystemAbstractionStorage::appendToPath ( string  $a_appendix)

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

275 : void
276 {
277 $this->path .= $a_appendix;
278 }

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 133 of file class.ilFileSystemAbstractionStorage.php.

133 : bool
134 {
135 if (@file_exists($a_from)) {
136 @copy($a_from, $a_to);
137 return true;
138 }
139 return false;
140 }

◆ create()

ilFileSystemAbstractionStorage::create ( )

Reimplemented in ilFSStorageExercise, ilIndividualAssessmentFileStorage, ilTestProcessLockFileStorage, and ilAssQuestionProcessLockFileStorage.

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

155 : void
156 {
157 if (!$this->getFileSystemService()->has($this->path)) {
158 $this->getFileSystemService()->createDir($this->path);
159 }
160 }
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 92 of file class.ilFileSystemAbstractionStorage.php.

92 : string
93 {
94 $path = [];
95 $found = false;
96 $num = $a_container_id;
97 $path_string = '';
98 for ($i = self::MAX_EXPONENT; $i > 0; $i--) {
99 $factor = pow(self::FACTOR, $i);
100 if (($tmp = (int) ($num / $factor)) or $found) {
101 $path[] = $tmp;
102 $num = $num % $factor;
103 $found = true;
104 }
105 }
106
107 if (count($path)) {
108 $path_string = (implode('/', $path) . '/');
109 }
110
111 return $path_string . $a_name . '_' . $a_container_id;
112 }
$i
Definition: metadata.php:41

References $i, and $path.

Referenced by init().

+ Here is the caller graph for this function:

◆ createRelativePathForFileSystem()

ilFileSystemAbstractionStorage::createRelativePathForFileSystem ( string  $a_absolute_path)
private

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

290 : string
291 {
292 $relative_path = ILIAS\Filesystem\Util\LegacyPathHelper::createRelativePath($a_absolute_path);
293
294 return $relative_path;
295 }
static createRelativePath(string $absolute_path)
Creates a relative path from an absolute path which starts with a valid storage location.

References ILIAS\Filesystem\Util\LegacyPathHelper\createRelativePath().

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

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

◆ delete()

ilFileSystemAbstractionStorage::delete ( )

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

218 : bool
219 {
220 try {
221 $this->getFileSystemService()->deleteDir($this->getAbsolutePath());
222 } catch (Exception $e) {
223 return false;
224 }
225
226 return true;
227 }
getAbsolutePath()
Calculates the full path on the filesystem.

References Vendor\Package\$e, getAbsolutePath(), and getFileSystemService().

+ Here is the call graph for this function:

◆ deleteDirectory()

ilFileSystemAbstractionStorage::deleteDirectory ( string  $a_abs_name)

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

229 : bool
230 {
231 $path = $this->createRelativePathForFileSystem($a_abs_name);
232 $this->getFileSystemService()->deleteDir($path);
233 return !$this->getFileSystemService()->has($path);
234 }

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

+ Here is the call graph for this function:

◆ deleteFile()

ilFileSystemAbstractionStorage::deleteFile ( string  $a_abs_name)

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

236 : bool
237 {
238 $path = $this->createRelativePathForFileSystem($a_abs_name);
239 $this->getFileSystemService()->delete($path);
240 return !$this->getFileSystemService()->has($path);
241 }

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

Referenced by ilIndividualAssessmentFileStorage\deleteAllFilesBut(), ilFSStorageCourse\deleteMemberExportFile(), and ilFSStorageGroup\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 62 of file class.ilFileSystemAbstractionStorage.php.

62 : bool
63 {
64 return $this->getFileSystemService()->has($this->createRelativePathForFileSystem($a_absolute_path));
65 }

References createRelativePathForFileSystem(), and getFileSystemService().

Referenced by ilFSStorageCourse\hasMemberExportFile(), and ilFSStorageGroup\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 171 of file class.ilFileSystemAbstractionStorage.php.

171 : string
172 {
173 return rtrim($this->getLegacyAbsolutePath(), "/");
174 }
getLegacyAbsolutePath()
Calculates the absolute filesystem storage location.

References getLegacyAbsolutePath().

Referenced by ilLearningSequenceFilesystem\__construct(), ilFSStorageSession\createDirectory(), delete(), ilFSStorageCourse\getInfoDirectory(), ilFSStorageCourse\getMemberExportDirectory(), ilFSStorageGroup\getMemberExportDirectory(), ilFSStorageMail\getRelativePathExMailDirectory(), and ilFSStorageExercise\init().

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

◆ getContainerId()

ilFileSystemAbstractionStorage::getContainerId ( )

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

References $container_id.

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

+ Here is the caller graph for this function:

◆ getFileSystemService()

ilFileSystemAbstractionStorage::getFileSystemService ( )
protected

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

75 {
76 switch ($this->getStorageType()) {
78 return $this->file_system_service->storage();
82 return $this->file_system_service->web();
83 }
84 throw new LogicException('cannot determine correct filesystem');
85 }
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...

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

Referenced by ilTestProcessLockFileStorage\create(), ilAssQuestionProcessLockFileStorage\create(), 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 183 of file class.ilFileSystemAbstractionStorage.php.

183 : string
184 {
185 if (!$this->getFileSystemService()->has($this->path)) {
186 $this->getFileSystemService()->createDir($this->path);
187 }
188
189 if ($this->getStorageType() === self::STORAGE_DATA) {
190 return rtrim(CLIENT_DATA_DIR, '/') . '/' . ltrim($this->path, '/');
191 }
192 return rtrim(CLIENT_WEB_DIR, '/') . '/' . ltrim($this->path, '/');
193 }
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 67 of file class.ilFileSystemAbstractionStorage.php.

67 : string
68 {
69 $stream = $this->getFileSystemService()->readStream($relative_path);
70
71 return $stream->getMetadata('uri');
72 }

References getFileSystemService().

+ Here is the call graph for this function:

◆ getPath()

ilFileSystemAbstractionStorage::getPath ( )

◆ getPathPostfix()

ilFileSystemAbstractionStorage::getPathPostfix ( )
abstractprotected

◆ getPathPrefix()

◆ getStorageType()

ilFileSystemAbstractionStorage::getStorageType ( )

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

References $storage_type.

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

+ Here is the caller graph for this function:

◆ init()

ilFileSystemAbstractionStorage::init ( )
protected

Reimplemented in ilFSStorageExercise, ilFSWebStorageExercise, and ilRestFileStorage.

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

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

References $container_id, 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 117 of file class.ilFileSystemAbstractionStorage.php.

118 {
119 if (!$fp = @fopen($a_absolute_path, 'w+')) {
120 return false;
121 }
122 if (@fwrite($fp, $a_data) === false) {
123 @fclose($fp);
124 return false;
125 }
126 @fclose($fp);
127 return true;
128 }

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

+ Here is the caller graph for this function:

Field Documentation

◆ $container_id

int ilFileSystemAbstractionStorage::$container_id
private

◆ $file_system_service

ILIAS Filesystem Filesystems ilFileSystemAbstractionStorage::$file_system_service
protected

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

◆ $path

◆ $path_conversion

bool ilFileSystemAbstractionStorage::$path_conversion = false
private

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

◆ $storage_type

int ilFileSystemAbstractionStorage::$storage_type
private

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

Referenced by getStorageType().

◆ FACTOR

const ilFileSystemAbstractionStorage::FACTOR = 100
private

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

◆ MAX_EXPONENT

const ilFileSystemAbstractionStorage::MAX_EXPONENT = 3
private

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

◆ SECURED_DIRECTORY

const ilFileSystemAbstractionStorage::SECURED_DIRECTORY = "sec"
private

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

Referenced by getFileSystemService().

◆ STORAGE_DATA

◆ STORAGE_SECURED

const ilFileSystemAbstractionStorage::STORAGE_SECURED = 3

Definition at line 30 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: