Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/QuickInstall/Sandbox/BoardRefreshService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private function runtimeConfig(array $board): array
'admin_pass' => 'password',
'admin_email' => 'admin@example.test',
'board_email' => 'board@example.test',
'board_timezone' => 'UTC',
'populate' => 'none',
'debug' => false,
'extensions' => [],
Expand Down
2 changes: 2 additions & 0 deletions src/QuickInstall/Sandbox/BoardRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public function uninstallExtension(string $board, string $name): void
}

$this->run(array_merge($command, ['extension:purge', $name]));
// Drop compiled autoloaders while the extension files are still mounted.
$this->purgeCache($board);
}

/** Runs phpBB-aware style cleanup before its files disappear. */
Expand Down
49 changes: 49 additions & 0 deletions src/QuickInstall/Sandbox/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function create(string $name, string $version = 'latest', string $db = 'm
'admin_pass' => 'password',
'admin_email' => 'admin@example.test',
'board_email' => 'board@example.test',
'board_timezone' => $this->hostTimezone(),
'extensions' => [],
'styles' => [],
];
Expand Down Expand Up @@ -124,6 +125,7 @@ public function create(string $name, string $version = 'latest', string $db = 'm
'path' => $boardDir,
'populate' => $populate,
'debug' => $debug,
'board_timezone' => $config['board_timezone'],
'extensions' => [],
'styles' => [],
'created_at' => gmdate('c'),
Expand All @@ -142,6 +144,53 @@ public function create(string $name, string $version = 'latest', string $db = 'm
return ['board' => $board, 'paths' => $paths];
}

/** Returns the host's PHP-supported timezone identifier, falling back to UTC. */
protected function hostTimezone(): string
{
$candidates = [];
$environment = getenv('TZ');
if (is_string($environment))
{
$candidates[] = ltrim(trim($environment), ':');
}

$localtime = realpath('/etc/localtime');
if (is_string($localtime) && preg_match('#/zoneinfo/(.+)$#', $localtime, $match))
{
$candidates[] = $match[1];
}

if (is_readable('/etc/timezone'))
{
$timezone = file_get_contents('/etc/timezone');
if (is_string($timezone))
{
$candidates[] = trim($timezone);
}
}

$candidates[] = date_default_timezone_get();
foreach ($candidates as $candidate)
{
if ($candidate === '')
{
continue;
}

try
{
// Match phpBB's own timezone validation semantics.
new \DateTimeZone($candidate);
return $candidate;
}
catch (\Exception $e)
{
}
}

return 'UTC';
}

private function backupBoardState(string $name): array
{
$token = str_replace('.', '', uniqid('replace-', true));
Expand Down
7 changes: 7 additions & 0 deletions src/QuickInstall/Sandbox/DockerComposeWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private function compose(string $name, array $config): string
environment:
QUICKINSTALL_PHPBB_VERSION: "{$config['phpbb']}"
QUICKINSTALL_POPULATE: "{$config['populate']}"
QUICKINSTALL_BOARD_TIMEZONE: "{$config['board_timezone']}"

$dbService

Expand Down Expand Up @@ -274,6 +275,12 @@ private function entrypoint(): string
if [ ! -s /var/www/html/config.php ] && [ -f /var/www/html/install/phpbbcli.php ]; then
php /var/www/html/install/phpbbcli.php install /opt/quickinstall/install-config.yml
rm -rf /var/www/html/install
if php -r 'try { new DateTimeZone((string) getenv("QUICKINSTALL_BOARD_TIMEZONE")); } catch (Exception $e) { exit(1); }'; then
php /var/www/html/bin/phpbbcli.php config:set board_timezone "$QUICKINSTALL_BOARD_TIMEZONE"
else
echo "Host timezone '$QUICKINSTALL_BOARD_TIMEZONE' is unsupported by this PHP runtime; using UTC."
php /var/www/html/bin/phpbbcli.php config:set board_timezone UTC
fi
chown -R www-data:www-data /var/www/html
fi

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/BoardRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testStopPurgeCacheAndRecreateWebRunExpectedDockerCommands(): voi
self::assertSame(['up', '-d', '--force-recreate', 'web'], array_slice($runner->runs[2], -4));
}

public function testUninstallExtensionDisablesThenPurges(): void
public function testUninstallExtensionDisablesPurgesAndClearsCache(): void
{
[$project] = $this->projectWithBoard();
$runner = new TestBoardRunner($project);
Expand All @@ -89,6 +89,7 @@ public function testUninstallExtensionDisablesThenPurges(): void

self::assertSame(['extension:disable', 'vendor/demo'], array_slice($runner->capturedCommands[0], -2));
self::assertSame(['extension:purge', 'vendor/demo'], array_slice($runner->runs[0], -2));
self::assertSame('php bin/phpbbcli.php cache:purge', end($runner->runs[1]));
}

public function testUninstallStyleCopiesAndRunsPhpbbCleanupScript(): void
Expand Down
30 changes: 30 additions & 0 deletions tests/Unit/BoardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,27 @@ public function testCreateWritesBoardAndRuntimeConfig(): void
self::assertSame(8090, $result['board']['port']);
self::assertSame('tiny', $result['board']['populate']);
self::assertTrue($result['board']['debug']);
self::assertSame('America/Los_Angeles', $result['board']['board_timezone']);
self::assertSame('demo', $project->boards()['demo']['name']);
self::assertFileExists($project->composePath('demo'));
}

public function testHostTimezoneUsesPhpCompatibleEnvironmentValue(): void
{
$previous = getenv('TZ');
putenv('TZ=US/Pacific');

try
{
$project = $this->projectWithSource('3.3.14');
self::assertSame('US/Pacific', (new HostTimezoneTestBoardService($project))->detectedHostTimezone());
}
finally
{
$previous === false ? putenv('TZ') : putenv('TZ=' . $previous);
}
}

public function testCreateRejectsDuplicateWithoutReplace(): void
{
$project = $this->projectWithSource('3.3.14');
Expand Down Expand Up @@ -236,6 +253,14 @@ private function projectWithSource(string $version, ?string $osFamily = null): P
}
}

class HostTimezoneTestBoardService extends BoardService
{
public function detectedHostTimezone(): string
{
return $this->hostTimezone();
}
}

class TestBoardService extends BoardService
{
private ?ServiceTestBoardRunner $runner;
Expand All @@ -255,6 +280,11 @@ protected function isPortInUse(int $port): bool
return $this->portInUse;
}

protected function hostTimezone(): string
{
return 'America/Los_Angeles';
}

protected function createBoardRunner(): BoardRunner
{
return $this->runner ?? parent::createBoardRunner();
Expand Down
9 changes: 8 additions & 1 deletion tests/Unit/DockerComposeWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ public function testWritesDatabaseRuntimeFiles(string $board, string $db, array
self::assertFileExists($paths['install_config']);
self::assertFileExists($paths['dockerfile']);
self::assertFileExists($paths['entrypoint']);
self::assertStringContainsString('apache2-foreground', file_get_contents($paths['entrypoint']));
$entrypoint = file_get_contents($paths['entrypoint']);
self::assertStringContainsString('apache2-foreground', $entrypoint);
self::assertStringContainsString('new DateTimeZone((string) getenv("QUICKINSTALL_BOARD_TIMEZONE"))', $entrypoint);
self::assertStringContainsString('config:set board_timezone "$QUICKINSTALL_BOARD_TIMEZONE"', $entrypoint);
self::assertStringContainsString('config:set board_timezone UTC', $entrypoint);
self::assertStringContainsString("is unsupported by this PHP runtime; using UTC.", $entrypoint);
self::assertStringContainsString('QUICKINSTALL_BOARD_TIMEZONE: "America/Los_Angeles"', file_get_contents($paths['compose']));

$output = file_get_contents($paths['compose']) . "\n" . file_get_contents($paths['install_config']) . "\n" . file_get_contents($paths['dockerfile']);
foreach ($expectedContains as $expected)
Expand Down Expand Up @@ -164,6 +170,7 @@ private function config(array $overrides = []): array
'admin_pass' => 'password',
'admin_email' => 'admin@example.test',
'board_email' => 'board@example.test',
'board_timezone' => 'America/Los_Angeles',
'extensions' => [
'acme/demo' => ['mode' => 'bind', 'source' => '/tmp/acme-demo'],
],
Expand Down