Skip to content

Commit

Permalink
Merge pull request #3388 from acrobat/fix-doctrine-related-deprecations
Browse files Browse the repository at this point in the history
[AllBundles] Fix doctrine related deprecations
  • Loading branch information
acrobat authored Apr 11, 2024
2 parents 06a5357 + 4e2dc2d commit 8af13be
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 51 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"symfony/security-acl": "^3.1",
"symfony/security-core" : "^6.4",
"symfony/security-http" : "^6.4",
"symfony/security-bundle": "^6.4",
"symfony/serializer": "^6.4",
"symfony/string": "^6.4",
"symfony/translation": "^6.4",
Expand All @@ -50,9 +51,9 @@
"symfony/mime": "^6.4",
"doctrine/inflector": "^1.4|^2.0",
"doctrine/orm": "^2.13",
"doctrine/dbal": "^2.13.1|^3.4",
"doctrine/doctrine-bundle": "^2.4",
"doctrine/persistence": "^2.5|^3.3",
"doctrine/dbal": "^3.8",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/persistence": "^3.3",

"knplabs/knp-menu-bundle": "^3.0",
"guzzlehttp/guzzle": "^7.0",
Expand Down
7 changes: 4 additions & 3 deletions src/Kunstmaan/AdminBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"php": "^8.1",
"babdev/pagerfanta-bundle": "^3.7",
"doctrine/orm": "^2.13",
"doctrine/dbal": "^2.13.1|^3.4",
"doctrine/doctrine-bundle": "^2.4",
"doctrine/persistence": "^2.5|^3.3",
"doctrine/dbal": "^3.8",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/persistence": "^3.3",
"guzzlehttp/guzzle": "^7.0",
"knplabs/knp-menu-bundle": "^3.0",
"kunstmaan/adminlist-bundle": "^7.0",
Expand All @@ -45,6 +45,7 @@
"symfony/security-acl": "^3.1",
"symfony/security-core" : "^6.4",
"symfony/security-http" : "^6.4",
"symfony/security-bundle": "^6.4",
"symfony/serializer": "^6.4",
"symfony/translation": "^6.4",
"symfony/twig-bundle": "^6.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getPagerfanta()
$adapter = new DbalQueryAdapter($this->getQueryBuilder(), function (QueryBuilder $queryBuilder): void {
$distinctString = $this->getUseDistinctCount() ? 'DISTINCT ' : '';
$queryBuilder->select('COUNT(' . $distinctString . $this->getCountField() . ') AS total_results')
->resetQueryPart('orderBy')
->resetOrderBy()
->setMaxResults(1);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@

namespace Kunstmaan\AdminListBundle\Tests\AdminList\FilterType\DBAL;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use PHPUnit\Framework\TestCase;

abstract class BaseDbalFilterTest extends TestCase
{
public function getQueryBuilder()
{
$conn = $this->createMock(Connection::class);
$expressionBuilder = new ExpressionBuilder($conn);

$conn->method('getDatabasePlatform')->willReturn(new MySQLPlatform());
if (method_exists(Connection::class, 'createExpressionBuilder')) {
$conn->method('createExpressionBuilder')->willReturn($expressionBuilder);
}
$conn->method('getExpressionBuilder')->willReturn($expressionBuilder);
$options = ['driver' => 'pdo_sqlite', 'path' => 'database.sqlite'];
$config = new Configuration();
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
$conn = DriverManager::getConnection($options, $config);

return new QueryBuilder($conn);
}
Expand Down
25 changes: 14 additions & 11 deletions src/Kunstmaan/MediaBundle/EventListener/DoctrineMediaListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Kunstmaan\MediaBundle\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PostPersistEventArgs;
use Doctrine\ORM\Event\PostUpdateEventArgs;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Doctrine\ORM\Event\PreRemoveEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Kunstmaan\MediaBundle\Entity\Media;
use Kunstmaan\MediaBundle\Helper\File\FileHandler;
Expand All @@ -29,9 +32,9 @@ public function __construct(MediaManager $mediaManager)
$this->mediaManager = $mediaManager;
}

public function prePersist(LifecycleEventArgs $eventArgs)
public function prePersist(PrePersistEventArgs $eventArgs)
{
$this->prepareMedia($eventArgs->getEntity());
$this->prepareMedia($eventArgs->getObject());
}

/**
Expand All @@ -50,15 +53,15 @@ private function prepareMedia($entity): bool

public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$entity = $eventArgs->getEntity();
$entity = $eventArgs->getObject();
if ($this->prepareMedia($entity)) {
// Hack ? Don't know, that's the behaviour Doctrine 2 seems to want
// See : http://www.doctrine-project.org/jira/browse/DDC-1020
$em = $eventArgs->getEntityManager();
$em = $eventArgs->getObjectManager();
$uow = $em->getUnitOfWork();
$uow->recomputeSingleEntityChangeSet(
$em->getClassMetadata(ClassLookup::getClass($entity)),
$eventArgs->getEntity()
$eventArgs->getObject()
);

// local media is soft-deleted or soft-delete is reverted
Expand All @@ -77,9 +80,9 @@ public function preUpdate(PreUpdateEventArgs $eventArgs)
}
}

public function postPersist(LifecycleEventArgs $eventArgs)
public function postPersist(PostPersistEventArgs $eventArgs)
{
$this->saveMedia($eventArgs->getEntity(), true);
$this->saveMedia($eventArgs->getObject(), true);
}

/**
Expand Down Expand Up @@ -109,12 +112,12 @@ private function saveMedia($entity, $new = false)
}
}

public function postUpdate(LifecycleEventArgs $eventArgs)
public function postUpdate(PostUpdateEventArgs $eventArgs)
{
$this->saveMedia($eventArgs->getEntity());
$this->saveMedia($eventArgs->getObject());
}

public function preRemove(LifecycleEventArgs $eventArgs)
public function preRemove(PreRemoveEventArgs $eventArgs)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Kunstmaan\NodeBundle\EventListener;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\MappingException;
use Kunstmaan\AdminBundle\FlashMessages\FlashTypes;
Expand Down Expand Up @@ -52,19 +52,19 @@ public function __construct(
$this->pagesConfiguration = $pagesConfiguration;
}

public function prePersist(LifecycleEventArgs $args)
public function prePersist(PrePersistEventArgs $args)
{
$entity = $args->getEntity();
$entity = $args->getObject();

if ($entity instanceof NodeTranslation) {
$this->setSlugWhenEmpty($entity, $args->getEntityManager());
$this->ensureSlugIsSlugified($entity);
}
}

public function preUpdate(LifecycleEventArgs $args)
public function preUpdate(PrePersistEventArgs $args)
{
$entity = $args->getEntity();
$entity = $args->getObject();

if ($entity instanceof NodeTranslation) {
$this->setSlugWhenEmpty($entity, $args->getEntityManager());
Expand Down Expand Up @@ -104,7 +104,7 @@ private function ensureSlugIsSlugified(NodeTranslation $nodeTranslation)
public function onFlush(OnFlushEventArgs $args)
{
try {
$em = $args->getEntityManager();
$em = $args->getObjectManager();

$class = $em->getClassMetadata(NodeTranslation::class);

Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/NodeBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"require": {
"php": "^8.1",
"doctrine/dbal": "^2.13.1|^3.4",
"doctrine/dbal": "^3.8",
"gedmo/doctrine-extensions": "^2.4.34|^3.1.0",
"kunstmaan/admin-bundle": "^7.0",
"kunstmaan/adminlist-bundle": "^7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ public function getQueryBuilder()
$this->locales
));

$identifierQuoteCharacter = $this->connection->getDatabasePlatform()->getIdentifierQuoteCharacter();
$quotedTextColumnName = $identifierQuoteCharacter . 'text' . $identifierQuoteCharacter;
$quotedTextColumnName = $this->connection->quoteIdentifier('text');

// Add join for every locale
foreach ($this->locales as $locale) {
Expand Down
16 changes: 5 additions & 11 deletions src/Kunstmaan/TranslatorBundle/Tests/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Security\Core\User\ChainUserChecker;

/**
* App Test Kernel for functional tests.
Expand Down Expand Up @@ -80,16 +79,11 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load($this->rootConfig);
$loader->load(function (ContainerBuilder $containerBuilder) {
$containerBuilder->prependExtensionConfig('security', ['enable_authenticator_manager' => true]);

// Only set these config options on 6.2+
if (class_exists(ChainUserChecker::class)) {
$containerBuilder->prependExtensionConfig('framework', [
'handle_all_throwables' => true,
'php_errors' => ['log' => true],
'annotations' => ['enabled' => false],
]);
}
$containerBuilder->prependExtensionConfig('framework', [
'handle_all_throwables' => true,
'php_errors' => ['log' => true],
'annotations' => ['enabled' => false],
]);
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/Kunstmaan/TranslatorBundle/Tests/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ doctrine:
path: "%kernel.cache_dir%/test.db"
use_savepoints: true
orm:
enable_lazy_ghost_objects: true
controller_resolver:
auto_mapping: false
default_entity_manager: default
entity_managers:
default:
connection: default
report_fields_where_declared: true
mappings:
KunstmaanTranslatorBundle: ~
4 changes: 2 additions & 2 deletions src/Kunstmaan/VotingBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"require": {
"php": "^8.1",
"doctrine/orm": "^2.13",
"doctrine/dbal": "^2.13.1|^3.4",
"doctrine/doctrine-bundle": "^2.4",
"doctrine/dbal": "^3.8",
"doctrine/doctrine-bundle": "^2.12",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/event-dispatcher": "^6.4",
Expand Down

0 comments on commit 8af13be

Please sign in to comment.