Skip to content

Commit 499d54b

Browse files
committed
[1.x] Fix abandoned-extensions sync never being scheduled
The sync command was registered onto `flarum.console.scheduled` in ExtensionServiceProvider::boot(). ConsoleServiceProvider consumes that array in its own boot() and is registered first, so the entry was appended too late and the task was never scheduled. Move the command and schedule registration into register() so it is present when the schedule is built. Fixes #4705
1 parent 1761fbe commit 499d54b

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

framework/core/src/Extension/ExtensionServiceProvider.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,12 @@ public function register()
4545
$this->container['flarum']->booting(function () {
4646
$this->container->make('flarum.extensions')->extend($this->container);
4747
});
48-
}
49-
50-
/**
51-
* {@inheritdoc}
52-
*/
53-
public function boot(Dispatcher $events)
54-
{
55-
$events->listen(
56-
Disabling::class,
57-
DefaultLanguagePackGuard::class
58-
);
5948

49+
// Register the abandoned-extensions sync command and its weekly schedule here in
50+
// register() rather than boot(). The ConsoleServiceProvider consumes the
51+
// `flarum.console.scheduled` array in its own boot() method, and it is registered
52+
// before this provider, so appending in boot() would happen too late and the task
53+
// would never be scheduled.
6054
$this->container->extend('flarum.console.commands', function (array $commands) {
6155
$commands[] = SyncAbandonedExtensionsCommand::class;
6256

@@ -73,4 +67,15 @@ public function boot(Dispatcher $events)
7367
return $scheduled;
7468
});
7569
}
70+
71+
/**
72+
* {@inheritdoc}
73+
*/
74+
public function boot(Dispatcher $events)
75+
{
76+
$events->listen(
77+
Disabling::class,
78+
DefaultLanguagePackGuard::class
79+
);
80+
}
7681
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Flarum.
5+
*
6+
* For detailed copyright and license information, please view the
7+
* LICENSE file that was distributed with this source code.
8+
*/
9+
10+
namespace Flarum\Tests\integration\extension;
11+
12+
use Flarum\Testing\integration\ConsoleTestCase;
13+
14+
class ScheduledAbandonedSyncTest extends ConsoleTestCase
15+
{
16+
/**
17+
* The abandoned-extensions sync command is registered by core's ExtensionServiceProvider.
18+
* It must end up in the scheduler so the abandoned list is refreshed automatically.
19+
*
20+
* This is a regression test: the registration was previously done in the provider's boot()
21+
* method, which ran after ConsoleServiceProvider::boot() had already consumed the
22+
* `flarum.console.scheduled` array, so the task was silently dropped and never scheduled.
23+
*
24+
* @test
25+
*/
26+
public function abandoned_sync_command_is_scheduled()
27+
{
28+
$output = $this->runCommand([
29+
'command' => 'schedule:list',
30+
]);
31+
32+
$this->assertStringContainsString('extensions:sync-abandoned', $output);
33+
}
34+
}

0 commit comments

Comments
 (0)