48 public function __construct(
private int $storage_type,
private bool $path_conversion,
private int $container_id)
51 $this->file_system_service = $DIC->filesystem();
57 public function fileExists(
string $a_absolute_path): bool
66 return $stream->getMetadata(
'uri');
72 case self::STORAGE_DATA:
73 return $this->file_system_service->storage();
74 case self::STORAGE_WEB:
75 case self::STORAGE_SECURED:
76 case self::SECURED_DIRECTORY:
77 return $this->file_system_service->web();
84 return $this->container_id;
91 $num = $a_container_id;
93 for ($i = self::MAX_EXPONENT; $i > 0; $i--) {
94 $factor = self::FACTOR ** $i;
95 if (($tmp = (
int) ($num / $factor)) or $found) {
103 $path_string = (implode(
'/', $path) .
'/');
106 return $path_string . $a_name .
'_' . $a_container_id;
114 if (!$fp = @fopen($a_absolute_path,
'w+')) {
117 if (@fwrite($fp, $a_data) ===
false) {
128 public function copyFile(
string $a_from,
string $a_to): bool
130 if (@file_exists($a_from)) {
131 @copy($a_from, $a_to);
185 return rtrim(
CLIENT_DATA_DIR,
'/') .
'/' . ltrim((
string) $this->path,
'/');
187 return rtrim(
CLIENT_WEB_DIR,
'/') .
'/' . ltrim((
string) $this->path,
'/');
190 protected function init(): bool
192 switch ($this->storage_type) {
193 case self::STORAGE_DATA:
194 case self::STORAGE_WEB:
196 case self::STORAGE_SECURED:
197 $this->path = rtrim($this->path ??
'',
'/') .
'/' . self::SECURED_DIRECTORY .
'/';
204 if ($this->path_conversion) {
205 $this->path .= self::createPathFromId($this->container_id, $this->
getPathPostfix());
207 $this->path .= ($this->
getPathPostfix() .
'_' . $this->container_id);
213 public function delete():
bool 241 $sourceFS = LegacyPathHelper::deriveFilesystemFrom($a_sdir);
242 $targetFS = LegacyPathHelper::deriveFilesystemFrom($a_tdir);
244 $sourceDir = LegacyPathHelper::createRelativePath($a_sdir);
245 $targetDir = LegacyPathHelper::createRelativePath($a_tdir);
248 if (!$sourceFS->hasDir($sourceDir)) {
252 $sourceList = $sourceFS->listContents($sourceDir,
true);
254 foreach ($sourceList as $item) {
255 if ($item->isDir()) {
259 $itemPath = $targetDir .
'/' . substr($item->getPath(), strlen($sourceDir));
260 $stream = $sourceFS->readStream($sourceDir);
261 $targetFS->writeStream($itemPath, $stream);
272 $this->path .= $a_appendix;
277 return $this->storage_type;
287 $relative_path = LegacyPathHelper::createRelativePath($a_absolute_path);
289 return $relative_path;
getPathPostfix()
Get directory name.
appendToPath(string $a_appendix)
deleteDirectory(string $a_abs_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createRelativePathForFileSystem(string $a_absolute_path)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
fileExists(string $a_absolute_path)
getPathPrefix()
Get path prefix.
static createPathFromId(int $a_container_id, string $a_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
copyFile(string $a_from, string $a_to)
__construct(private int $storage_type, private bool $path_conversion, private int $container_id)
Constructor.
getLegacyAbsolutePath()
Calculates the absolute filesystem storage location.
getAbsolutePath()
Calculates the full path on the filesystem.
writeToFile(string $a_data, $a_absolute_path)
Filesystems $file_system_service
getLegacyFullAbsolutePath(string $relative_path)
static _copyDirectory(string $a_sdir, string $a_tdir)
The Filesystems interface defines the access methods which can be used to fetch the different filesys...
deleteFile(string $a_abs_name)