50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace app\command;
|
||
|
||
use app\cunkebao\service\ContentItemMediaService;
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\Output;
|
||
use think\console\input\Option;
|
||
|
||
/**
|
||
* 内容库素材 · 将 resUrls 归档到 ossUrls(部署前/素材裂图修复)
|
||
*
|
||
* 用法:
|
||
* php think content:oss-backfill --libraryId=230 --limit=100
|
||
* php think content:oss-backfill --itemId=15058
|
||
*/
|
||
class ContentItemOssBackfillCommand extends Command
|
||
{
|
||
protected function configure()
|
||
{
|
||
$this->setName('content:oss-backfill')
|
||
->setDescription('内容库素材图片归档 OSS,修复素材管理裂图')
|
||
->addOption('libraryId', null, Option::VALUE_OPTIONAL, '内容库 ID', 0)
|
||
->addOption('itemId', null, Option::VALUE_OPTIONAL, '单条素材 ID', 0)
|
||
->addOption('limit', null, Option::VALUE_OPTIONAL, '批量条数', 50);
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
$itemId = (int)$input->getOption('itemId');
|
||
if ($itemId > 0) {
|
||
$ok = ContentItemMediaService::backfillItemOss($itemId);
|
||
$output->writeln($ok ? "素材 {$itemId} OSS 回填成功" : "素材 {$itemId} 无需更新或下载失败");
|
||
return $ok ? 0 : 1;
|
||
}
|
||
|
||
$libraryId = (int)$input->getOption('libraryId');
|
||
if ($libraryId <= 0) {
|
||
$output->writeln('请指定 --libraryId 或 --itemId');
|
||
return 1;
|
||
}
|
||
|
||
$limit = max(1, (int)$input->getOption('limit'));
|
||
$count = ContentItemMediaService::backfillLibrary($libraryId, $limit);
|
||
$output->writeln("内容库 {$libraryId}:成功回填 OSS {$count} 条(limit={$limit})");
|
||
return 0;
|
||
}
|
||
}
|