ILIAS  release_8 Revision v8.23
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.

References $DIC, and init().

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
+ 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.

Referenced by ilFSStorageCourse\_clone(), and ilObjPortfolioBase\cloneBasics().

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

◆ appendToPath()

ilFileSystemAbstractionStorage::appendToPath ( string  $a_appendix)

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

Referenced by ilFSStorageMail\__construct().

275  : void
276  {
277  $this->path .= $a_appendix;
278  }
+ 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.

References getPathPostfix(), and getPathPrefix().

133  : bool
134  {
135  if (@file_exists($a_from)) {
136  @copy($a_from, $a_to);
137  return true;
138  }
139  return false;
140  }
+ Here is the call graph for this function:

◆ create()

ilFileSystemAbstractionStorage::create ( )

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

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

Referenced by ilLearningSequenceFilesystem\__construct(), ilExAssignment\cloneAssignmentsOfExercise(), ilExAssignmentEditorGUI\executeCommand(), ilExerciseDataSet\importRecord(), and ilRestFileStorage\init().

155  : void
156  {
157  if (!$this->getFileSystemService()->has($this->path)) {
158  $this->getFileSystemService()->createDir($this->path);
159  }
160  }
has(string $class_name)
+ 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.

References $i.

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

◆ createRelativePathForFileSystem()

ilFileSystemAbstractionStorage::createRelativePathForFileSystem ( string  $a_absolute_path)
private

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

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

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

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.
+ 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.

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

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

◆ deleteDirectory()

ilFileSystemAbstractionStorage::deleteDirectory ( string  $a_abs_name)

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

References createRelativePathForFileSystem(), and getFileSystemService().

Referenced by ilExcCriteriaFile\resetReview().

229  : bool
230  {
231  $path = $this->createRelativePathForFileSystem($a_abs_name);
232  $this->getFileSystemService()->deleteDir($path);
233  return !$this->getFileSystemService()->has($path);
234  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteFile()

ilFileSystemAbstractionStorage::deleteFile ( string  $a_abs_name)

◆ fileExists()

ilFileSystemAbstractionStorage::fileExists ( string  $a_absolute_path)

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

References createRelativePathForFileSystem(), and getFileSystemService().

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

62  : bool
63  {
64  return $this->getFileSystemService()->has($this->createRelativePathForFileSystem($a_absolute_path));
65  }
+ 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.

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

References getLegacyAbsolutePath().

Referenced by ilLearningSequenceFilesystem\__construct(), ilExAssignment\cloneAssignmentsOfExercise(), ilFSStorageSession\createDirectory(), delete(), ilFSWebStorageExercise\getAssignmentFilePath(), ilFSStorageExercise\getAssignmentFilePath(), ilFSStorageCourse\getInfoDirectory(), ilFSStorageGroup\getMemberExportDirectory(), ilFSStorageCourse\getMemberExportDirectory(), ilFSStorageMail\getRelativePathExMailDirectory(), ilLearningSequenceFilesystem\getStoragePath(), ilFSStorageExercise\init(), ilFSWebStorageExercise\uploadAssignmentFiles(), and ilFSStorageExercise\uploadAssignmentFiles().

171  : string
172  {
173  return rtrim($this->getLegacyAbsolutePath(), "/");
174  }
getLegacyAbsolutePath()
Calculates the absolute filesystem storage location.
+ 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 ilFSStorageGroup\getMemberExportFiles(), and ilFSStorageCourse\getMemberExportFiles().

+ Here is the caller graph for this function:

◆ getFileSystemService()

ilFileSystemAbstractionStorage::getFileSystemService ( )
protected

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

References getStorageType().

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

74  : Filesystem
75  {
76  switch ($this->getStorageType()) {
77  case self::STORAGE_DATA:
78  return $this->file_system_service->storage();
79  case self::STORAGE_WEB:
80  case self::STORAGE_SECURED:
81  case self::SECURED_DIRECTORY:
82  return $this->file_system_service->web();
83  }
84  throw new LogicException('cannot determine correct filesystem');
85  }
Class FlySystemFileAccessTest disabled disabled disabled.
+ 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.

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

Referenced by getAbsolutePath().

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  }
has(string $class_name)
const CLIENT_DATA_DIR
Definition: constants.php:46
const CLIENT_WEB_DIR
Definition: constants.php:47
+ 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.

References getFileSystemService().

67  : string
68  {
69  $stream = $this->getFileSystemService()->readStream($relative_path);
70 
71  return $stream->getMetadata('uri');
72  }
+ Here is the call graph for this function:

◆ 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

Referenced by copyFile(), and 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

Referenced by copyFile(), and init().

+ Here is the caller graph for this function:

◆ getStorageType()

ilFileSystemAbstractionStorage::getStorageType ( )

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

References $storage_type.

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

280  : int
281  {
282  return $this->storage_type;
283  }
+ Here is the caller graph for this function:

◆ init()

ilFileSystemAbstractionStorage::init ( )
protected

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

References $container_id, getPathPostfix(), and getPathPrefix().

Referenced by __construct().

195  : bool
196  {
197  switch ($this->storage_type) {
198  case self::STORAGE_DATA:
199  case self::STORAGE_WEB:
200  break;
201  case self::STORAGE_SECURED:
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  }
getPathPostfix()
Get directory name.
getPathPrefix()
Get path prefix.
+ 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.

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

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  }
+ 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.

◆ STORAGE_DATA

◆ STORAGE_SECURED

const ilFileSystemAbstractionStorage::STORAGE_SECURED = 3

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

◆ STORAGE_WEB

const ilFileSystemAbstractionStorage::STORAGE_WEB = 1

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


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