作者 刘锟

update

@@ -37,7 +37,54 @@ class Temp extends Command @@ -37,7 +37,54 @@ class Temp extends Command
37 37
38 public function handle() 38 public function handle()
39 { 39 {
40 - $this->change_cname_projects_240(); 40 + $this->check_cname_amp();
  41 + }
  42 +
  43 + public function check_cname_amp()
  44 + {
  45 + $server_ip_model = new ServersIp();
  46 +
  47 + $server_ip_ids = $server_ip_model->where('servers_id', 1)->get()->pluck('id')->toArray();
  48 +
  49 + $project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get();
  50 +
  51 + $domain_model = new DomainInfo();
  52 + $file = fopen(public_path('amp_site.text'), 'a+');
  53 + foreach ($project_list as $value) {
  54 + $project_id = $value->id;
  55 +
  56 + $domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain', 'amp_status']);
  57 + if (!$domain_info) {
  58 + //过滤未绑定正式域名的项目
  59 + continue;
  60 + }
  61 + $domain = $domain_info['domain'];
  62 +
  63 + if ($domain_info['amp_status'] == 1) {
  64 + //迁移amp站
  65 + $domain_array = parse_url($domain);
  66 + $host = $domain_array['host'] ?? $domain_array['path'];
  67 + $host_array = explode('.', $host);
  68 + if (count($host_array) <= 2) {
  69 + array_unshift($host_array, 'm');
  70 + } else {
  71 + $host_array[0] = 'm';
  72 + }
  73 + $amp_domain = implode('.', $host_array);
  74 +
  75 + $check_amp = dns_get_record($amp_domain, DNS_A);
  76 + $host_amp = $check_amp[0]['host'] ?? '';
  77 + if ($host_amp == 'cname.globalso.com') {
  78 + //获取amp站备份证书
  79 + $str = "rsync -avuP --progress /mnt/datadisk0/c-globalso/public/" . $amp_domain . " -e 'ssh -p 49873' root@38.145.218.9:/www/wwwroot/c-globalso/public/" . PHP_EOL;
  80 + fwrite($file, $str);
  81 + }
  82 + }
  83 + }
  84 +
  85 + fclose($file);
  86 +
  87 + $this->output('success');
41 } 88 }
42 89
43 /** 90 /**