Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4b338d9

Browse filesBrowse files
Merge branch '8.0' into 8.1
* 8.0: [DependencyInjection] Skip validating deprecated aliases in CheckAliasValidityPass [Scheduler] Fix checkpoint state expiring when cache has default TTL
2 parents eb3332d + 460adb0 commit 4b338d9
Copy full SHA for 4b338d9

4 files changed

+40-9Lines changed: 40 additions & 9 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Symfony/Component/DependencyInjection/Compiler/CheckAliasValidityPass.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckAliasValidityPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function process(ContainerBuilder $container): void
2525
{
2626
foreach ($container->getAliases() as $id => $alias) {
2727
try {
28-
if (!$container->hasDefinition((string) $alias)) {
28+
if ($alias->isDeprecated() || !$container->hasDefinition((string) $alias)) {
2929
continue;
3030
}
3131

Collapse file

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckAliasValidityPassTest.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckAliasValidityPassTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public function testProcessIgnoresTargetWithoutClass()
7272
$this->addToAssertionCount(1);
7373
}
7474

75+
public function testProcessIgnoresDeprecatedAlias()
76+
{
77+
$container = new ContainerBuilder();
78+
$container->register('a')->setClass(FooNotImplementing::class);
79+
$container->setAlias(FooInterface::class, 'a')
80+
->setDeprecated('vendor/package', '1.2', 'The "%alias_id%" alias is deprecated.');
81+
82+
$this->process($container);
83+
$this->addToAssertionCount(1);
84+
}
85+
7586
protected function process(ContainerBuilder $container): void
7687
{
7788
$pass = new CheckAliasValidityPass();
Collapse file

‎src/Symfony/Component/Scheduler/Generator/Checkpoint.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/Scheduler/Generator/Checkpoint.php
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111

1212
namespace Symfony\Component\Scheduler\Generator;
1313

14+
use Psr\Cache\CacheItemInterface;
1415
use Symfony\Component\Lock\LockInterface;
1516
use Symfony\Contracts\Cache\CacheInterface;
1617

1718
final class Checkpoint implements CheckpointInterface
1819
{
20+
private const CACHE_EXPIRY = 5 * 365 * 86400; // 5 years
21+
1922
private \DateTimeImmutable $from;
2023
private \DateTimeImmutable $time;
2124
private int $index = -1;
@@ -38,7 +41,11 @@ public function acquire(\DateTimeImmutable $now): bool
3841
}
3942

4043
if ($this->cache) {
41-
[$this->time, $this->index, $this->from] = $this->cache->get($this->name, static fn () => [$now, -1, $now]) + [2 => $now];
44+
[$this->time, $this->index, $this->from] = $this->cache->get($this->name, static function (CacheItemInterface $item) use ($now) {
45+
$item->expiresAfter(self::CACHE_EXPIRY);
46+
47+
return [$now, -1, $now];
48+
}) + [2 => $now];
4249
$this->save($this->time, $this->index);
4350
} elseif ($this->reset) {
4451
$this->reset = false;
@@ -71,7 +78,12 @@ public function save(\DateTimeImmutable $time, int $index): void
7178
$this->time = $time;
7279
$this->index = $index;
7380
$this->from ??= $time;
74-
$this->cache?->get($this->name, fn () => [$time, $index, $this->from], \INF);
81+
$from = $this->from;
82+
$this->cache?->get($this->name, static function (CacheItemInterface $item) use ($time, $index, $from) {
83+
$item->expiresAfter(self::CACHE_EXPIRY);
84+
85+
return [$time, $index, $from];
86+
}, \INF);
7587
}
7688

7789
/**
Collapse file

‎src/Symfony/Component/Scheduler/Tests/Generator/CheckpointTest.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/Scheduler/Tests/Generator/CheckpointTest.php
+14-6Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Lock\NoLock;
2020
use Symfony\Component\Lock\Store\InMemoryStore;
2121
use Symfony\Component\Scheduler\Generator\Checkpoint;
22+
use Symfony\Contracts\Cache\ItemInterface;
2223

2324
class CheckpointTest extends TestCase
2425
{
@@ -149,17 +150,14 @@ public function testWithCacheFullCycle()
149150
$checkpoint = new Checkpoint('cache', new NoLock(), $cache = new ArrayAdapter());
150151
$now = new \DateTimeImmutable('2020-02-20 20:20:20Z');
151152

152-
// init
153153
$cache->get('cache', static fn () => [$now->modify('-1 min'), 3], \INF);
154154

155-
// action
156155
$acquired = $checkpoint->acquire($now);
157156
$lastTime = $checkpoint->time();
158157
$lastIndex = $checkpoint->index();
159158
$checkpoint->save($now, 0);
160159
$checkpoint->release($now, null);
161160

162-
// asserting
163161
$this->assertTrue($acquired);
164162
$this->assertEquals($now->modify('-1 min'), $lastTime);
165163
$this->assertSame(3, $lastIndex);
@@ -259,22 +257,32 @@ public function testWithLockFullCycle()
259257
$checkpoint = new Checkpoint('dummy', $lock);
260258
$now = new \DateTimeImmutable('2020-02-20 20:20:20Z');
261259

262-
// init
263260
$checkpoint->save($now->modify('-1 min'), 3);
264261

265-
// action
266262
$acquired = $checkpoint->acquire($now);
267263
$lastTime = $checkpoint->time();
268264
$lastIndex = $checkpoint->index();
269265
$checkpoint->save($now, 0);
270266
$checkpoint->release($now, null);
271267

272-
// asserting
273268
$this->assertTrue($acquired);
274269
$this->assertEquals($now->modify('-1 min'), $lastTime);
275270
$this->assertSame(3, $lastIndex);
276271
$this->assertEquals($now, $checkpoint->time());
277272
$this->assertSame(0, $checkpoint->index());
278273
$this->assertFalse($lock->isAcquired());
279274
}
275+
276+
public function testCheckpointOverridesPoolDefaultLifetime()
277+
{
278+
$cache = new ArrayAdapter(1);
279+
$checkpoint = new Checkpoint('cache', new NoLock(), $cache);
280+
$now = new \DateTimeImmutable('2020-02-20 20:20:20Z');
281+
282+
$checkpoint->acquire($now);
283+
$checkpoint->save($now, 5);
284+
285+
$expiry = $cache->getItem('cache')->getMetadata()[ItemInterface::METADATA_EXPIRY] ?? null;
286+
$this->assertGreaterThan(time() + 365 * 86400, $expiry);
287+
}
280288
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.