8000 Prepare some doctrine/orm 3 changes by alexander-schranz · Pull Request #7857 · sulu/sulu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Prepare some doctrine/orm 3 changes #7857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants 8000 to merge 1 commit into
base: 2.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
8000
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@

// set value of id explicitly if class has a pre-insert identity-generator to be compatible with postgresql
if (!$classMetadata->idGenerator->isPostInsertGenerator()) {
$queryBuilder->setValue($classMetadata->getColumnName('id'), $classMetadata->idGenerator->generate($this->entityManager, $activity));
$queryBuilder->setValue(
$classMetadata->getColumnName('id'),
\method_exists($classMetadata->idGenerator, 'generateId')

Check failure on line 108 in src/Sulu/Bundle/ActivityBundle/Infrastructure/Doctrine/Repository/ActivityRepository.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Parameter #1 $object_or_class of function method_exists expects object|string, Doctrine\ORM\Id\AbstractIdGenerator|null given.
? $classMetadata->i 8000 dGenerator->generateId($this->entityManager, $activity)
: $classMetadata->idGenerator->generate($this->entityManager, $activity) // remove when doctrine/orm or greater 2.18 is min version
);
}

return $queryBuilder;
Expand Down
2 changes: 1 addition & 1 deletion src/Sulu/Bundle/ContactBundle/Entity/ContactRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public function findContactWithAccountsById($id)

public function findByExcludedAccountId(int $excludedAccountId, ?string $search = null)
{
$subQueryBuilder = $this->_em->createQueryBuilder()
$subQueryBuilder = $this->getEntityManager()->createQueryBuilder()
->addSelect('IDENTITY(account_contacts.contact)')
->from(AccountContact::class, 'account_contacts')
->where('IDENTITY(account_contacts.account) = :excludedAccountId');
Expand Down
16 changes: 8 additions & 8 deletions src/Sulu/Bundle/MediaBundle/Entity/CollectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public function findCollectionById($id)
LEFT JOIN n.children AS collectionChildren
LEFT JOIN collectionParent.meta AS parentMeta
WHERE n.id = :id',
$this->_entityName
$this->getClassName()
);

$query = new Query($this->_em);
$query = new Query($this->getEntityManager());
$query->setDQL($dql);
$query->setParameter('id', $id);
$result = $query->getResult();
Expand Down Expand Up @@ -239,11 +239,11 @@ public function findCollectionBreadcrumbById($id)
LEFT JOIN n.defaultMeta AS defaultMeta
WHERE p.id = :id AND p.lft > n.lft AND p.rgt < n.rgt
ORDER BY n.lft',
$this->_entityName,
$this->_entityName
$this->getClassName(),
$this->getClassName()
);

$query = new Query($this->_em);
$query = new Query($this->getEntityManager());
$query->setDQL($sql);
$query->setParameter('id', $id);

Expand Down Expand Up @@ -274,7 +274,7 @@ public function findTree($id, $locale)
{
$subQueryBuilder = $this->createQueryBuilder('subCollection')
->select('subCollection.id')
->leftJoin($this->_entityName, 'c', Join::WITH, 'c.id = :id')
->leftJoin($this->getClassName(), 'c', Join::WITH, 'c.id = :id')
->andWhere('subCollection.lft <= c.lft AND subCollection.rgt > c.lft');

$queryBuilder = $this->createQueryBuilder('collection')
Expand Down Expand Up @@ -387,7 +387,7 @@ private function getIdsQuery(

public function findIdByMediaId(int $mediaId): ?int
{
$queryBuilder = $this->_em->createQueryBuilder()
$queryBuilder = $this->getEntityManager()->createQueryBuilder()
->from(MediaInterface::class, 'media')
->select('IDENTITY(media.collection)')
->where('media.id = :mediaId')
Expand All @@ -409,7 +409,7 @@ public function findDescendantIdsById($id)
{
$queryBuilder = $this->createQueryBuilder('subCollection')
->select('subCollection.id')
->from($this->_entityName, 'collection')
->from($this->getClassName(), 'collection')
->andWhere('collection.id = :id')
->andWhere('subCollection.lft > collection.lft AND subCollection.rgt < collection.rgt')
->setParameter('id', $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
function(Media $media) use ($locale) {
return $this->mediaManager->addFormatsAndUrl(new MediaApi($media, $locale));
},
$entities

Check failure on line 86 in src/Sulu/Bundle/MediaBundle/Entity/MediaDataProviderRepository.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Ignored error pattern #^Parameter \#2 \$array of function array_map expects array, mixed given\.$# (argument.type) in path /home/runner/work/sulu/sulu/src/Sulu/Bundle/MediaBundle/Entity/MediaDataProviderRepository.php is expected to occur 1 time, but occurred 2 times.
);
}

Expand Down Expand Up @@ -238,12 +238,12 @@
->setParameter('locale', $locale);
}

public function createQueryBuilder($alias, $indexBy = null)
public function createQueryBuilder($alias, $indexBy = null): \Doctrine\ORM\QueryBuilder

Check failure on line 241 in src/Sulu/Bundle/MediaBundle/Entity/MediaDataProviderRepository.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Method Sulu\Bundle\MediaBundle\Entity\MediaDataProviderRepository::createQueryBuilder() has parameter $indexBy with no type specified.

Check failure on line 241 in src/Sulu/Bundle/MediaBundle/Entity/MediaDataProviderRepository.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Method Sulu\Bundle\MediaBundle\Entity\MediaDataProviderRepository::createQueryBuilder() has parameter $alias with no type specified.
Copy link
Member
@Prokyonn Prokyonn Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should also be removed? 🤔

Suggested change
public function createQueryBuilder($alias, $indexBy = null): \Doctrine\ORM\QueryBuilder
public function createQueryBuilder($alias, $indexBy = null)

Copy link
Member Author
@alexander-schranz alexander-schranz Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return type is required now. It can not be removed but I would think that this service is nobody extends from and would be fine with technical bc break here.

{
return $this->entityManager->createQueryBuilder()
->select($alias)
->addSelect('collection')
->from($this->mediaEntityName, $alias, $indexBy)

Check failure on line 246 in src/Sulu/Bundle/MediaBundle/Entity/MediaDataProviderRepository.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Parameter #3 $indexBy of method Doctrine\ORM\QueryBuilder::from() expects string|null, mixed given.

Check failure on line 246 in src/Sulu/Bundle/MediaBundle/Entity/MediaDataProviderRepository.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Parameter #2 $alias of method Doctrine\ORM\QueryBuilder::from() expects string, mixed given.
->innerJoin($alias . '.collection', 'collection');

Check failure on line 247 in src/Sulu/Bundle/MediaBundle/Entity/MediaDataProviderRepository.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Binary operation "." between mixed and '.collection' results in an error.
}
}
2 changes: 1 addition & 1 deletion src/Sulu/Bundle/MediaBundle/Entity/MediaRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function findMediaDisplayInfo($ids, $locale)
return $queryBuilder->getQuery()->getArrayResult();
}

public function count(array $filter)
public function count(array $filter = []): int
{
list($collection, $systemCollections, $types, $search) = $this->extractFilterVars($filter);

Expand Down
14 changes: 10 additions & 4 deletions src/Sulu/Bundle/RouteBundle/Entity/RouteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function findByPath($path, $locale)
->andWhere('entity.path = :path')
->andWhere('entity.locale = :locale')
->getQuery()
->setParameters(['path' => $path, 'locale' => $locale]);
->setParameter('path', $path)
->setParameter('locale', $locale);

try {
return $query->getSingleResult();
Expand All @@ -46,7 +47,9 @@ public function findByEntity($entityClass, $entityId, $locale)
->andWhere('entity.entityId = :entityId')
->andWhere('entity.locale = :locale')
->andWhere('entity.history = false')
->setParameters(['entityClass' => $entityClass, 'entityId' => $entityId, 'locale' => $locale]);
->setParameter('entityClass', $entityClass)
->setParameter('entityId', $entityId)
->setParameter('locale', $locale);

try {
/** @var RouteInterface */
Expand All @@ -63,7 +66,9 @@ public function findHistoryByEntity($entityClass, $entityId, $locale)
->andWhere('entity.entityId = :entityId')
->andWhere('entity.locale = :locale')
->andWhere('entity.history = true')
->setParameters(['entityClass' => $entityClass, 'entityId' => $entityId, 'locale' => $locale]);
->setParameter('entityClass', $entityClass)
->setParameter('entityId', $entityId)
->setParameter('locale', $locale);

/** @var RouteInterface[] */
return $queryBuilder->getQuery()->getResult();
Expand All @@ -74,7 +79,8 @@ public function findAllByEntity($entityClass, $entityId, $locale = null)
$queryBuilder = $this->createQueryBuilder('entity')
->andWhere('entity.entityClass = :entityClass')
->andWhere('entity.entityId = :entityId')
->setParameters(['entityClass' => $entityClass, 'entityId' => $entityId]);
->setParameter('entityClass', $entityClass)
->setParameter('entityId', $entityId);

if ($locale) {
$queryBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Sulu\Bundle\PageBundle\Document\BasePageDocument;
use Sulu\Bundle\RouteBundle\Content\Type\PageTreeRouteContentType;
use Sulu\Bundle\RouteBundle\Entity\Route;
use Sulu\Bundle\RouteBundle\Entity\RouteRepository;
use Sulu\Bundle\RouteBundle\Entity\RouteRepositoryInterface;
use Sulu\Bundle\RouteBundle\Generator\ChainRouteGeneratorInterface;
use Sulu\Bundle\RouteBundle\Manager\ConflictResolverInterface;
Expand Down Expand Up @@ -123,7 +124,7 @@ public function setUp(): void
$this->chainRouteGenerator = $this->prophesize(ChainRouteGeneratorInterface::class);
$this->conflictResolver = $this->prophesize(ConflictResolverInterface::class);
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
$this->routeRepository = $this->prophesize(RouteRepositoryInterface::class);
$this->routeRepository = $this->prophesize(RouteRepository::class);
$this->property = $this->prophesize(PropertyInterface::class);
$this->node = $this->prophesize(NodeInterface::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public function findIdsWithGrantedPermissions(
?string $system,
?int $anonymousRoleId
): array {
$systemRoleQueryBuilder = $this->_em->createQueryBuilder()
$systemRoleQueryBuilder = $this->getEntityManager()->createQueryBuilder()
->from(RoleInterface::class, 'systemRoles')
->select('systemRoles.id')
->where('systemRoles.system = :system');

$queryBuilder = $this->_em->createQueryBuilder()
$queryBuilder = $this->getEntityManager()->createQueryBuilder()
->select('accessControl.entityId as id')
->distinct()
->from(AccessControl::class, 'accessControl')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function findSettingValue($roleId, $key)
->join('s.role', 'r')
->where('r.id = :roleId')
->andWhere('s.key = :key')
->setParameters(['roleId' => $roleId, 'key' => $key]);
->setParameter('roleId', $roleId)
->setParameter('key', $key);

try {
/** @var string $value */
Expand All @@ -64,7 +65,8 @@ public function findSetting($roleId, $key)
->join('s.role', 'r')
->where('r.id = :roleId')
->andWhere('s.key = :key')
->setParameters(['roleId' => $roleId, 'key' => $key]);
->setParameter('roleId', $roleId)
->setParameter('key', $key);

try {
return $queryBuilder->getQuery()->getSingleResult();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

/*
Expand All @@ -12,7 +12,7 @@
namespace Sulu\Component\Media\Tests\Unit\SmartContent;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectRepository;
use Doctrine\ORM\EntityRepository;
use JMS\Serializer\SerializationContext;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
Expand Down Expand Up @@ -167,11 +167,11 @@

public function testGetTypesConfiguration(): void
{
/** @var EntityManagerInterface|ObjectProphecy $entityManager */
/** @var ObjectProphecy<EntityManagerInterface> $entityManager */
$entityManager = $this->prophesize(EntityManagerInterface::class);

/** @var ObjectRepository|ObjectProphecy $mediaTypeRepository */
$mediaTypeRepository = $this->prophesize(ObjectRepository::class);
/** @var ObjectProphecy<EntityRepository> $mediaTypeRepository */
$mediaTypeRepository = $this->prophesize(EntityRepository::class);

$serializer = $this->prophesize(ArraySerializerInterface::class);
$collectionManager = $this->prophesize(CollectionManagerInterface::class);
Expand All @@ -194,7 +194,7 @@
->shouldBeCalled()
->willReturn([$mediaType1, $mediaType2]);

/** @var TranslatorInterface|ObjectProphecy $translator */
/** @var ObjectProphecy<TranslatorInterface> $translator */
$translator = $this->prophesize(TranslatorInterface::class);
$translator->trans('sulu_media.audio', [], 'admin')
->shouldBeCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event)
}
}

private function pro F438 cess(ClassMetadataInfo $metadata)
private function process(ClassMetadataInfo|ClassMetadata $metadata)
{
foreach ($this->objects as $application => $classes) {
foreach ($classes as $class) {
Expand All @@ -71,7 +71,7 @@ private function process(ClassMetadataInfo $metadata)
}

private function setAssociationMappings(
ClassMetadataInfo $metadata,
ClassMetadataInfo|ClassMetadata $metadata,
Configuration $configuration,
ReflectionService $reflectionService
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

/**
* Provides basic implementation of orm DataProvider repository.
*
* @method abstract createQueryBuilder(string $alias, ?string $indexBy = null): \Doctrine\ORM\QueryBuilder;
*/
trait DataProviderRepositoryTrait
{
Expand Down Expand Up @@ -339,16 +341,6 @@ private function appendRelationAnd(QueryBuilder $queryBuilder, $relation, $value
return $parameter;
}

/**
* Creates a new QueryBuilder instance that is prepopulated for this entity name.
*
* @param string $alias
* @param string|null $indexBy
*
* @return QueryBuilder
*/
abstract public function createQueryBuilder($alias, $indexBy = null);
Comment on lines -342 to -350
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the return type here would a major BC Break making lot of bundles fail. So removing the abstract and move it to a phpdoc is only way for Backards compatibility to orm 2 based bundles.


/**
* Append joins to query builder for "findByFilters" function.
*
Expand Down
Loading
0