feat(seo-copy): restore all source scenes

This commit is contained in:
root
2026-04-17 13:16:03 +08:00
parent 0b9a45e5c4
commit 28e2a93563

View File

@@ -19,18 +19,20 @@ function usage(): void
$script = basename(__FILE__); $script = basename(__FILE__);
echo <<<TXT echo <<<TXT
Usage: Usage:
php code/scripts/{$script} --host=chuanjiafeng-net --source=/abs/source/path [--target=/abs/target/path] [--dry-run] php code/scripts/{$script} --host=chuanjiafeng-net --source=/abs/source/path [--target=/abs/target/path] [--scenes=detail,play] [--dry-run]
Options: Options:
--host Host directory name under seo_copy, e.g. chuanjiafeng-net --host Host directory name under seo_copy, e.g. chuanjiafeng-net
--source Source root that contains <host>/detail/*.json and <host>/play/*.json --source Source root that contains <host>/detail/*.json and <host>/play/*.json
--target Target root. Defaults to code/data/seo_copy_published --target Target root. Defaults to code/data/seo_copy_published
--scenes Optional comma-separated scenes. Defaults to all known scenes found in source
--dry-run Preview only, do not write files --dry-run Preview only, do not write files
Examples: Examples:
php code/scripts/{$script} \\ php code/scripts/{$script} \\
--host=chuanjiafeng-net \\ --host=chuanjiafeng-net \\
--source=code/storage/domain_bootstrap_bundles/chuanjiafeng-compact/data/seo_copy \\ --source=code/storage/domain_bootstrap_bundles/chuanjiafeng-compact/data/seo_copy \\
--scenes=home,category_index,category_list,search,rank_index,rank_list,detail,forge,play \\
--dry-run --dry-run
TXT; TXT;
@@ -80,6 +82,7 @@ foreach (array_slice($argv, 1) as $strArg) {
$strHost = trim((string)($arrArgs['host'] ?? '')); $strHost = trim((string)($arrArgs['host'] ?? ''));
$strSource = trim((string)($arrArgs['source'] ?? '')); $strSource = trim((string)($arrArgs['source'] ?? ''));
$strTarget = trim((string)($arrArgs['target'] ?? base_path('data/seo_copy_published'))); $strTarget = trim((string)($arrArgs['target'] ?? base_path('data/seo_copy_published')));
$strScenes = trim((string)($arrArgs['scenes'] ?? ''));
$boolDryRun = !empty($arrArgs['dry-run']); $boolDryRun = !empty($arrArgs['dry-run']);
if ($strHost === '' || $strSource === '') { if ($strHost === '' || $strSource === '') {
@@ -96,7 +99,33 @@ if (!is_dir($strHostSource)) {
exit(2); exit(2);
} }
$arrScenes = ['detail', 'play']; $arrKnownScenes = ['home', 'category_index', 'category_list', 'search', 'rank_index', 'rank_list', 'detail', 'forge', 'play'];
$arrScenes = [];
if ($strScenes !== '') {
foreach (explode(',', $strScenes) as $strScene) {
$strScene = trim((string)$strScene);
if ($strScene === '' || !in_array($strScene, $arrKnownScenes, true)) {
continue;
}
$arrScenes[] = $strScene;
}
} else {
foreach ($arrKnownScenes as $strScene) {
if (is_dir($strHostSource . '/' . $strScene)) {
$arrScenes[] = $strScene;
}
}
}
$arrScenes = array_values(array_unique($arrScenes));
if (empty($arrScenes)) {
fwrite(STDERR, "no valid scenes found for host: {$strHost}\n");
exit(3);
}
$arrSummary = []; $arrSummary = [];
foreach ($arrScenes as $strScene) { foreach ($arrScenes as $strScene) {