<?php
/**
 * Created by PhpStorm.
 * User: zhl
 * Date: 2023/2/7
 * Time: 17:58
 */
namespace App\Console\Commands\Test;


use App\Helper\Arr;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory;
use App\Models\Com\KeywordVideoTask;
use App\Models\Com\KeywordVideoTaskLog;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
use App\Models\File\File;
use App\Models\File\File as FileModel;
use App\Models\File\Image;
use App\Models\File\Image as ImageModel;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\DeployOptimize;
use App\Models\Project\MinorLanguages;
use App\Models\Project\Project;
use App\Models\Purchaser\PurchaserInfo;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BCustomTemplate;
use App\Models\Template\BTemplateCom;
use App\Services\AmazonS3Service;
use App\Services\ProjectServer;
use App\Utils\EncryptUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;


class Demo extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'demo';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'demo';

    public function handle(){
        $projectModel = new Project();
        $list = $projectModel->list(['is_upgrade'=>1]);
        $data = [];
        foreach ($list as $v){
            echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
            ProjectServer::useProject($v['id']);
            $this->init404Page($v['id']);
            DB::disconnect('custom_mysql');
        }
        echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
    }
    public static function init404Page($project_id){
        $time = date('Y-m-d H:i:s');
        $info = DB::connection('custom_mysql')->table('gl_web_custom_template')->where('url',404)->first();
        if(empty($info)) {
            $data = [
                'project_id' => $project_id,
                'name' => BCustomTemplate::NOT_FOUND_PAGE_URL,
                'status' => 1,
                'url' => BCustomTemplate::NOT_FOUND_PAGE_URL,
                'html' => self::$main404Html,
                'html_style' => '<style id="globalsojs-styles"></style>',
                'title' => '404-Page not found',
                'description' => 'Sorry. The page has either moved or cannot be found.',
                'created_at' => $time, 'updated_at' => $time];
            $id = DB::connection('custom_mysql')->table('gl_web_custom_template')->insertGetId($data);
            //路由
            $info = DB::connection('custom_mysql')->table('gl_route_map')->first();
            if(empty($info)) {
                $data = ['project_id' => $project_id, 'source' => RouteMap::SOURCE_PAGE, 'source_id' => $id, 'route' => BCustomTemplate::NOT_FOUND_PAGE_URL, 'created_at' => $time, 'updated_at' => $time];
                DB::connection('custom_mysql')->table('gl_route_map')->insert($data);
            }
        }
    }
}