|
11 | 11 | use EscolaLms\HeadlessH5P\Models\H5PLibraryLanguage;
|
12 | 12 | use H5PFrameworkInterface;
|
13 | 13 | use Illuminate\Support\Facades\Log;
|
| 14 | +use TypeError; |
14 | 15 |
|
15 | 16 | class H5PRepository implements H5PFrameworkInterface
|
16 | 17 | {
|
@@ -636,17 +637,29 @@ public function deleteLibraryUsage($contentId)
|
636 | 637 | */
|
637 | 638 | public function saveLibraryUsage($contentId, $librariesInUse)
|
638 | 639 | {
|
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'], |
647 | 649 | ])->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 | + } |
648 | 662 | }, $librariesInUse);
|
649 |
| - |
650 | 663 | $content = H5PContent::with('library')->findOrFail($contentId);
|
651 | 664 |
|
652 | 665 | $libraryLibraries = array_map(function ($value) use ($contentId) {
|
|
0 commit comments