forked from laysense/laysite
Prepare LaySite 1.5.1 page routing and template updates
This commit is contained in:
+21
-13
@@ -12,7 +12,7 @@ use Throwable;
|
||||
final class SiteBackup
|
||||
{
|
||||
private const FORMAT = 'laysite-site';
|
||||
private const VERSION = 5;
|
||||
private const VERSION = 6;
|
||||
private const TABLES = [
|
||||
'site_settings', 'design_presets', 'pages', 'sections', 'article_categories', 'articles',
|
||||
'article_category_links', 'article_redirects', 'article_deletions', 'media',
|
||||
@@ -111,6 +111,7 @@ final class SiteBackup
|
||||
}
|
||||
Database::write(function (PDO $pdo) use ($tables, $staged, $directory, &$installed): void {
|
||||
self::replaceTables($pdo, $tables);
|
||||
DesignLibrary::ensureDefaultPalette($pdo);
|
||||
foreach ($staged as $name => $source) {
|
||||
$target = $directory . '/' . $name;
|
||||
if (is_file($target) && !is_link($target) && hash_file('sha256', $target) === hash_file('sha256', $source)) {
|
||||
@@ -140,7 +141,7 @@ final class SiteBackup
|
||||
private static function prepare(mixed $manifest): array
|
||||
{
|
||||
if (!is_array($manifest) || ($manifest['format'] ?? '') !== self::FORMAT
|
||||
|| !in_array($manifest['version'] ?? null, [1, 2, 3, 4, self::VERSION], true) || !is_array($manifest['tables'] ?? null)) {
|
||||
|| !in_array($manifest['version'] ?? null, [1, 2, 3, 4, 5, self::VERSION], true) || !is_array($manifest['tables'] ?? null)) {
|
||||
throw new RuntimeException('备份格式不受支持,请使用相同或更新版本的 LaySite。');
|
||||
}
|
||||
$tables = $manifest['tables'];
|
||||
@@ -174,6 +175,9 @@ final class SiteBackup
|
||||
$site = ['name' => $settings['name'], 'cdn' => ['origin' => Assets::cdn($settings['cdn']['origin'] ?? '')], 'revisions' => ['general' => time()]];
|
||||
$site['head_html'] = PageHead::normalize($settings['head_html'] ?? '');
|
||||
$site['favicon'] = SiteIcon::normalize($settings['favicon'] ?? '');
|
||||
if (isset($settings['palette_id'])) {
|
||||
$site['palette_id'] = self::selection($designs, 'palette', $settings['palette_id']);
|
||||
}
|
||||
$layoutDefaults = $settings['layout_defaults'] ?? [];
|
||||
if (!is_array($layoutDefaults)) {
|
||||
throw new RuntimeException('备份的基础页头页脚配置无效。');
|
||||
@@ -190,21 +194,25 @@ final class SiteBackup
|
||||
foreach ($tables['pages'] as &$row) {
|
||||
$layout = $row['layout_id'] ?? null;
|
||||
$row['page_type'] ??= 'page';
|
||||
if ($row['page_type'] !== 'page') {
|
||||
if ($layout !== null || !is_string($row['page_type']) || !SystemPage::slugMatches($row['page_type'], $row['slug'] ?? null)) {
|
||||
throw new RuntimeException('备份包含无效的系统页面。');
|
||||
}
|
||||
if (($row['status'] ?? null) === 'published') {
|
||||
$publishedSystemPages[$row['slug']] = $row['page_type'];
|
||||
}
|
||||
} elseif ($layout === null) {
|
||||
PageDraft::slug($row['slug'] ?? null);
|
||||
} else {
|
||||
PageDraft::slug($row['slug'] ?? null, includeSpecial: true);
|
||||
if ($manifest['version'] < 6 && $layout === null && $row['slug'] === 'home' && $row['page_type'] === 'page') {
|
||||
$row['page_type'] = 'home';
|
||||
}
|
||||
if (!is_string($row['page_type'])) {
|
||||
throw new RuntimeException('备份包含无效的页面类型。');
|
||||
}
|
||||
if ($layout !== null) {
|
||||
$kind = is_int($layout) ? ($designs[$layout] ?? null) : null;
|
||||
if (!in_array($kind, ['header', 'footer'], true) || ($row['slug'] ?? null) !== LayoutPage::slug($kind, $layout)) {
|
||||
if (!in_array($kind, ['header', 'footer'], true) || $row['page_type'] !== 'page') {
|
||||
throw new RuntimeException('备份包含无效的页头或页脚页面。');
|
||||
}
|
||||
$row['status'] = 'published';
|
||||
} elseif (isset(SystemPage::TYPES[$row['page_type']])) {
|
||||
if (($row['status'] ?? null) === 'published') {
|
||||
$publishedSystemPages[$row['slug']] = $row['page_type'];
|
||||
}
|
||||
} elseif (!in_array($row['page_type'], ['page', 'home'], true)) {
|
||||
throw new RuntimeException('备份包含无效的页面类型。');
|
||||
}
|
||||
self::validateAssetUrl($row['image'] ?? '', true);
|
||||
$row['actions'] = Database::json(Buttons::validate(self::decode($row['actions'] ?? '[]')));
|
||||
|
||||
Reference in New Issue
Block a user