95 $versions = count($this->file_object->getVersions());
96 if ($versions === 1) {
97 $version_one = $this->file_object->getDirectory(1) .
"/" . $this->file_object->getFileName();
99 $version_two = $this->file_object->getDirectory(2) .
"/" . $this->file_object->getFileName();
101 if (!$this->fs->has($relative_version_one) && $this->fs->has($relative_version_two)) {
109 $dirname = dirname($this->relative_path);
110 if (!$this->fs->has($dirname)) {
111 $this->
log(
"FAILED: Sanitizing File Path: {$this->file_object->getFile()}. Message: Directory not found");
116 $first_file = reset($this->fs->listContents($dirname));
117 }
catch (DirectoryNotFoundException $e) {
118 $this->
log(
"FAILED AGAIN and AGAIN: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}");
126 if (!$this->fs->has($valid_filename)) {
127 $this->fs->rename($first_file->getPath(), $valid_filename);
130 $this->
log(
"Sanitized File Path: {$valid_filename}");
136 $this->
log(
"FAILED: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}. Will try using native PHP");
140 $scandir = scandir(dirname($this->absolute_path));
141 if (isset($scandir[2])) {
142 $first_file = $scandir[2];
143 if (is_file($first_file)) {
145 if (rename($first_file, $valid_filename)) {
147 $this->
log(
"Sanitized File Path: {$valid_filename}");
150 throw new Exception(
"is not a file: " . $first_file);
153 throw new Exception(
"no File found in " . dirname($this->absolute_path));
156 $this->
log(
"FAILED AGAIN: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}");
160 if ($item->isDot()) {
163 if ($item->isFile()) {
165 if (rename($item->getPathname(), $valid_filename)) {
167 $this->
log(
"Sanitized File Path: {$valid_filename}");
173 $this->
log(
"FAILED AGAIN and AGAIN: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}");
static createRelativePath(string $absolute_path)
Creates a relative path from an absolute path which starts with a valid storage location.
saveNewNameForFileObject($valid_filename)
Class FlySystemFileAccessTest.
santitizeFilename($first_file)