Skip to content

Commit 88725af

Browse files
Merge pull request #90 from EscolaLMS/issue/upload
Issue/upload
2 parents 412e1cf + b96cbac commit 88725af

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/Repositories/H5PRepository.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use EscolaLms\HeadlessH5P\Models\H5PLibraryLanguage;
1212
use H5PFrameworkInterface;
1313
use Illuminate\Support\Facades\Log;
14+
use TypeError;
1415

1516
class H5PRepository implements H5PFrameworkInterface
1617
{
@@ -636,17 +637,29 @@ public function deleteLibraryUsage($contentId)
636637
*/
637638
public function saveLibraryUsage($contentId, $librariesInUse)
638639
{
639-
$contentLibraries = array_map(function ($value) use ($contentId) {
640-
return H5PContentLibrary::firstOrCreate([
641-
'content_id' => $contentId,
642-
'library_id' => $value['library']['id'],
643-
'dependency_type' => $value['type'],
644-
], [
645-
'drop_css' => boolval($value['library']['dropLibraryCss']),
646-
'weight' => $value['weight'],
640+
$contentLibraries = array_map(function ($value) use ($contentId, &$test) {
641+
try {
642+
return H5PContentLibrary::firstOrCreate([
643+
'content_id' => $contentId,
644+
'library_id' => $value['library']['id'],
645+
'dependency_type' => $value['type'],
646+
], [
647+
'drop_css' => boolval($value['library']['dropLibraryCss']),
648+
'weight' => $value['weight'],
647649
])->toArray();
650+
} catch (TypeError $exception) {
651+
dd([
652+
'drop_css' => boolval($value['library']['dropLibraryCss']),
653+
'weight' => $value['weight'],
654+
],
655+
[
656+
'content_id' => $contentId,
657+
'library_id' => $value['library']['id'],
658+
'dependency_type' => $value['type'],
659+
]
660+
);
661+
}
648662
}, $librariesInUse);
649-
650663
$content = H5PContent::with('library')->findOrFail($contentId);
651664

652665
$libraryLibraries = array_map(function ($value) use ($contentId) {

0 commit comments

Comments
 (0)