Migrate Laysense to unmodified LaySite 1.5.2

This commit is contained in:
2026-11-28 14:44:34 +08:00
parent e39439467d
commit b08008c9ca
134 changed files with 3485 additions and 754 deletions
+14 -7
View File
@@ -2,9 +2,11 @@
declare(strict_types=1);
use App\Content\Database;
use Dotenv\Dotenv;
require dirname(__DIR__) . '/vendor/autoload.php';
require __DIR__ . '/migrate-content.php';
function sourcePath(string $root, array $env, string $key, string $default): string
{
@@ -96,8 +98,10 @@ try {
}
$env = Dotenv::createArrayBacked($source)->safeLoad();
$original = sourcePath($source, $env, 'LAYSITE_DB', 'storage/laysite.sqlite');
$uploads = sourcePath($source, $env, 'LAYSITE_MEDIA_DIR', 'storage/media');
$storage = is_file($source . '/laysite.sqlite') ? '' : 'storage/';
$original = sourcePath($source, $env, 'LAYSITE_DB', $storage . 'laysite.sqlite');
$uploads = sourcePath($source, $env, 'LAYSITE_MEDIA_DIR', $storage . 'media');
$legacyData = sourcePath($source, $env, 'LAYSENSE_SITE_DIR', '.');
if (!is_file($original)) {
throw new RuntimeException('旧站目录缺少 SQLite 数据库。');
}
@@ -134,16 +138,19 @@ try {
alignSiteData($db);
$db = null;
$assets = json_decode(file_get_contents(dirname(__DIR__) . '/plugin/laysense/assets.json'), true, flags: JSON_THROW_ON_ERROR);
foreach ($assets as $asset) {
copyFile($source . '/public/' . $asset, $stage . '/' . $asset);
}
putenv('LAYSITE_DB=' . $stage . '/laysite.sqlite');
putenv('LAYSITE_MEDIA_DIR=' . $stage . '/media');
Database::initialize();
migrateAssetsAndDesign([$source . '/public', $legacyData, $source], $stage);
if (is_file($source . '/backup.tar')) {
copyFile($source . '/backup.tar', $stage . '/backups/legacy-backup.tar');
}
if (Database::connect()->query('PRAGMA wal_checkpoint(TRUNCATE)')->fetchColumn() !== 0) {
throw new RuntimeException('新站 SQLite 暂存数据未能写入数据库。');
}
$dotenv = is_file($source . '/.env') ? file_get_contents($source . '/.env') : "LAYSITE_SITE_URL=https://laysense.cn\n";
$dotenv = preg_replace('/^\h*(?:export\h+)?(?:LAYSITE_DB|LAYSITE_MEDIA_DIR|LAYSENSE_SITE_DIR)\h*=.*(?:\R|$)/m', '', $dotenv);
foreach (['LAYSITE_DB' => $target . '/laysite.sqlite', 'LAYSITE_MEDIA_DIR' => $target . '/media', 'LAYSENSE_SITE_DIR' => $target] as $key => $value) {
foreach (['LAYSITE_DB' => $target . '/laysite.sqlite', 'LAYSITE_MEDIA_DIR' => $target . '/media'] as $key => $value) {
if (preg_match('/[\r\n\x00]/', $value)) {
throw new RuntimeException('数据目录包含无效字符。');
}