From 04fc94e0157136e6ce04c3d20edbf2845c4e0ebe Mon Sep 17 00:00:00 2001 From: Khaled Lela Date: Tue, 1 Mar 2022 11:02:49 +0200 Subject: refactor onerror clean resources and throw exception --- src/Manager/ScormDisk.php | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'src/Manager/ScormDisk.php') diff --git a/src/Manager/ScormDisk.php b/src/Manager/ScormDisk.php index 5f15d38..34e4cb6 100644 --- a/src/Manager/ScormDisk.php +++ b/src/Manager/ScormDisk.php @@ -53,20 +53,54 @@ class ScormDisk Storage::writeStream($file, $this->getArchiveDisk()->readStream($file)); $path = Storage::path($file); call_user_func($fn, $path); - unlink($path); // delete temp package - Storage::deleteDirectory(dirname($file)); // delete temp dir + // Clean local resources + $this->clean($file); } catch (Exception $ex) { throw new StorageNotFoundException('scorm_archive_not_found'); } } + private function clean($file) + { + try { + Storage::delete($file); + Storage::deleteDirectory(dirname($file)); // delete temp dir + } catch (Exception $ex) { + } + } + + /** + * @param string $directory + * @return bool + */ + public function deleteScorm($uuid) + { + $this->deleteScormArchive($uuid); // try to delete archive if exists. + return $this->deleteScormContent($uuid); + } + + /** + * @param string $directory + * @return bool + */ + private function deleteScormContent($folderHashedName) + { + try { + return $this->getDisk()->deleteDirectory($folderHashedName); + } catch (Exception $ex) { + } + } + /** * @param string $directory * @return bool */ - public function deleteScormFolder($folderHashedName) + private function deleteScormArchive($uuid) { - return $this->getDisk()->deleteDirectory($folderHashedName); + try { + return $this->getArchiveDisk()->deleteDirectory($uuid); + } catch (Exception $ex) { + } } /** -- cgit v1.2.3