Skip to content

Commit

Permalink
Merge pull request #193 from Novactive/feat-108625-ibexa-4-form-mail-…
Browse files Browse the repository at this point in the history
…protection-fix-em-v3

[NovaeZProtectedContentBundle] fix EM
  • Loading branch information
erdnaxelaweb authored Jun 4, 2024
2 parents 50967cb + 30380d8 commit 1a81697
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

namespace Novactive\Bundle\eZProtectedContentBundle\Command;

use Doctrine\ORM\EntityManagerInterface;
use Novactive\Bundle\eZProtectedContentBundle\Entity\ProtectedTokenStorage;
use Novactive\Bundle\eZProtectedContentBundle\Repository\ProtectedTokenStorageRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -24,13 +22,10 @@

class CleanTokenCommand extends Command
{
/**
* @param EntityManagerInterface $entityManager
*/
public function __construct(EntityManagerInterface $entityManager)
{
public function __construct(
protected ProtectedTokenStorageRepository $protectedTokenStorageRepository,
) {
parent::__construct();
$this->entityManager = $entityManager;
}

protected function configure(): void
Expand All @@ -47,16 +42,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

/** @var ProtectedTokenStorageRepository $protectedTokenStorageRepository */
$protectedTokenStorageRepository = $this->entityManager->getRepository(ProtectedTokenStorage::class);
$entities = $this->protectedTokenStorageRepository->findExpired();

$entities = $protectedTokenStorageRepository->findExpired();
$io->comment(sprintf('%d entities to delete', count($entities)));

foreach ($entities as $entity) {
$this->entityManager->remove($entity);
$this->protectedTokenStorageRepository->remove($entity);
}

$this->entityManager->flush();
$this->protectedTokenStorageRepository->flush();

$io->success(sprintf('%d entities deleted', count($entities)));
$io->success('Done.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle(
return new RedirectResponse(
$router->generate('ibexa.content.view', ['contentId' => $location->contentId,
'locationId' => $location->id,
]).
]).
'#ibexa-tab-location-view-protect-content#tab'
);
}
Expand All @@ -86,7 +86,7 @@ public function remove(
return new RedirectResponse(
$router->generate('ibexa.content.view', ['contentId' => $location->contentId,
'locationId' => $location->id,
]).
]).
'#ibexa-tab-location-view-protect-content#tab'
);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
/**
* @ORM\Entity()
* @ORM\Table(name="novaezprotectedcontent")
* @ORM\EntityListeners({"Novactive\Bundle\eZProtectedContentBundle\Listener\EntityContentLink"})
*/
class ProtectedAccess implements ContentInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\Validator\Constraints as Assert;

/**
* @ORM\Entity(repositoryClass="Novactive\Bundle\eZProtectedContentBundle\Repository\ProtectedTokenStorageRepository")
* @ORM\Entity()
* @ORM\Table(name="novaezprotectedcontentstorage")
*/
class ProtectedTokenStorage
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,18 @@

namespace Novactive\Bundle\eZProtectedContentBundle\Repository;

use Doctrine\ORM\EntityManagerInterface;
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Novactive\Bundle\eZProtectedContentBundle\Entity\ProtectedAccess;

class ProtectedAccessRepository extends EntityRepository
class ProtectedAccessRepository
{
/**
* @var Repository
*/
private $repository;

/**
* @required
*/
public function setRepository(Repository $repository): void
{
$this->repository = $repository;
}
public function __construct(
protected readonly Repository $repository,
protected readonly EntityManagerInterface $entityManager,
) { }

protected function getAlias(): string
{
Expand Down Expand Up @@ -63,7 +56,10 @@ function (Repository $repository) use ($content) {
}
);

$qb = parent::createQueryBuilderForFilters();
$entityRepository = $this->entityManager->getRepository($this->getEntityClass());

$qb = $entityRepository->createQueryBuilder($this->getAlias());

$qb->where($qb->expr()->eq($this->getAlias().'.enabled', true));
$qb->andWhere(
$qb->expr()->in($this->getAlias().'.contentId', ':contentIds')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
namespace Novactive\Bundle\eZProtectedContentBundle\Repository;

use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Ibexa\Contracts\Core\Repository\Repository;
use Novactive\Bundle\eZProtectedContentBundle\Entity\ProtectedTokenStorage;

class ProtectedTokenStorageRepository extends EntityRepository
class ProtectedTokenStorageRepository
{
public function __construct(
protected readonly EntityManagerInterface $entityManager,
) { }

protected function getAlias(): string
{
return 'pts';
Expand All @@ -17,29 +23,55 @@ protected function getEntityClass(): string
return ProtectedTokenStorage::class;
}

/**
* @param array $criteria
* @return ProtectedTokenStorage[]
*/
public function findUnexpiredBy(array $criteria = []): array
{
$dbQuery = $this->_em->createQueryBuilder()
->select('c')
$entityRepository = $this->entityManager->getRepository($this->getEntityClass());
$qb = $entityRepository->createQueryBuilder($this->getAlias());

$qb ->select('c')
->from(ProtectedTokenStorage::class, 'c')
->where('c.created >= :nowMinusOneHour')
->setParameter('nowMinusOneHour', new DateTime('now - 1 hours'));

foreach ($criteria as $key => $criterion) {
$dbQuery->andWhere("c.$key = '$criterion'");
$qb->andWhere("c.$key = '$criterion'");
}

return $dbQuery->getQuery()->getResult();
return $qb->getQuery()->getResult();
}

public function findExpired(): array
{
$dbQuery = $this->_em->createQueryBuilder()
->select('c')
$entityRepository = $this->entityManager->getRepository($this->getEntityClass());
$qb = $entityRepository->createQueryBuilder($this->getAlias());
$qb ->select('c')
->from(ProtectedTokenStorage::class, 'c')
->where('c.created < :nowMinusOneHour')
->setParameter('nowMinusOneHour', new DateTime('now - 1 hours'));

return $dbQuery->getQuery()->getResult();
return $qb->getQuery()->getResult();
}

/**
* @param ProtectedTokenStorage $entity
* @return void
* @see EntityManagerInterface::remove()
*/
public function remove(ProtectedTokenStorage $entity): void
{
$this->entityManager->remove($entity);
}

/**
* @return void
* @see EntityManagerInterface::flush()
*/
public function flush(): void
{
$this->entityManager->flush();
}
}
Loading

0 comments on commit 1a81697

Please sign in to comment.