Skip to content

Commit b3be60a

Browse files
authored
Display old structure if .env.plesk is missing or empty
2 parents 38500c5 + 010bcca commit b3be60a

3 files changed

Lines changed: 90 additions & 8 deletions

File tree

src/PleskEnv.php

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,54 @@ public static function get(string $name): ?string
9191
}
9292

9393
/**
94-
* Whether the multi-queue scheme is configured (the queue list is present).
95-
* When false, the legacy single-worker variables should be used instead.
94+
* Whether the multi-queue format applies. True only when the
95+
* PLESK_EXT_LARAVEL_QUEUE_LIST key is explicitly present in the file (an
96+
* empty "PLESK_EXT_LARAVEL_QUEUE_LIST=" still counts). A missing or empty
97+
* file, or a legacy-only file, falls back to the legacy single-worker
98+
* format. This is what the Plesk extension keys on: the queue-list row
99+
* appears in the output only for the new format.
96100
*/
97101
public static function isMultiQueue(): bool
98102
{
99-
return self::get(self::LIST_VAR) !== null;
103+
return self::hasQueueList();
100104
}
101105

102106
/**
103-
* Where the queue configuration comes from. Reads .env.plesk directly, so
104-
* the result is either "plesk-environment" (any queue setting present) or
105-
* "default" (nothing configured).
107+
* Whether the PLESK_EXT_LARAVEL_QUEUE_LIST key is defined, regardless of its
108+
* value (an empty value still counts as present).
109+
*/
110+
public static function hasQueueList(): bool
111+
{
112+
self::load();
113+
114+
return Env::getRepository()->has(self::LIST_VAR);
115+
}
116+
117+
/**
118+
* Whether any legacy single-worker variable is defined.
119+
*/
120+
private static function hasLegacyConfig(): bool
121+
{
122+
self::load();
123+
124+
$repository = Env::getRepository();
125+
foreach (self::legacyParameterNames() as $name) {
126+
if ($repository->has($name)) {
127+
return true;
128+
}
129+
}
130+
131+
return false;
132+
}
133+
134+
/**
135+
* Where the queue configuration comes from: "plesk-environment" when any
136+
* queue configuration is present (the queue-list key or a legacy variable),
137+
* otherwise "default".
106138
*/
107139
public static function configSource(): string
108140
{
109-
if (self::isMultiQueue() || self::get(self::LEGACY_ENABLED) !== null) {
141+
if (self::hasQueueList() || self::hasLegacyConfig()) {
110142
return self::SOURCE_PLESK_ENV;
111143
}
112144

tests/Feature/ListEnvCommandTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ public function testLegacyOutputShowsWorkerVariables(): void
3030

3131
public function testLegacyOutputDefaultsEnabledToFalseWhenUnset(): void
3232
{
33+
// Legacy structure: a WORKER_* variable is present and there is no
34+
// queue-list key, so the enabled flag is unset and shown as "false".
35+
$this->setPleskEnv([
36+
'PLESK_EXT_LARAVEL_QUEUE_WORKER_TIMEOUT' => '5',
37+
]);
38+
39+
$this->artisan('plesk-ext-laravel:list-env')
40+
->expectsTable(['Parameter', 'Value'], [
41+
['PLESK_EXT_LARAVEL_QUEUE_MULTIPLE_SUPPORTED', 'true'],
42+
['PLESK_EXT_LARAVEL_QUEUE_WORKER_ENABLED', 'false'],
43+
['PLESK_EXT_LARAVEL_QUEUE_WORKER_STOP_WHEN_EMPTY', ''],
44+
['PLESK_EXT_LARAVEL_QUEUE_WORKER_TIMEOUT', '5'],
45+
['PLESK_EXT_LARAVEL_QUEUE_WORKER_MAX_JOBS', ''],
46+
['PLESK_EXT_LARAVEL_QUEUE_WORKER_MAX_TIME', ''],
47+
])
48+
->assertExitCode(0);
49+
}
50+
51+
public function testEmptyEnvironmentOutputsLegacyFormat(): void
52+
{
53+
// No .env.plesk / nothing configured -> legacy format (no queue-list
54+
// row), so the extension treats it as the old package.
3355
$this->artisan('plesk-ext-laravel:list-env')
3456
->expectsTable(['Parameter', 'Value'], [
3557
['PLESK_EXT_LARAVEL_QUEUE_MULTIPLE_SUPPORTED', 'true'],
@@ -42,6 +64,22 @@ public function testLegacyOutputDefaultsEnabledToFalseWhenUnset(): void
4264
->assertExitCode(0);
4365
}
4466

67+
public function testExplicitEmptyQueueListOutputsMultiQueueFormat(): void
68+
{
69+
// Only "PLESK_EXT_LARAVEL_QUEUE_LIST=" present -> the new format, because
70+
// the queue-list key is explicitly there.
71+
$this->setPleskEnv([
72+
'PLESK_EXT_LARAVEL_QUEUE_LIST' => '',
73+
]);
74+
75+
$this->artisan('plesk-ext-laravel:list-env')
76+
->expectsTable(['Parameter', 'Value'], [
77+
['PLESK_EXT_LARAVEL_QUEUE_MULTIPLE_SUPPORTED', 'true'],
78+
['PLESK_EXT_LARAVEL_QUEUE_LIST', ''],
79+
])
80+
->assertExitCode(0);
81+
}
82+
4583
public function testMultiQueueOutputListsEveryQueueParameter(): void
4684
{
4785
$this->setPleskEnv([

tests/Feature/ScheduleTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,19 @@ public function testLegacyWorkerTranslatesEveryParameterToFlags(): void
9292

9393
public function testNothingIsScheduledWhenLegacyWorkerDisabled(): void
9494
{
95-
// No PLESK_EXT_LARAVEL_QUEUE_* variables set at all.
95+
// Legacy structure (a WORKER_* variable present, no queue list) with the
96+
// worker explicitly disabled -> nothing is scheduled.
97+
$this->setPleskEnv([
98+
'PLESK_EXT_LARAVEL_QUEUE_WORKER_ENABLED' => 'false',
99+
]);
100+
101+
$this->assertCount(0, $this->queueWorkerCommands());
102+
}
103+
104+
public function testNothingIsScheduledWithoutAnyConfiguration(): void
105+
{
106+
// No PLESK_EXT_LARAVEL_QUEUE_* variables at all: legacy mode with the
107+
// worker not enabled -> no workers.
96108
$this->assertCount(0, $this->queueWorkerCommands());
97109
}
98110

0 commit comments

Comments
 (0)