新增 config:sync-media 与 sync_db_config_tencent,部署流程接入 2f 步骤;修复 workbench/内容库迁移 SQL 在生产库可重复执行。 Co-authored-by: Cursor <cursoragent@cursor.com>
82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
||
|
||
namespace app\command;
|
||
|
||
use app\common\service\MediaOssArchiveService;
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\Output;
|
||
use think\Db;
|
||
|
||
/**
|
||
* 将场景目录等配置中的外链媒体同步到存客宝 OSS(res.quwanzhi.com)
|
||
*/
|
||
class SyncConfigMediaCommand extends Command
|
||
{
|
||
protected function configure()
|
||
{
|
||
$this->setName('config:sync-media')
|
||
->setDescription('同步 plan_scene 等配置表外链图片/视频到 OSS');
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
$updated = 0;
|
||
$skipped = 0;
|
||
$failed = 0;
|
||
|
||
$rows = Db::name('plan_scene')
|
||
->where('image', '<>', '')
|
||
->whereNotNull('image')
|
||
->field('id,name,image')
|
||
->select();
|
||
|
||
foreach ($rows as $row) {
|
||
$url = trim((string)($row['image'] ?? ''));
|
||
if ($url === '' || MediaOssArchiveService::isOwnOssUrl($url)) {
|
||
$skipped++;
|
||
continue;
|
||
}
|
||
|
||
$result = MediaOssArchiveService::archiveRemoteUrl(
|
||
$url,
|
||
'plan_scene',
|
||
'cover',
|
||
(string)$row['id']
|
||
);
|
||
|
||
if (empty($result['success'])) {
|
||
$failed++;
|
||
$output->writeln(sprintf(
|
||
'FAIL scene #%d %s: %s',
|
||
$row['id'],
|
||
$row['name'] ?? '',
|
||
$result['error'] ?? 'unknown'
|
||
));
|
||
continue;
|
||
}
|
||
|
||
$newUrl = (string)($result['url'] ?? '');
|
||
if ($newUrl !== '' && $newUrl !== $url) {
|
||
Db::name('plan_scene')->where('id', $row['id'])->update([
|
||
'image' => $newUrl,
|
||
'updateTime' => time(),
|
||
]);
|
||
$updated++;
|
||
$output->writeln(sprintf('OK scene #%d -> %s', $row['id'], $newUrl));
|
||
} else {
|
||
$skipped++;
|
||
}
|
||
}
|
||
|
||
$output->writeln(sprintf(
|
||
'plan_scene 媒体同步完成:更新 %d,跳过 %d,失败 %d',
|
||
$updated,
|
||
$skipped,
|
||
$failed
|
||
));
|
||
|
||
return $failed > 0 ? 1 : 0;
|
||
}
|
||
}
|