Skip to content

Commit

Permalink
Update ScormService.php
Browse files Browse the repository at this point in the history
  • Loading branch information
qunabu authored Feb 26, 2024
1 parent 22e4e6d commit 511c947
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Services/ScormService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use Ramsey\Uuid\Uuid;
use ZipArchive;
use EscolaLms\Scorm\Services\Contracts\ScormServiceContract;
use Illuminate\Http\File;


class ScormService implements ScormServiceContract
{
Expand All @@ -36,8 +38,7 @@ class ScormService implements ScormServiceContract
*/
public function __construct(
ScormTrackServiceContract $scormTrackService
)
{
) {
$this->scormLib = new ScormLib();
$this->scormTrackService = $scormTrackService;
}
Expand Down Expand Up @@ -228,7 +229,17 @@ private function unzipScormArchive(UploadedFile $file, string $hashName): void
Storage::disk(config('scorm.disk'))->makeDirectory($hashName);
}

$zip->extractTo(Storage::disk(config('scorm.disk'))->path($hashName));
$zip->extractTo(sys_get_temp_dir() . '/' . $hashName);

for ($i = 0; $i < $zip->numFiles; $i++) {

$fileName = $zip->getNameIndex($i);
$f = sys_get_temp_dir() . '/' . $hashName . '/' . $fileName;
if (is_file($f) && !is_dir($f)) {
Storage::disk(config('scorm.disk'))->putFileAs($hashName, new File($f), $fileName);
}
unlink($f);
}
$zip->close();
}

Expand All @@ -245,6 +256,7 @@ private function generateScorm(UploadedFile $file): array
$scormFilePath = 'scorm/' . $scormData['version'] . '/' . $hashName;
$this->unzipScormArchive($file, $scormFilePath);


if (!config()->has('filesystems.disks.' . config('scorm.disk') . '.root')) {
throw new StorageNotFoundException();
}
Expand Down Expand Up @@ -315,7 +327,7 @@ public function zipScormFiles(ScormModel $scorm): string
$scormDisk = Storage::disk(config('scorm.disk'));
$scormPath = 'scorm' . DIRECTORY_SEPARATOR . $scorm->version . DIRECTORY_SEPARATOR . $scorm->hash_name;
$scormFilePath = $scormPath . DIRECTORY_SEPARATOR . $scorm->hash_name . '.zip';
$files = array_filter($scormDisk->allFiles($scormPath), fn($item) => $item !== $scormFilePath);
$files = array_filter($scormDisk->allFiles($scormPath), fn ($item) => $item !== $scormFilePath);

if (!Storage::disk('local')->exists('scorm/exports')) {
Storage::disk('local')->makeDirectory('scorm/exports');
Expand Down

0 comments on commit 511c947

Please sign in to comment.