| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Command\Init;
- use App\Model\UserModel;
- use App\Model\VideoModel;
- use App\Repositories\CommentRepository;
- use App\Repositories\Service\CommonService;
- use App\Repositories\Utils\MediaCenterRepository;
- use App\Repositories\Utils\RandomUserInfoRepository;
- use Carbon\Carbon;
- use Hyperf\Command\Command as HyperfCommand;
- use Hyperf\Guzzle\ClientFactory;
- use Psr\Container\ContainerInterface;
- use Hyperf\Command\Annotation\Command;
- /**
- * @Command
- */
- #[Command]
- class SyncVideoToMediaCenter extends HyperfCommand
- {
- /**
- * 执行的命令行
- *
- * @var string
- */
- protected $name = 'init:sync_video_to_media_center';
- /**
- * @var ContainerInterface
- */
- protected $container;
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
- parent::__construct($this->name);
- }
- public function configure()
- {
- parent::configure();
- $this->setDescription('同步所有视频信息到媒资库.');
- $this->addUsage(" 无参数");
- }
- public function handle()
- {
- $startDateObj = Carbon::now();
- $totalNum = 0;
- $appAliasName = env('STATIC_DIR_NAME', 'doukui');
- $columns = ['id', 'cover', 'title', 'tags', 'file_hash', 'deleted_at', 'uid'];
- $mediaCenterRepo = make(MediaCenterRepository::class);
- VideoModel::query()->whereNull('deleted_at')->select($columns)->orderBy('id', 'desc')->chunk(100, function ($items) use (&$totalNum, $appAliasName, $mediaCenterRepo) {
- $postData = [
- 'force_sync_state' => 'no',
- 'items' => [],
- ];
- foreach ($items as $v) {
- $postData['items'][] = [
- 'app_alias_name' => $appAliasName,
- 'app_module_name' => 'video',
- 'app_item_code' => $v->id,
- 'file_hash' => $v->file_hash,
- 'cover' => $v->cover,
- 'title' => $v->title,
- 'tags' => !empty($v->tags) ? $v->tags : '',
- ];
- $totalNum++;
- }
- // 开始阻塞同步到媒资库.
- $mediaCenterRepo->syncAppVideoToMediaCenter($postData);
- unset($postData);
- });
- $endDateObj = Carbon::now();
- $diffSeconds = abs($endDateObj->diffInSeconds($startDateObj));
- $this->comment(sprintf('[%s]完成同步视频到媒资库, 总计:%s个视频, 耗时:%s秒', $endDateObj->toDateTimeString(), strval($totalNum), strval($diffSeconds)));
- }
- }
|