Edit shared headers and footers as page types
This commit is contained in:
@@ -12,7 +12,7 @@ use Throwable;
|
||||
final class SiteBackup
|
||||
{
|
||||
private const FORMAT = 'laysite-site';
|
||||
private const VERSION = 2;
|
||||
private const VERSION = 3;
|
||||
private const TABLES = [
|
||||
'site_settings', 'design_presets', 'pages', 'sections', 'article_categories', 'articles',
|
||||
'article_category_links', 'article_redirects', 'article_deletions', 'media',
|
||||
@@ -140,7 +140,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, self::VERSION], true) || !is_array($manifest['tables'] ?? null)) {
|
||||
|| !in_array($manifest['version'] ?? null, [1, 2, self::VERSION], true) || !is_array($manifest['tables'] ?? null)) {
|
||||
throw new RuntimeException('备份格式不受支持,请使用相同或更新版本的 LaySite。');
|
||||
}
|
||||
$tables = $manifest['tables'];
|
||||
@@ -179,7 +179,16 @@ final class SiteBackup
|
||||
}
|
||||
$tables['site_settings'] = [['id' => 1, 'payload' => Database::json($site)]];
|
||||
foreach ($tables['pages'] as &$row) {
|
||||
PageDraft::slug($row['slug'] ?? null, array_diff(PageDraft::RESERVED, ['home']));
|
||||
$layout = $row['layout_id'] ?? null;
|
||||
if ($layout === null) {
|
||||
PageDraft::slug($row['slug'] ?? null, array_diff(PageDraft::RESERVED, ['home']));
|
||||
} else {
|
||||
$kind = is_int($layout) ? ($designs[$layout] ?? null) : null;
|
||||
if (!in_array($kind, ['header', 'footer'], true) || ($row['slug'] ?? null) !== LayoutPage::slug($kind, $layout)) {
|
||||
throw new RuntimeException('备份包含无效的页头或页脚页面。');
|
||||
}
|
||||
$row['status'] = 'published';
|
||||
}
|
||||
self::validateAssetUrl($row['image'] ?? '', true);
|
||||
$row['actions'] = Database::json(Buttons::validate(self::decode($row['actions'] ?? '[]')));
|
||||
$row['quicklinks'] = Database::json(Buttons::validate(self::decode($row['quicklinks'] ?? '[]'), 20));
|
||||
@@ -196,7 +205,7 @@ final class SiteBackup
|
||||
unset($row);
|
||||
foreach ($tables['sections'] as &$row) {
|
||||
PageDraft::slug($row['key'] ?? null, ['home', 'contact', 'main-content', 'primary-navigation', 'preview']);
|
||||
if (!in_array($row['style'] ?? '', ['plain', 'tinted', 'hero-links'], true)) {
|
||||
if (!in_array($row['style'] ?? '', ['plain', 'tinted', 'hero-links', 'layout'], true)) {
|
||||
throw new RuntimeException('备份包含未知区块样式。');
|
||||
}
|
||||
$row['body'] = Html::sanitize($row['body'] ?? '');
|
||||
@@ -267,6 +276,7 @@ final class SiteBackup
|
||||
$insert->execute([$layout['id'], $saved['revision'], $saved['encrypted_secret']]);
|
||||
}
|
||||
}
|
||||
LayoutPage::migrate($pdo);
|
||||
}
|
||||
|
||||
private static function selection(array $designs, string $kind, mixed $id): ?int
|
||||
|
||||
Reference in New Issue
Block a user