Files
KantSites/tests/pilot-fixture.php
T
kantarci 495b26896e
CMS quality / php (8.2) (push) Canceled after 0s
CMS quality / php (8.4) (push) Canceled after 0s
CMS quality / browser (push) Canceled after 0s
CMS quality / mysql (push) Canceled after 0s
Fassung 1.7.0: verlässliche Installation, übersichtliche Verwaltung und bedienbare Bewegung
2026-09-14 10:49:54 +02:00

30 lines
1.4 KiB
PHP

<?php
// Read the local pilot only to make a consistent, isolated copy. Never write to its database.
require dirname(__DIR__).'/vendor/autoload.php';
use App\Infrastructure\ConnectionFactory;
$root = dirname(__DIR__);
$source = $argv[1] ?? $root.'/var/kantit.db';
if (!is_file($source)) {
throw new RuntimeException('Die Pilotdatenbank fehlt. Pfad als erstes Argument angeben.');
}
$directory = $root.'/var/browser-tests/pilot-'.bin2hex(random_bytes(6));
mkdir($directory, 0o700, true);
$path = $directory.'/pilot.db';
$original = new SQLite3($source, SQLITE3_OPEN_READONLY);
$copy = new SQLite3($path);
if (!$original->backup($copy)) {
throw new RuntimeException('Die Pilotdatenbank konnte nicht kopiert werden.');
}
$copy->close();
$original->close();
$url = 'sqlite:///'.str_replace('\\', '/', $path);
$db = ConnectionFactory::create($url);
$db->executeStatement('UPDATE scheduled_task SET enabled = 0');
$username = 'qa-'.bin2hex(random_bytes(6));
$password = bin2hex(random_bytes(20));
$db->insert('cms_user', ['id' => $username, 'username' => $username, 'password_hash' => password_hash($password, PASSWORD_BCRYPT, ['cost' => 4]), 'roles' => '["ROLE_ADMIN"]']);
echo json_encode(['databaseUrl' => $url, 'mediaDirectory' => $root.'/var/kantit-media', 'directory' => $directory, 'username' => $username, 'password' => $password, 'homeId' => $db->fetchOne("SELECT id FROM page WHERE path = 'home'")], JSON_THROW_ON_ERROR);