ProjectReset.php 1.7 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');

        $un = [448, 626, 528, 455, 437, 595, 555, 639, 633, 723, 457, 544, 298, 456, 625];

        $data = UpdateLog::where('project_id', '<=', 723)->where('api_type', 'website_info')->get();

        foreach ($data as $v) {
            $project_id = $v->project_id;
            if (in_array($project_id, $un)) {
                continue;
            }

            $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;
        }
    }
}