Skip to content

Commit

Permalink
Remove contentUserData bugfix and refactor #31
Browse files Browse the repository at this point in the history
fix error:
php.CRITICAL: Uncaught Error: Call to undefined method Doctrine\Bundle\DoctrineBundle\Registry::remove()

inject $entityManager instead of $container
  • Loading branch information
jorisdugue committed May 5, 2021
2 parents b9de957 + 096cdb6 commit e9edc37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 12 additions & 18 deletions Service/ResultService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand All @@ -61,11 +59,7 @@ 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,
Expand All @@ -74,11 +68,11 @@ public function removeData($contentId, $dataType, $user, $subContentId)
'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();
}
}
}
}

0 comments on commit e9edc37

Please sign in to comment.