From 359e2588a4962f51c0d5cbdd2823530a15defee0 Mon Sep 17 00:00:00 2001 From: devianl2 Date: Fri, 11 Feb 2022 12:05:11 +0800 Subject: Revert "Improve SCORM disk storage handler" --- src/Manager/ScormDisk.php | 74 ----------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/Manager/ScormDisk.php (limited to 'src/Manager/ScormDisk.php') diff --git a/src/Manager/ScormDisk.php b/src/Manager/ScormDisk.php deleted file mode 100644 index 249f027..0000000 --- a/src/Manager/ScormDisk.php +++ /dev/null @@ -1,74 +0,0 @@ -cleanPath($path); - - $zipArchive = new ZipArchive(); - if ($zipArchive->open($file) !== true) { - return false; - } - - /** @var FilesystemAdapter $disk */ - $disk = $this->getDisk(); - - for ($i = 0; $i < $zipArchive->numFiles; ++$i) { - $zipEntryName = $zipArchive->getNameIndex($i); - $destination = $path . DIRECTORY_SEPARATOR . $this->cleanPath($zipEntryName); - if ($this->isDirectory($zipEntryName)) { - $disk->createDir($destination); - continue; - } - $disk->putStream($destination, $zipArchive->getStream($zipEntryName)); - } - - return true; - } - - /** - * @param string $directory - * @return bool - */ - public function deleteScormFolder($folderHashedName) - { - return $this->getDisk()->deleteDirectory($folderHashedName); - } - - private function isDirectory($zipEntryName) - { - return substr($zipEntryName, -1) === '/'; - } - - private function cleanPath($path) - { - return str_replace('/', DIRECTORY_SEPARATOR, $path); - } - - /** - * @return FilesystemAdapter $disk - */ - private function getDisk() - { - if (!config()->has('filesystems.disks.' . config('scorm.disk'))) { - throw new StorageNotFoundException('scorm_disk_not_define'); - } - return Storage::disk(config('scorm.disk')); - } -} -- cgit v1.2.3 From 2c643200d419e1ffae72eb8fb7c392a057a0c9b9 Mon Sep 17 00:00:00 2001 From: devianl2 Date: Fri, 11 Feb 2022 12:39:14 +0800 Subject: Revert "Revert "Improve SCORM disk storage handler"" --- src/Manager/ScormDisk.php | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/Manager/ScormDisk.php (limited to 'src/Manager/ScormDisk.php') diff --git a/src/Manager/ScormDisk.php b/src/Manager/ScormDisk.php new file mode 100644 index 0000000..249f027 --- /dev/null +++ b/src/Manager/ScormDisk.php @@ -0,0 +1,74 @@ +cleanPath($path); + + $zipArchive = new ZipArchive(); + if ($zipArchive->open($file) !== true) { + return false; + } + + /** @var FilesystemAdapter $disk */ + $disk = $this->getDisk(); + + for ($i = 0; $i < $zipArchive->numFiles; ++$i) { + $zipEntryName = $zipArchive->getNameIndex($i); + $destination = $path . DIRECTORY_SEPARATOR . $this->cleanPath($zipEntryName); + if ($this->isDirectory($zipEntryName)) { + $disk->createDir($destination); + continue; + } + $disk->putStream($destination, $zipArchive->getStream($zipEntryName)); + } + + return true; + } + + /** + * @param string $directory + * @return bool + */ + public function deleteScormFolder($folderHashedName) + { + return $this->getDisk()->deleteDirectory($folderHashedName); + } + + private function isDirectory($zipEntryName) + { + return substr($zipEntryName, -1) === '/'; + } + + private function cleanPath($path) + { + return str_replace('/', DIRECTORY_SEPARATOR, $path); + } + + /** + * @return FilesystemAdapter $disk + */ + private function getDisk() + { + if (!config()->has('filesystems.disks.' . config('scorm.disk'))) { + throw new StorageNotFoundException('scorm_disk_not_define'); + } + return Storage::disk(config('scorm.disk')); + } +} -- cgit v1.2.3 From a3643727ec1f398b3e8e2fc7e4160e3346b8fe99 Mon Sep 17 00:00:00 2001 From: Christopher Thomas Date: Fri, 18 Mar 2022 19:34:17 +0000 Subject: Update ScormDisk.php Added forward compatibility with flysystem API v2 while maintaining V1 compatibility. Notable changes for ScormDisk.php - - $filesystem->createDir($path); + $filesystem->createDirectory($path); - $filesystem->putStream($path, $contents); + $filesystem->writeStream($path, $contents); --- src/Manager/ScormDisk.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/Manager/ScormDisk.php') diff --git a/src/Manager/ScormDisk.php b/src/Manager/ScormDisk.php index 249f027..ef82d1c 100644 --- a/src/Manager/ScormDisk.php +++ b/src/Manager/ScormDisk.php @@ -28,15 +28,22 @@ class ScormDisk /** @var FilesystemAdapter $disk */ $disk = $this->getDisk(); + $createDir = 'createDir'; + $putStream = 'putStream'; + + if (!method_exists($disk, $createDir)) { + $createDir = 'createDirectory'; + $putStream = 'writeStream'; + } for ($i = 0; $i < $zipArchive->numFiles; ++$i) { $zipEntryName = $zipArchive->getNameIndex($i); $destination = $path . DIRECTORY_SEPARATOR . $this->cleanPath($zipEntryName); if ($this->isDirectory($zipEntryName)) { - $disk->createDir($destination); + $disk->$createDir($destination); continue; } - $disk->putStream($destination, $zipArchive->getStream($zipEntryName)); + $disk->$putStream($destination, $zipArchive->getStream($zipEntryName)); } return true; -- cgit v1.2.3