From 9b0b9fcba5346506d3b4ccd5c3e73307c5ff17fe Mon Sep 17 00:00:00 2001 From: Mateusz Qunabu Date: Wed, 5 May 2021 15:10:11 +0200 Subject: [PATCH] Feature/seeder (#42) * the seeder * swagger badge --- composer.json | 6 +- database/seeders/ContentLibrarySeeder.php | 119 ++++++++++++++++++++++ readme.md | 23 +++-- src/Repositories/H5PRepository.php | 3 + 4 files changed, 138 insertions(+), 13 deletions(-) create mode 100644 database/seeders/ContentLibrarySeeder.php diff --git a/composer.json b/composer.json index a013dc04..53c610f9 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,9 @@ "autoload": { "psr-4": { "EscolaLms\\HeadlessH5P\\": "src", - "EscolaLms\\HeadlessH5P\\Tests\\": "tests" + "EscolaLms\\HeadlessH5P\\Tests\\": "tests", + "EscolaLms\\HeadlessH5P\\Database\\Factories\\": "database/factories", + "EscolaLms\\HeadlessH5P\\Database\\Seeders\\": "database/seeders" } }, "license": "Apache-2.0", @@ -33,4 +35,4 @@ ] } } -} +} \ No newline at end of file diff --git a/database/seeders/ContentLibrarySeeder.php b/database/seeders/ContentLibrarySeeder.php new file mode 100644 index 00000000..edc7378a --- /dev/null +++ b/database/seeders/ContentLibrarySeeder.php @@ -0,0 +1,119 @@ +hh5pService->getRepository()->getUploadedH5pPath()); + + // Content update is skipped because it is new registration + $content = null; + $skipContent = !$addContent; + $h5p_upgrade_only = false; + + if ($this->hh5pService->getValidator()->isValidPackage($skipContent, $h5p_upgrade_only)) { + $this->hh5pService->getStorage()->savePackage($content, null, $skipContent); + } else { + echo "Invalid package $filename \n"; + } + + @unlink($this->hh5pService->getRepository()->getUploadedH5pPath()); + + return true; + } + + /** + * Execute the console command. + * + * @return void + */ + public function run(HeadlessH5PServiceContract $hh5pService) + { + $addContent = true; + + $this->hh5pService = $hh5pService; + $libs = [ + "example-content-arts-of-europe-443085.h5p", + "advanced-blanks-example-1-503253.h5p", + "course-presentation-21-21180.h5p", + "interactive-video-2-618.h5p", + "example-content-virtual-tour-360-441814.h5p", + "true-false-question-34806.h5p", + "timeline-3-716.h5p", + "summary-714.h5p", + "speak-the-words-set-example-120784.h5p", + "speak-the-words-73595.h5p", + "example-content-single-choice-set-64682.h5p", + "question-set-616.h5p", + "questionnaire-4-30615.h5p", + "personality-quiz-21254.h5p", + "multiple-choice-713.h5p", + "memory-game-5-708.h5p", + "mark-the-words-2-1408.h5p", + "contact-18-1022298.h5p", + "berries-28-441940.h5p", + "impressive-presentation-7141.h5p", + "image-slider-2-130336.h5p", + "image-sequencing-3-110117.h5p", + "example-content-image-pairing-2-233382.h5p", + "image-juxtaposition-65047.h5p", + "image-hotspots-2-825.h5p", + "iframe-embedder-621.h5p", + "image-multiple-hotspot-question-65081.h5p", + "find-the-hotspot-3024.h5p", + "example-content-find-the-words-557697.h5p", + "flashcards-51-111820.h5p", + "guess-the-answer-2402.h5p", + "fill-in-the-blanks-837.h5p", + "essay-4-166755.h5p", + "drag-the-words-1399.h5p", + "drag-and-drop-712.h5p", + "documentation-tool-3022.h5p", + "chart-7143.h5p", + "collage-3065.h5p", + "h5p-column-34794.h5p", + "dialog-cards-620.h5p", + "dictation-389727.h5p", + "audio-recorder-87-748022.h5p", + "arithmetic-quiz-22-57860.h5p", + "agamotto-80158.h5p", + "advent-blue-snowman-1075566.h5p", + "accordion-6-7138.h5p" + ]; + + foreach ($libs as $lib) { + echo "seeding $lib \n"; + $this->downloadAndSeed($lib, $addContent); + } + } +} diff --git a/readme.md b/readme.md index e678cb7f..bb88efde 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,6 @@ # Headless H5P Laravel API +[![swagger](https://img.shields.io/badge/documentation-swagger-green)](https://escolalms.github.io/H5P/) [![codecov](https://codecov.io/gh/EscolaLMS/H5P/branch/main/graph/badge.svg?token=ci4VPQbrOI)](https://codecov.io/gh/EscolaLMS/H5P) [![phpunit](https://github.com/EscolaLMS/H5P/actions/workflows/test.yml/badge.svg)](https://github.com/EscolaLMS/Core/actions/workflows/test.yml) [![downloads](https://img.shields.io/packagist/dt/escolalms/headless-h5p)](https://packagist.org/packages/escolalms/headless-h5p) @@ -8,7 +9,7 @@ ## Features -The lib allows headlessly +The lib allows headlessly - play all h5p content - exposed all essential data, yet player is needed - edit all h5p content - exposed all essential data, yet editor is needed @@ -19,7 +20,7 @@ The lib allows headlessly See [Swagger](https://escolalms.github.io/H5P/) documented endpoints. -Some [tests](tests) can also be a great point of start. +Some [tests](tests) can also be a great point of start. To play the content you can use [EscolaLMS H5P Player](https://github.com/EscolaLMS/H5P-player) @@ -34,7 +35,7 @@ You need to publish many of files to be availabe as public link. `php artisan h5p:link` which creates a symbolic link from `storage/app/h5` and `vendor/h5p/h5p-core` and `vendor/h5p/h5p-editor` to be accesible to public, as follows - ``` +``` public_path('h5p') => storage_path('app/h5p'), public_path('h5p-core') => base_path().'vendor/h5p/h5p-core', public_path('h5p-editor') => base_path().'vendor/h5p/h5p-editor', @@ -59,12 +60,12 @@ You can seed library and content with build-in seeders that are accessible with - `php artisan h5p:seed` to add just libraries - `php artisan h5p:seed --addContent` to add content with libraries -## Road map +## Road map -- caching -- content export -- some transaltions are missing -- casading delete -- sql foreign keys indexing -- clearup task - deleting temp files, marked for delete -- in some contents, js libs content is invalid +- caching +- content export +- some transaltions are missing +- casading delete +- sql foreign keys indexing +- clearup task - deleting temp files, marked for delete +- in some contents, js libs content is invalid diff --git a/src/Repositories/H5PRepository.php b/src/Repositories/H5PRepository.php index 5d653e4a..712c35a4 100644 --- a/src/Repositories/H5PRepository.php +++ b/src/Repositories/H5PRepository.php @@ -517,6 +517,9 @@ public function updateContent($content, $contentMainId = null) H5PContent::findOrFail($content['id'])->update($content); return $content['id']; } else { + unset($content['params']); + unset($content['library']); + $newContent = H5PContent::create($content); return $newContent->id; }