ProjectReset.php 1.3 KB
<?php

namespace App\Console\Commands\Update;

use App\Models\Com\UpdateLog;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class ProjectReset extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'project_reset {project_id}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '项目采集重置';


    public function handle()
    {
        $project_id = $this->argument('project_id');

        $project = ProjectServer::useProject($project_id);
        if ($project) {
            try {
                DB::connection('custom_mysql')->statement("DELETE FROM `gl_collect_source`  WHERE `origin` LIKE '%.css%' OR `origin` LIKE '%.js%'");
                DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0");
            } catch (\Exception $e) {
                echo $project_id . ',重置失败' . PHP_EOL;
            }
        }
        //关闭数据库
        DB::disconnect('custom_mysql');

        UpdateLog::where('project_id', $project_id)->whereIn('api_type', ['post', 'page', 'news', 'blog'])->update(['collect_status' => 0]);

        echo $project_id . ',重置成功' . PHP_EOL;
    }
}