作者 刘锟

合并分支 'akun' 到 'master'

update



查看合并请求 !698
... ... @@ -3,20 +3,12 @@
namespace App\Console\Commands\Test;
use App\Helper\Arr;
use App\Models\Collect\CollectTask;
use App\Models\Com\Notify;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateVisit;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Process\Process;
class Temp extends Command
{
... ... @@ -34,55 +26,72 @@ class Temp extends Command
*/
protected $description = '临时脚本';
public function handle(){
ProjectServer::useProject(1515);
public function handle()
{
$notify_model = new Notify();
$products = Product::select(['id','content'])->get();
$domain_list = DomainInfo::where('status', 1)->where('amp_status', 1)->get();
foreach ($products as $product){
$content = $product->content;
$content = str_replace('<h1','<h2', $content);
$content = str_replace('</h1','</h2', $content);
foreach ($domain_list as $domain) {
$project_id = $domain->project_id;
$domain = $domain->domain;
$product->content = $content;
$product->save();
$this->output('项目id:' . $project_id . ',start');
$this->output('productID:'.$product->id.',success');
//获取项目所在服务器
$project_model = new Project();
$project_info = $project_model->read(['id' => $project_id], ['serve_id']);
if (!$project_info) {
$this->output('未查询到项目数据');
}
$this->output('end');
$serve_ip_model = new ServersIp();
$serve_ip_info = $serve_ip_model->read(['id' => $project_info['serve_id']], ['servers_id']);
if (!$serve_ip_info) {
$this->output('未查询到服务器数据');
}
$servers_id = $serve_ip_info['servers_id'];
public function check_cname($domain, $server_info)
{
$checkA = false;
$checkCname = false;
if ($servers_id == ServerConfig::SELF_SITE_ID) {
//自建站服务器:如果项目已经上线,不请求C端接口,数据直接入库
//判断是否已有更新进行中
$data = [
'project_id' => $project_id,
'type' => 3,
'route' => 1,
'server_id' => ServerConfig::SELF_SITE_ID,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data, ['id']);
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $server_info['ip']) !== false;
if ($checkA) {
return $domain;
}
}
if (!$notify) {
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$domain = implode('.', $host_array);
//是否cname
$process = new Process(['nslookup', '-qt=cname', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkCname = (strpos($line, $server_info['domain']) !== false);
if ($checkCname) {
return $domain;
$data['data'] = Arr::a2s(['domain' => $domain, 'url' => [], 'language' => []]);
$data['status'] = Notify::STATUS_INIT;
$notify_model->add($data);
}
} else {
//其他服务器:请求对应C端接口
$c_url = $domain . '/api/update_page/';
$param = [
'project_id' => $project_id,
'type' => 3,
'route' => 1,
'url' => [],
'language' => []
];
http_post($c_url, json_encode($param));
}
$this->output('项目id:' . $project_id . ',end');
}
return false;
}
public function output($msg)
... ...