49 $this->version = (int) $file_object->
getVersion();
51 $this->absolute_path = $this->file_object->getDirectory($this->version) .
"/" . $this->file_object->getFileName();
63 $fs_relative_path_existing = $this->fs->has($this->relative_path);
65 $native_absolute_path_exists = file_exists($this->absolute_path);
69 !$fs_relative_path_existing
70 || !$fs_valid_relative_path_existing
71 || !$native_absolute_path_exists
72 || !$native_valid_absolute_path_existing
86 $DIC->logger()->root()->debug(
"FilePathSanitizer: " .
$message);
97 $dirname = dirname($this->relative_path);
98 if (!$this->fs->has($dirname)) {
99 $this->
log(
"FAILED: Sanitizing File Path: {$this->file_object->getFile()}. Message: Directory not found");
104 $first_file = reset($this->fs->listContents($dirname));
106 $this->
log(
"FAILED AGAIN and AGAIN: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}");
114 if (!$this->fs->has($valid_filename)) {
115 $this->fs->rename($first_file->getPath(), $valid_filename);
118 $this->
log(
"Sanitized File Path: {$valid_filename}");
124 $this->
log(
"FAILED: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}. Will try using native PHP");
128 $scandir = scandir(dirname($this->absolute_path));
129 if (isset($scandir[2])) {
130 $first_file = $scandir[2];
131 if (is_file($first_file)) {
133 if (rename($first_file, $valid_filename)) {
135 $this->
log(
"Sanitized File Path: {$valid_filename}");
138 throw new Exception(
"is not a file: " . $first_file);
141 throw new Exception(
"no File found in " . dirname($this->absolute_path));
144 $this->
log(
"FAILED AGAIN: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}");
148 if ($item->isDot()) {
151 if ($item->isFile()) {
153 if (rename($item->getPathname(), $valid_filename)) {
155 $this->
log(
"Sanitized File Path: {$valid_filename}");
161 $this->
log(
"FAILED AGAIN and AGAIN: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}");
184 $valid_filename = $first_file;
186 while (preg_match(
'#\p{C}+|^\./#u', $valid_filename)) {
187 $valid_filename = preg_replace(
'#\p{C}+|^\./#u',
'', $valid_filename);
190 $valid_filename = preg_replace(
'/[\x00-\x1F\x7F-\xFF]/',
'', $valid_filename);
199 return $valid_filename;
208 $sanitized_filename = basename($valid_filename);
209 $this->file_object->setFileName($sanitized_filename);
210 $this->file_object->update();
static createRelativePath(string $absolute_path)
Creates a relative path from an absolute path which starts with a valid storage location.
__construct(ilObjFile $file_object)
FilePathSanitizer constructor.
Class ChatMainBarProvider .
Class DirectoryNotFoundException Indicates that the directory is missing or not found.
static deriveFilesystemFrom(string $absolute_path)
Tries to fetch the filesystem responsible for the absolute path.
saveNewNameForFileObject($valid_filename)
Class FlySystemFileAccessTest disabled disabled disabled.
static getValidFilename($a_filename)
Get valid filename.
santitizeFilename($first_file)