Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DoctrineBridge] Fix LockStoreSchemaListener not working properly with iterable objects #54407

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
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 @@ -12,7 +12,6 @@
namespace Symfony\Bridge\Doctrine\SchemaListener;

use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\Store\DoctrineDbalStore;

Expand All @@ -30,20 +29,12 @@ public function postGenerateSchema(GenerateSchemaEventArgs $event): void
{
$connection = $event->getEntityManager()->getConnection();

$storesIterator = new \ArrayIterator($this->stores);
while ($storesIterator->valid()) {
try {
$store = $storesIterator->current();
if (!$store instanceof DoctrineDbalStore) {
continue;
}

$store->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
} catch (InvalidArgumentException) {
Copy link
Member

Choose a reason for hiding this comment

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

we still need catch the exception to not reintroduce the bug that #50761 tried to fix

// no-op
foreach ($this->stores as $store) {
if (!$store instanceof DoctrineDbalStore) {
continue;
}

$storesIterator->next();
$store->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaListener;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Store\DoctrineDbalStore;

class LockStoreSchemaListenerTest extends TestCase
Expand All @@ -40,20 +39,4 @@ public function testPostGenerateSchemaLockPdo()
$subscriber = new LockStoreSchemaListener([$lockStore]);
$subscriber->postGenerateSchema($event);
}

public function testPostGenerateSchemaWithInvalidLockStore()
Copy link
Member

Choose a reason for hiding this comment

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

this test should be kept as fixing the issue #50761 tried to fix is legitimate

{
$entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager->expects($this->once())
->method('getConnection')
->willReturn($this->createMock(Connection::class));
$event = new GenerateSchemaEventArgs($entityManager, new Schema());

$subscriber = new LockStoreSchemaListener((static function (): \Generator {
yield $this->createMock(DoctrineDbalStore::class);

throw new InvalidArgumentException('Unsupported Connection');
})());
$subscriber->postGenerateSchema($event);
}
}
48 changes: 48 additions & 0 deletions src/Symfony/Component/Lock/Store/NullStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Lock\Store;

use Symfony\Component\Lock\BlockingSharedLockStoreInterface;
use Symfony\Component\Lock\Key;

/**
* NullStore is a PersistingStoreInterface implementation which discards all operations.
*
* @author Pavel Bartoň <[email protected]>
*/
class NullStore implements BlockingSharedLockStoreInterface
Copy link
Member

Choose a reason for hiding this comment

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

Introducing this class (as well as the changes to the StoreFactory) must be moved into a separate PR targeting the 7.2 branch. That's a new feature.

{
public function save(Key $key): void
{
}

public function saveRead(Key $key): void
{
}

public function waitAndSaveRead(Key $key): void
{
}

public function delete(Key $key): void
{
}

public function exists(Key $key): bool
{
return false;
}

public function putOffExpiration(Key $key, float $ttl): void
{
}
}
3 changes: 3 additions & 0 deletions src/Symfony/Component/Lock/Store/StoreFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public static function createStore(#[\SensitiveParameter] object|string $connect

case 'in-memory' === $connection:
return new InMemoryStore();

case 'null' === $connection:
return new NullStore();
}

throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection));
Expand Down
Loading