From 5054e2d5936c33903196ec4d797029917b0123fe Mon Sep 17 00:00:00 2001 From: Micheal Date: Wed, 5 May 2021 14:26:10 +0200 Subject: [PATCH 1/4] Remove contentUserData and refactor --- Resources/config/services.yml | 2 +- Service/ResultService.php | 30 ++++++++++++------------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 804298d..51270d2 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -78,7 +78,7 @@ services: studit_h5p.result_storage: class: Studit\H5PBundle\Service\ResultService - arguments: ['@service_container'] + arguments: ['@doctrine.orm.entity_manager'] Studit\H5PBundle\Service\ResultService: '@studit_h5p.result_storage' Studit\H5PBundle\Command\H5pBundleIncludeAssetsCommand: diff --git a/Service/ResultService.php b/Service/ResultService.php index 6653dcd..9641757 100644 --- a/Service/ResultService.php +++ b/Service/ResultService.php @@ -5,24 +5,22 @@ use Doctrine\ORM\EntityManagerInterface; -use Psr\Container\ContainerInterface; use Studit\H5PBundle\Entity\ContentResult; use Symfony\Component\HttpFoundation\Request; class ResultService { /** - * @var ContainerInterface + * @var EntityManagerInterface */ - private $container; + private $em; /** * ResultService constructor. - * @param ContainerInterface $container */ - public function __construct(ContainerInterface $container) + public function __construct(EntityManagerInterface $em) { - $this->container = $container; + $this->em = $em; } /** @@ -37,8 +35,8 @@ public function handleRequestFinished(Request $request, $userId) \H5PCore::ajaxError('Invalid content'); } // TODO: Fire 'h5p_alter_user_result' event here. - $contentRepo = $this->container->get('doctrine')->getRepository('StuditH5PBundle:Content'); - $contentResultRepo = $this->container->get('doctrine')->getRepository('StuditH5PBundle:ContentResult'); + $contentRepo = $this->em->getRepository('StuditH5PBundle:Content'); + $contentResultRepo = $this->em->getRepository('StuditH5PBundle:ContentResult'); $result = $contentResultRepo->findOneBy(['userId' => $userId, 'content' => $contentId]); if (!$result) { $result = new ContentResult($userId); @@ -61,24 +59,20 @@ public function handleRequestFinished(Request $request, $userId) */ public function removeData($contentId, $dataType, $user, $subContentId) { - /** - * @var $em EntityManagerInterface - */ - $em = $this->container->get('doctrine'); - $ContenUserData = $em->getRepository('StuditH5PBundle:ContentUserData') + $ContentUserData = $this->em->getRepository('StuditH5PBundle:ContentUserData') ->findBy( [ 'subContentId' => $subContentId, 'mainContent' => $contentId, - 'dataId' => $dataType, + 'dataId' => 'state', 'user' => $user->getId() ] ); - if (count($ContenUserData) > 0){ - foreach ($ContenUserData as $content){ - $em->remove($content); + if (count($ContentUserData) > 0){ + foreach ($ContentUserData as $content){ + $this->em->remove($content); } - $em->flush(); + $this->em->flush(); } } } \ No newline at end of file From 419bc64118e44432db0f01c3eb8048961f574129 Mon Sep 17 00:00:00 2001 From: Micheal Date: Wed, 5 May 2021 14:28:32 +0200 Subject: [PATCH 2/4] fix end of file --- Service/ResultService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/ResultService.php b/Service/ResultService.php index 9641757..4847725 100644 --- a/Service/ResultService.php +++ b/Service/ResultService.php @@ -75,4 +75,4 @@ public function removeData($contentId, $dataType, $user, $subContentId) $this->em->flush(); } } -} \ No newline at end of file +} From 096cdb6a8898120f1d99893f82dc668b2c16fff4 Mon Sep 17 00:00:00 2001 From: Micheal Date: Wed, 5 May 2021 14:29:34 +0200 Subject: [PATCH 3/4] fix --- Service/ResultService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/ResultService.php b/Service/ResultService.php index 4847725..d4e2bf1 100644 --- a/Service/ResultService.php +++ b/Service/ResultService.php @@ -64,7 +64,7 @@ public function removeData($contentId, $dataType, $user, $subContentId) [ 'subContentId' => $subContentId, 'mainContent' => $contentId, - 'dataId' => 'state', + 'dataId' => $dataType, 'user' => $user->getId() ] ); From 8da2853369ff6c55a05038d0fc373a412f5ce671 Mon Sep 17 00:00:00 2001 From: jorisdugue Date: Wed, 5 May 2021 14:47:08 +0200 Subject: [PATCH 4/4] Update guzzle to 7.3 (latest) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2a35cb9..68cd81c 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "require": { "php": "^7.2.5", "doctrine/orm": "^2.7", - "guzzlehttp/guzzle": "^6.5", + "guzzlehttp/guzzle": "^7.3", "h5p/h5p-core": "^1.24", "h5p/h5p-editor": "^1.24", "symfony/framework-bundle": "~4.0|~5.0",