作者 刘锟

update

@@ -43,7 +43,7 @@ class Temp extends Command @@ -43,7 +43,7 @@ class Temp extends Command
43 43
44 public function handle() 44 public function handle()
45 { 45 {
46 - $this->check_no_cname_projects(); 46 + $this->change_cname_projects();
47 } 47 }
48 48
49 /** 49 /**
@@ -600,15 +600,18 @@ class Temp extends Command @@ -600,15 +600,18 @@ class Temp extends Command
600 600
601 601
602 /** 602 /**
603 - * 240服务器上解析cname的项目迁移 603 + * 服务器上解析cname的项目迁移
604 * @author Akun 604 * @author Akun
605 * @date 2025/02/17 14:21 605 * @date 2025/02/17 14:21
606 */ 606 */
607 - public function change_cname_projects_240() 607 + public function change_cname_projects()
608 { 608 {
  609 + $origin_server_id = 20;//原服务器
  610 + $target_server_id = 27;//目标服务器
  611 +
609 $server_ip_model = new ServersIp(); 612 $server_ip_model = new ServersIp();
610 613
611 - $server_ip_ids = $server_ip_model->where('servers_id', 1)->get()->pluck('id')->toArray(); 614 + $server_ip_ids = $server_ip_model->where('servers_id', $origin_server_id)->get()->pluck('id')->toArray();
612 615
613 $project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get(); 616 $project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get();
614 617
@@ -626,60 +629,70 @@ class Temp extends Command @@ -626,60 +629,70 @@ class Temp extends Command
626 $domain = $domain_info['domain']; 629 $domain = $domain_info['domain'];
627 630
628 //迁移主站 631 //迁移主站
629 - $check = dns_get_record($domain, DNS_A);  
630 - $host = $check[0]['host'] ?? '';  
631 - if ($host == 'cname.globalso.com') {  
632 - //获取主站备份证书  
633 - $ssl_info = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $domain)->first();  
634 - if (!$ssl_info) {  
635 - $this->output('项目id:' . $project_id . ' | 未备份主站证书');  
636 - continue;  
637 - } 632 + try {
  633 + $check = dns_get_record($domain, DNS_A);
  634 + $host = $check[0]['host'] ?? '';
  635 + } catch (\Exception $e) {
  636 + $this->output($domain . ' | 获取解析记录失败');
  637 + continue;
  638 + }
638 639
639 - //创建主站建站任务  
640 - $task_info = DomainCreateTask::where('type', 1)->where('server_id', 20)->where('project_id', $project_id)->where('status', '!=', DomainCreateTask::STATUS_SUC)->first();  
641 - if (!$task_info) {  
642 - $task_model = new DomainCreateTask();  
643 - $task_model->type = 1;  
644 - $task_model->server_id = 20;  
645 - $task_model->project_id = $project_id;  
646 - $task_model->domain_id = $domain_id;  
647 - $task_model->certs = json_encode(['key' => $ssl_info->private_key, 'csr' => $ssl_info->private_cert]);  
648 - $task_model->save();  
649 - } 640 + if ($host != 'cname.globalso.com') {
  641 + $this->output($domain . ' | 未解析cname');
  642 + continue;
  643 + }
650 644
651 - //创建主站页面生成任务  
652 - $notify_data = [  
653 - 'project_id' => $project_id,  
654 - 'type' => 1,  
655 - 'route' => 1,  
656 - 'server_id' => 20,  
657 - 'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]  
658 - ];  
659 - $notify = $notify_model->read($notify_data, ['id']); 645 + //获取主站备份证书
  646 + $ssl_info = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $domain)->first();
  647 + if (!$ssl_info) {
  648 + $this->output($domain . ' | 未备份证书');
  649 + continue;
  650 + }
660 651
661 - if (!$notify) {  
662 - $notify_data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);  
663 - $notify_data['status'] = Notify::STATUS_INIT;  
664 - $notify_model->add($notify_data);  
665 - } 652 + //创建主站建站任务
  653 + $task_info = DomainCreateTask::where('type', 1)->where('server_id', $target_server_id)->where('project_id', $project_id)->where('status', '!=', DomainCreateTask::STATUS_SUC)->first();
  654 + if (!$task_info) {
  655 + $task_model = new DomainCreateTask();
  656 + $task_model->type = 1;
  657 + $task_model->server_id = $target_server_id;
  658 + $task_model->project_id = $project_id;
  659 + $task_model->domain_id = $domain_id;
  660 + $task_model->certs = json_encode(['key' => $ssl_info->private_key, 'csr' => $ssl_info->private_cert]);
  661 + $task_model->save();
  662 + }
666 663
667 - //创建主站关键词页面生成任务  
668 - $notify_keyword_data = [  
669 - 'project_id' => $project_id,  
670 - 'type' => 1,  
671 - 'route' => 4,  
672 - 'server_id' => 20,  
673 - 'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]  
674 - ];  
675 - $notify_keyword = $notify_model->read($notify_keyword_data, ['id']); 664 +// //创建主站页面生成任务
  665 +// $notify_data = [
  666 +// 'project_id' => $project_id,
  667 +// 'type' => 1,
  668 +// 'route' => 1,
  669 +// 'server_id' => 20,
  670 +// 'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
  671 +// ];
  672 +// $notify = $notify_model->read($notify_data, ['id']);
  673 +//
  674 +// if (!$notify) {
  675 +// $notify_data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
  676 +// $notify_data['status'] = Notify::STATUS_INIT;
  677 +// $notify_model->add($notify_data);
  678 +// }
  679 +//
  680 +// //创建主站关键词页面生成任务
  681 +// $notify_keyword_data = [
  682 +// 'project_id' => $project_id,
  683 +// 'type' => 1,
  684 +// 'route' => 4,
  685 +// 'server_id' => 20,
  686 +// 'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
  687 +// ];
  688 +// $notify_keyword = $notify_model->read($notify_keyword_data, ['id']);
  689 +//
  690 +// if (!$notify_keyword) {
  691 +// $notify_keyword_data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
  692 +// $notify_keyword_data['status'] = Notify::STATUS_INIT;
  693 +// $notify_model->add($notify_keyword_data);
  694 +// }
676 695
677 - if (!$notify_keyword) {  
678 - $notify_keyword_data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);  
679 - $notify_keyword_data['status'] = Notify::STATUS_INIT;  
680 - $notify_model->add($notify_keyword_data);  
681 - }  
682 - }  
683 696
684 if ($domain_info['amp_status'] == 1) { 697 if ($domain_info['amp_status'] == 1) {
685 //迁移amp站 698 //迁移amp站
@@ -693,44 +706,53 @@ class Temp extends Command @@ -693,44 +706,53 @@ class Temp extends Command
693 } 706 }
694 $amp_domain = implode('.', $host_array); 707 $amp_domain = implode('.', $host_array);
695 708
696 - $check_amp = dns_get_record($amp_domain, DNS_A);  
697 - $host_amp = $check_amp[0]['host'] ?? '';  
698 - if ($host_amp == 'cname.globalso.com') {  
699 - //获取amp站备份证书  
700 - $ssl_info_amp = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $amp_domain)->first();  
701 - if (!$ssl_info_amp) {  
702 - $this->output('项目id:' . $project_id . ' | 未备份amp站证书');  
703 - continue;  
704 - } 709 + try {
  710 + $check_amp = dns_get_record($amp_domain, DNS_A);
  711 + $host_amp = $check_amp[0]['host'] ?? '';
  712 + } catch (\Exception $e) {
  713 + $this->output($amp_domain . ' | 获取解析记录失败');
  714 + continue;
  715 + }
705 716
706 - //创建amp站建站任务  
707 - $task_info_amp = DomainCreateTask::where('type', 2)->where('server_id', 20)->where('project_id', $project_id)->where('status', '!=', DomainCreateTask::STATUS_SUC)->first();  
708 - if (!$task_info_amp) {  
709 - $task_model = new DomainCreateTask();  
710 - $task_model->type = 2;  
711 - $task_model->server_id = 20;  
712 - $task_model->project_id = $project_id;  
713 - $task_model->domain_id = $domain_id;  
714 - $task_model->certs = json_encode(['key' => $ssl_info_amp->private_key, 'csr' => $ssl_info_amp->private_cert]);  
715 - $task_model->save();  
716 - } 717 + if ($host_amp != 'cname.globalso.com') {
  718 + $this->output($amp_domain . ' | 未解析cname');
  719 + continue;
  720 + }
717 721
718 - //创建amp站页面生成任务  
719 - $notify_amp_data = [  
720 - 'project_id' => $project_id,  
721 - 'type' => 3,  
722 - 'route' => 1,  
723 - 'server_id' => 20,  
724 - 'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]  
725 - ];  
726 - $notify_amp = $notify_model->read($notify_amp_data, ['id']);  
727 -  
728 - if (!$notify_amp) {  
729 - $notify_amp_data['data'] = Arr::a2s(['domain' => $amp_domain, 'url' => null, 'language' => []]);  
730 - $notify_amp_data['status'] = Notify::STATUS_INIT;  
731 - $notify_model->add($notify_amp_data);  
732 - } 722 + //获取amp站备份证书
  723 + $ssl_info_amp = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $amp_domain)->first();
  724 + if (!$ssl_info_amp) {
  725 + $this->output($amp_domain . ' | 未备份证书');
  726 + continue;
733 } 727 }
  728 +
  729 + //创建amp站建站任务
  730 + $task_info_amp = DomainCreateTask::where('type', 2)->where('server_id', $target_server_id)->where('project_id', $project_id)->where('status', '!=', DomainCreateTask::STATUS_SUC)->first();
  731 + if (!$task_info_amp) {
  732 + $task_model = new DomainCreateTask();
  733 + $task_model->type = 2;
  734 + $task_model->server_id = $target_server_id;
  735 + $task_model->project_id = $project_id;
  736 + $task_model->domain_id = $domain_id;
  737 + $task_model->certs = json_encode(['key' => $ssl_info_amp->private_key, 'csr' => $ssl_info_amp->private_cert]);
  738 + $task_model->save();
  739 + }
  740 +
  741 +// //创建amp站页面生成任务
  742 +// $notify_amp_data = [
  743 +// 'project_id' => $project_id,
  744 +// 'type' => 3,
  745 +// 'route' => 1,
  746 +// 'server_id' => 20,
  747 +// 'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
  748 +// ];
  749 +// $notify_amp = $notify_model->read($notify_amp_data, ['id']);
  750 +//
  751 +// if (!$notify_amp) {
  752 +// $notify_amp_data['data'] = Arr::a2s(['domain' => $amp_domain, 'url' => null, 'language' => []]);
  753 +// $notify_amp_data['status'] = Notify::STATUS_INIT;
  754 +// $notify_model->add($notify_amp_data);
  755 +// }
734 } 756 }
735 } 757 }
736 } 758 }