Migrate Laysense to unmodified LaySite 1.5.2
This commit is contained in:
+10
-18
@@ -1,35 +1,27 @@
|
||||
# laysense.cn 部署与升级
|
||||
# laysense.cn 迁移到 LaySite 1.5.2
|
||||
|
||||
网站使用 LaySite 官方 1.4.3。站点扩展在 `plugin/laysense/`,通过 Webman 保留品牌外观、版权服务页样式、首页动效、原静态文件地址和旧文章跳转。核心代码与官方发布包一致。
|
||||
程序文件与官方 `v1.5.2` 一致。这个目录的脚本负责一次性转换来笙网站的数据。迁移后的站点由 LaySite 原生功能运行。
|
||||
|
||||
## 从当前站点迁移一次
|
||||
## 生成迁移数据
|
||||
|
||||
将新版本部署到新的代码目录。旧站的运行目录是首选数据源,`backup` 分支的单独检出也可作为快照来源。使用运行 Webman 的系统账户执行迁移。先暂停旧站的写入,再运行下列命令。
|
||||
把本分支检出到新的程序目录,并在该目录运行以下命令。第一个参数可以是原网站程序目录,也可以是已经分离的旧数据目录。
|
||||
|
||||
```sh
|
||||
cd /srv/laysense-code
|
||||
composer install --no-dev --prefer-dist
|
||||
php site/migrate.php /srv/laysense-old /srv/laysense-data
|
||||
ln -s /srv/laysense-data/.env .env
|
||||
php bin/install.php
|
||||
php site/migrate.php /www/laysense-old /www/laysense-data-152
|
||||
ln -s /www/laysense-data-152/.env .env
|
||||
php start.php start
|
||||
```
|
||||
|
||||
迁移会读取旧库和 WAL 中的已提交数据,生成完整的独立 SQLite 文件。它同时复制 SQLite 密钥(如有)、上传文件、旧 URL 对应的静态素材及原站点环境配置。脚本会拒绝覆盖已有目标数据目录。管理员账号也在迁移后的数据库里,可继续使用原账号登录。
|
||||
目标数据目录须尚未存在。先用旧站副本演练。正式切换前暂停旧站写入,再对生产数据生成一次副本。迁移读取 SQLite 中已提交的 WAL 数据,同时复制媒体、数据库密钥(如有)和运行设置。已有管理员可继续使用原账号登录。使用运行 LaySite 的系统账户执行,或在启动前赋予该账户相应的目录权限。若程序目录已有 `.env`,先保留原文件,然后使用迁移生成的配置。
|
||||
|
||||
产品与服务及支持项目分类分别采用 LaySite 的标准标识 `catalog` 和 `projects`。分类名称、文章关系和旧 URL 都会保留。页脚地址与三个旧区块样式也会转换为官方备份工具可导入的格式。
|
||||
|
||||
反向代理将新代码目录的 `public/` 作为静态目录,把其余请求转给 Webman。旧站素材路径需要保留这一回退规则,才能由站点扩展从独立数据目录提供文件。沿用 CDN 时,同步或刷新对应素材的缓存即可。
|
||||
素材、品牌 CSS 和首页动效 JS 导入媒体库。页面、文章及页头页脚中的素材引用会指向新的媒体地址。站点图标在站点设置中管理。全站 CSS 和首页 JS 分别由全站 Head 和首页 Head 加载。站内已知的旧链接更新为当前地址。现有公开页面沿用原网址标识。
|
||||
|
||||
## 后续更新
|
||||
|
||||
进入新站代码目录,先检查可用版本。带目标标签执行更新前暂停 Webman。
|
||||
长期保存迁移后的数据目录和其中的 `.env`、SQLite 文件、数据库密钥及 `media/`。LaySite 的站点备份也包含媒体库文件、站点图标和 Head 设置。直接使用官方更新器检查版本并升级。执行升级前暂停 Webman。
|
||||
|
||||
```sh
|
||||
php bin/update.php check
|
||||
php bin/update.php
|
||||
php bin/update.php vX.Y.Z /www/laysense-data-152/pre-update.tar
|
||||
```
|
||||
|
||||
可直接指定版本和备份路径,例如 `php bin/update.php vX.Y.Z /srv/laysense-data/backups/pre-update.tar`。更新器会替换官方发布包中的系统文件及运行数据库迁移。站点扩展和独立数据目录会保留。
|
||||
|
||||
日常备份应包含整个 `/srv/laysense-data` 目录。LaySite 的站点备份另可用于移植数据库内容和媒体库上传文件。
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
.hero-home .hero-visual.app-frame {
|
||||
isolation: isolate;
|
||||
border: 1px solid #cad9f6;
|
||||
border-radius: 1.8rem;
|
||||
background: radial-gradient(circle, #a9bce9 1px, transparent 1.3px) 0 0 / 20px 20px, #eaf0fd;
|
||||
padding: clamp(.45rem, 1.8vw, 1.7rem);
|
||||
box-shadow: 0 22px 85px -44px #204dba65;
|
||||
}
|
||||
.hero-home .hero-visual.app-frame img {
|
||||
aspect-ratio: 4 / 3;
|
||||
object-fit: cover;
|
||||
border-radius: 1.15rem;
|
||||
mix-blend-mode: multiply;
|
||||
}
|
||||
.hero-home ~ #about {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
isolation: isolate;
|
||||
color: white;
|
||||
background: var(--navy);
|
||||
}
|
||||
.hero-home ~ #about::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
inset: 0;
|
||||
background: repeating-radial-gradient(circle at 90% 72%, transparent 0 33px, #5e8ff822 34px 35px, transparent 36px 60px),
|
||||
linear-gradient(135deg, #111f3b, #142b5f);
|
||||
pointer-events: none;
|
||||
}
|
||||
.hero-home ~ #about.moment-active::before { animation: iris 900ms ease-out both; }
|
||||
.hero-home ~ #about .section-heading { margin-bottom: 1.45rem; }
|
||||
.hero-home ~ #about .rich p { color: #dbe7ff; font-size: clamp(1.2rem, 2.4vw, 1.7rem); max-width: 50rem; }
|
||||
.page-photo-credit { padding-bottom: 1.4rem; margin-bottom: 0; color: var(--muted); font-size: .875rem; }
|
||||
|
||||
@media (max-width: 44rem) {
|
||||
.hero-home .hero-visual.app-frame { border-radius: 1.15rem; }
|
||||
.hero-home .hero-visual.app-frame img { border-radius: .8rem; }
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
.footer-company .site-address { margin: .25rem 0 0; color: var(--muted); max-width: 26rem; font-style: italic; }
|
||||
@@ -0,0 +1,12 @@
|
||||
<svg class="home-pipe-flow" viewBox="0 0 640 480" aria-hidden="true" focusable="false">
|
||||
<defs>
|
||||
<path id="hero-pipe-tower" pathLength="100" d="M174 347 241 312 Q246 310 246 305 L246 299 Q246 295 252 293 L273 282"/>
|
||||
<path id="hero-pipe-disk" pathLength="100" d="M409 282 428 293 Q433 296 433 300 L433 304 Q433 307 438 309 L500 337"/>
|
||||
<path id="hero-pipe-node" pathLength="100" d="M119 201 125 205 Q129 207 129 212 L129 214 Q130 217 134 219 L190 243"/>
|
||||
<path id="hero-pipe-chart" pathLength="100" d="M443 226 471 213 Q478 208 483 209 L488 207 Q492 205 492 200 L492 182"/>
|
||||
</defs>
|
||||
<g class="home-pipe-route"><use href="#hero-pipe-tower"/><use href="#hero-pipe-tower"/></g>
|
||||
<g class="home-pipe-route"><use href="#hero-pipe-disk"/><use href="#hero-pipe-disk"/></g>
|
||||
<g class="home-pipe-route"><use href="#hero-pipe-node"/><use href="#hero-pipe-node"/></g>
|
||||
<g class="home-pipe-route"><use href="#hero-pipe-chart"/><use href="#hero-pipe-chart"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1004 B |
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const homeHero = document.querySelector('#main-content > .hero-home');
|
||||
const homeTitle = homeHero?.querySelector('.hero-copy h1');
|
||||
if (homeTitle) {
|
||||
const cursor = document.createElement('span');
|
||||
cursor.className = 'home-cursor';
|
||||
cursor.setAttribute('aria-hidden', 'true');
|
||||
cursor.textContent = '_';
|
||||
homeTitle.append(cursor);
|
||||
}
|
||||
|
||||
const homeImage = homeHero?.querySelector('.hero-visual > img');
|
||||
if (homeImage && new URL(homeImage.src).pathname === HOME_IMAGE_PATH) {
|
||||
homeImage.insertAdjacentHTML('afterend', HOME_MOTION_SVG);
|
||||
}
|
||||
|
||||
document.querySelector('#main-content > .hero-home ~ #about')?.setAttribute('data-moment', 'iris-opens');
|
||||
@@ -0,0 +1,65 @@
|
||||
[
|
||||
"assets/favicon.png",
|
||||
"assets/laysense.css",
|
||||
"assets/original/10-1.png",
|
||||
"assets/original/10-2.png",
|
||||
"assets/original/10-3.png",
|
||||
"assets/original/1s.png",
|
||||
"assets/original/DNSPod.svg",
|
||||
"assets/original/IP.png",
|
||||
"assets/original/IdealShark_B.png",
|
||||
"assets/original/RAM.png",
|
||||
"assets/original/Redis.png",
|
||||
"assets/original/backup.png",
|
||||
"assets/original/chinadomain.png",
|
||||
"assets/original/component-element.mp4",
|
||||
"assets/original/copyright-wechat.png",
|
||||
"assets/original/copyright.webp",
|
||||
"assets/original/download.png",
|
||||
"assets/original/drag-in-components.mp4",
|
||||
"assets/original/edit-components.mp4",
|
||||
"assets/original/fast.png",
|
||||
"assets/original/footer-wordmark.webp",
|
||||
"assets/original/fw-banner.svg",
|
||||
"assets/original/highspeaker-logo-optimized.webp",
|
||||
"assets/original/highspeaker-ui-optimized.webp",
|
||||
"assets/original/highspeakerrz-optimized.webp",
|
||||
"assets/original/home-hero.webp",
|
||||
"assets/original/icon_rewrite.png",
|
||||
"assets/original/jeo-optimized.webp",
|
||||
"assets/original/locate.png",
|
||||
"assets/original/logo_img.png",
|
||||
"assets/original/mimirlib.png",
|
||||
"assets/original/nonat-optimized.webp",
|
||||
"assets/original/oneprovider_invert.svg",
|
||||
"assets/original/orange-optimized.webp",
|
||||
"assets/original/pagepan-editor-optimized.webp",
|
||||
"assets/original/pagepan-example.webp",
|
||||
"assets/original/pagepan-wechat.png",
|
||||
"assets/original/pagepan/cdn.svg",
|
||||
"assets/original/pagepan/cms.svg",
|
||||
"assets/original/pagepan/code.svg",
|
||||
"assets/original/pagepan/files.svg",
|
||||
"assets/original/pagepan/fonts.svg",
|
||||
"assets/original/pagepan/gradient.svg",
|
||||
"assets/original/pagepan/languages.svg",
|
||||
"assets/original/pagepan/seo.svg",
|
||||
"assets/original/pagepan/sitemap.svg",
|
||||
"assets/original/papepan-logo.svg",
|
||||
"assets/original/payment-alipay.png",
|
||||
"assets/original/payment-taobao.png",
|
||||
"assets/original/payment-wechat.png",
|
||||
"assets/original/qywx.png",
|
||||
"assets/original/shnu-hero.webp",
|
||||
"assets/original/smartroute.png",
|
||||
"assets/original/sorting-components.mp4",
|
||||
"assets/original/teo-optimized.webp",
|
||||
"assets/original/traffic.png",
|
||||
"assets/original/waf.png",
|
||||
"assets/page-templates/dusk-dunes.webp",
|
||||
"assets/page-templates/studio-letterpress.webp",
|
||||
"assets/service/code.svg",
|
||||
"assets/service/project.svg",
|
||||
"assets/service/support.svg",
|
||||
"assets/wordmark.webp"
|
||||
]
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Content\Database;
|
||||
use App\Content\Html;
|
||||
use App\Content\Media;
|
||||
use App\Content\PageHead;
|
||||
use App\Content\SiteIcon;
|
||||
use App\Content\View;
|
||||
use Webman\Http\UploadFile;
|
||||
|
||||
function findAsset(array $roots, string $asset): string
|
||||
{
|
||||
foreach ($roots as $root) {
|
||||
$source = $root . '/' . $asset;
|
||||
if (is_file($source) && is_readable($source)) {
|
||||
return $source;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException('找不到旧站素材 ' . $asset);
|
||||
}
|
||||
|
||||
function readText(string $path): string
|
||||
{
|
||||
$contents = file_get_contents($path);
|
||||
if ($contents === false) {
|
||||
throw new RuntimeException('读取文件失败 ' . basename($path));
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
function normalizeLegacySvg(string $path): string
|
||||
{
|
||||
$contents = str_replace('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">', '', readText($path));
|
||||
$document = new DOMDocument();
|
||||
if (!$document->loadXML($contents, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING)
|
||||
|| $document->doctype || !$document->documentElement) {
|
||||
throw new RuntimeException('无法读取旧站 SVG ' . basename($path));
|
||||
}
|
||||
foreach ($document->getElementsByTagName('*') as $node) {
|
||||
foreach (['id', 'version', 'class', 'enable-background', 'xml:space', 'p-id', 't'] as $name) {
|
||||
$node->removeAttribute($name);
|
||||
}
|
||||
if ($node->hasAttribute('style') && preg_match('/^fill:\s*(#[a-f0-9]{3,8});?$/iD', $node->getAttribute('style'), $fill)) {
|
||||
$node->setAttribute('fill', $fill[1]);
|
||||
$node->removeAttribute('style');
|
||||
}
|
||||
}
|
||||
|
||||
return $document->saveXML($document->documentElement);
|
||||
}
|
||||
|
||||
function importMedia(string $source, string $label): string
|
||||
{
|
||||
try {
|
||||
Media::upload(new UploadFile($source, $label, '', UPLOAD_ERR_OK), $label);
|
||||
} catch (RuntimeException $error) {
|
||||
throw new RuntimeException('无法导入媒体 ' . $label . ':' . $error->getMessage(), previous: $error);
|
||||
}
|
||||
$name = Database::connect()->query('SELECT name FROM media WHERE rowid = last_insert_rowid()')->fetchColumn();
|
||||
if (!is_string($name)) {
|
||||
throw new RuntimeException('找不到导入后的媒体 ' . $label);
|
||||
}
|
||||
|
||||
return '/assets/uploads/' . $name;
|
||||
}
|
||||
|
||||
function importText(string $stage, string $label, string $contents): string
|
||||
{
|
||||
$temporary = $stage . '/asset-import';
|
||||
if (file_put_contents($temporary, $contents) !== strlen($contents)) {
|
||||
throw new RuntimeException('无法暂存媒体 ' . $label);
|
||||
}
|
||||
try {
|
||||
return importMedia($temporary, $label);
|
||||
} finally {
|
||||
unlink($temporary);
|
||||
}
|
||||
}
|
||||
|
||||
function rewriteReferences(PDO $db, array $assets, array $links, array $origins): void
|
||||
{
|
||||
$replacements = $assets + $links;
|
||||
$origins = array_map(static fn (string $origin): string => preg_quote(rtrim($origin, '/'), '~'), array_filter($origins));
|
||||
$alternatives = array_keys($replacements);
|
||||
usort($alternatives, static fn (string $a, string $b): int => strlen($b) <=> strlen($a));
|
||||
$alternatives = array_map(static fn (string $path): string => preg_quote($path, '~'), $alternatives);
|
||||
$pattern = '~(?<![a-z0-9_.:/%-])(?:' . implode('|', $origins) . ')?(' . implode('|', $alternatives) . ')(?=$|[\s"\'<>?#(),\[\]])~i';
|
||||
$columnsByTable = [
|
||||
'site_settings' => ['payload'],
|
||||
'pages' => ['image', 'heading', 'description', 'lead', 'actions', 'quicklinks', 'presentation', 'head_html'],
|
||||
'sections' => ['body', 'lead', 'presentation'],
|
||||
'articles' => ['body', 'summary', 'card'],
|
||||
'design_presets' => ['payload'],
|
||||
];
|
||||
foreach ($columnsByTable as $table => $columns) {
|
||||
$assignments = implode(', ', array_map(static fn (string $key): string => $key . ' = ?', $columns));
|
||||
$update = $db->prepare("UPDATE $table SET $assignments WHERE rowid = ?");
|
||||
foreach ($db->query('SELECT rowid AS record_id, ' . implode(', ', $columns) . ' FROM ' . $table)->fetchAll() as $row) {
|
||||
$id = array_shift($row);
|
||||
$values = array_values($row);
|
||||
$newValues = array_map(static fn (string $value): string => preg_replace_callback(
|
||||
$pattern, static fn (array $match): string => $replacements[$match[1]] ?? $match[0], $value
|
||||
) ?? throw new RuntimeException('无法迁移旧链接。'), $values);
|
||||
if ($values !== $newValues) {
|
||||
$update->execute([...$newValues, $id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function migrateAssetsAndDesign(array $roots, string $stage): void
|
||||
{
|
||||
$inventory = json_decode(readText(__DIR__ . '/legacy-assets.json'), true, flags: JSON_THROW_ON_ERROR);
|
||||
$assets = [];
|
||||
$iconFile = findAsset($roots, 'assets/favicon.png');
|
||||
$legacyCss = readText(findAsset($roots, 'assets/laysense.css'));
|
||||
foreach ($inventory as $asset) {
|
||||
if ($asset === 'assets/laysense.css') {
|
||||
continue;
|
||||
}
|
||||
$file = findAsset($roots, $asset);
|
||||
$label = basename($file);
|
||||
$assets['/' . $asset] = str_ends_with($asset, '.svg')
|
||||
? importText($stage, $label, normalizeLegacySvg($file)) : importMedia($file, $label);
|
||||
}
|
||||
$brandCss = strtr($legacyCss, $assets + [
|
||||
'.hero-service-art' => '.hero-visual.app-frame',
|
||||
'.copyright-service' => '#main-content:has(> :is(.hero-sc, .hero-shnu-sc))',
|
||||
]) . "\n" . readText(__DIR__ . '/footer.css') . "\n" . readText(__DIR__ . '/brand.css');
|
||||
$style = importText($stage, 'laysense.css', $brandCss);
|
||||
$homeImage = $assets['/assets/original/home-hero.webp'];
|
||||
$homeMotion = "(() => {\n" . strtr(readText(__DIR__ . '/home.js'), [
|
||||
'HOME_IMAGE_PATH' => json_encode($homeImage, JSON_THROW_ON_ERROR),
|
||||
'HOME_MOTION_SVG' => json_encode(readText(__DIR__ . '/home-motion.svg'), JSON_THROW_ON_ERROR),
|
||||
]) . "\n})();\n";
|
||||
$script = importText($stage, 'laysense-home.js', $homeMotion);
|
||||
$assets['/assets/laysense.css'] = $style;
|
||||
$assets['/assets/laysense-site-compat.css'] = $style;
|
||||
|
||||
Database::write(static function (PDO $db) use ($assets, $iconFile, $style, $script, $homeImage): void {
|
||||
$site = json_decode($db->query('SELECT payload FROM site_settings WHERE id = 1')->fetchColumn(), true, flags: JSON_THROW_ON_ERROR);
|
||||
$links = [
|
||||
'/main' => '/articles', '/main/category/1.html' => '/articles/category/product',
|
||||
'/main/category/2.html' => '/articles/category/news', '/main/category/3.html' => '/articles/category/announcement',
|
||||
'/main/category/5.html' => '/#projects', '/main/category/6.html' => '/#partners',
|
||||
'/articles/category/services' => '/articles/category/catalog',
|
||||
'/articles/category/supported-projects' => '/articles/category/projects',
|
||||
'/#supported-projects' => '/#projects', '/home#supported-projects' => '/home#projects',
|
||||
'/network#supported-projects' => '/network#network-group-projects', '/network#partners' => '/network#network-group-partners',
|
||||
];
|
||||
foreach ($db->query("SELECT legacy_path, slug FROM articles WHERE status = 'published' AND legacy_path LIKE '/news/id/%'") as $article) {
|
||||
$links[$article['legacy_path']] = '/articles/' . $article['slug'];
|
||||
}
|
||||
rewriteReferences($db, $assets, $links, ['https://laysense.cn', 'http://laysense.cn', $site['cdn']['origin'] ?? '']);
|
||||
|
||||
$site = json_decode($db->query('SELECT payload FROM site_settings WHERE id = 1')->fetchColumn(), true, flags: JSON_THROW_ON_ERROR);
|
||||
if (empty($site['favicon'])) {
|
||||
$site['favicon'] = SiteIcon::normalize(base64_encode(readText($iconFile)));
|
||||
}
|
||||
$head = $site['head_html'] ?? '';
|
||||
$head .= "\n<link rel=\"stylesheet\" href=\"" . View::escape($style) . '">';
|
||||
if (!str_contains($head, 'og:image')) {
|
||||
$image = rtrim($site['cdn']['origin'] ?? 'https://laysense.cn', '/') ?: 'https://laysense.cn';
|
||||
$head .= "\n<meta property=\"og:image\" content=\"" . View::escape($image . $homeImage) . '">'
|
||||
. "\n<meta property=\"og:image:alt\" content=\"来笙 Laysense\">";
|
||||
}
|
||||
$site['head_html'] = PageHead::normalize($head);
|
||||
$db->prepare('UPDATE site_settings SET payload = ? WHERE id = 1')->execute([Database::json($site)]);
|
||||
$head = $db->query("SELECT head_html FROM pages WHERE slug = 'home'")->fetchColumn();
|
||||
if ($head !== false) {
|
||||
$head = PageHead::normalize($head . "\n<script src=\"" . View::escape($script) . "\" defer></script>");
|
||||
$db->prepare("UPDATE pages SET head_html = ? WHERE slug = 'home'")->execute([$head]);
|
||||
}
|
||||
migratePhotoCredits($db, $assets);
|
||||
if ($db->query('PRAGMA foreign_key_check')->fetch() !== false) {
|
||||
throw new RuntimeException('迁移数据包含无效的关联记录。');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function migratePhotoCredits(PDO $db, array $assets): void
|
||||
{
|
||||
$credits = [
|
||||
'studio-letterpress.webp' => ['Adam Lusch', 'CC BY-SA 2.0', 'https://commons.wikimedia.org/wiki/File:Wood_Type_close-up.jpg', 'https://creativecommons.org/licenses/by-sa/2.0/'],
|
||||
'dusk-dunes.webp' => ['Bob Wick / BLM Utah', '公有领域', 'https://commons.wikimedia.org/wiki/File:Utah_Dunes_Landscape_-_West_Desert_District.jpg', ''],
|
||||
];
|
||||
$pages = $db->prepare('SELECT slug, visibility FROM pages WHERE image = ? AND layout_id IS NULL');
|
||||
$insert = $db->prepare("INSERT OR IGNORE INTO sections (page_slug, key, title, lead, body, style, position)
|
||||
VALUES (?, 'photo-credit', '摄影署名', '', ?, 'layout', (SELECT COALESCE(MAX(position), -1) + 1 FROM sections WHERE page_slug = ?))");
|
||||
foreach ($credits as $image => [$author, $license, $source, $terms]) {
|
||||
$pages->execute([$assets['/assets/page-templates/' . $image]]);
|
||||
$authorLink = '<a href="' . View::escape($source) . '">' . View::escape($author) . '</a>';
|
||||
$termsLink = $terms === '' ? View::escape($license) : '<a href="' . View::escape($terms) . '">' . View::escape($license) . '</a>';
|
||||
$body = Html::sanitize('<p class="wrap page-photo-credit">摄影 ' . $authorLink . ' · ' . $termsLink . '</p>');
|
||||
foreach ($pages->fetchAll() as $page) {
|
||||
if (json_decode($page['visibility'], true, flags: JSON_THROW_ON_ERROR)['hero'] ?? true) {
|
||||
$insert->execute([$page['slug'], $body, $page['slug']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-7
@@ -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('数据目录包含无效字符。');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user