Bozhidar Slaveykov 1 год назад
Родитель
Сommit
2d941960f4
1 измененных файлов с 23 добавлено и 19 удалено
  1. 23 19
      web/app/Models/PhyreServer.php

+ 23 - 19
web/app/Models/PhyreServer.php

@@ -93,28 +93,32 @@ class PhyreServer extends Model
                 $centralServerHostingSubscriptionsExternalIds[] = $customer->external_id;
             }
         }
-      //  $getPhyreServerHostingSubscriptions = $phyreApiSDK->getHostingSubscriptions();
+        $getPhyreServerHostingSubscriptions = $phyreApiSDK->getHostingSubscriptions();
+        if (isset($getPhyreServerHostingSubscriptions['data']['HostingSubscriptions'])) {
+            foreach ($getPhyreServerHostingSubscriptions['data']['HostingSubscriptions'] as $phyreServerHostingSubscription) {
 
-        dd($centralServerHostingSubscriptionsExternalIds);
+                $findHostingSubscription = HostingSubscription::where('external_id', $phyreServerHostingSubscription['id'])
+                    ->where('phyre_server_id', $this->id)
+                    ->first();
+                if (!$findHostingSubscription) {
+                    $findHostingSubscription = new HostingSubscription();
+                    $findHostingSubscription->phyre_server_id = $this->id;
+                    $findHostingSubscription->external_id = $phyreServerHostingSubscription['id'];
+                }
+                
+                $findHostingSubscriptionCustomer = Customer::where('external_id', $phyreServerHostingSubscription['customer_id'])
+                    ->where('phyre_server_id', $this->id)
+                    ->first();
+                if ($findHostingSubscriptionCustomer) {
+                    $findHostingSubscription->customer_id = $findHostingSubscriptionCustomer->id;
+                }
 
-        if (isset($getExternalHostingSubscriptions['data']['HostingSubscriptions'])) {
-            $externalHostingSubscriptionsIds = [];
-            foreach ($getExternalHostingSubscriptions['data']['HostingSubscriptions'] as $externalHostingSubscriptions) {
-                $externalHostingSubscriptionsIds[] = $externalHostingSubscriptions['id'];
-            }
+                $findHostingSubscription->domain = $phyreServerHostingSubscription['domain'];
+                $findHostingSubscription->save();
 
-            // Delete hosting subscriptions to main server that are not in external server
-            foreach ($customerExternalIds as $customerExternalId) {
-                if (!in_array($customerExternalId, $externalCustomerIds)) {
-                    $getCustomer = Customer::where('external_id', $customerExternalId)->first();
-                    if ($getCustomer) {
-                        $getCustomer->delete();
-                    }
-                }
-            }
 
+            }
         }
-        dd($externalHostingSubscriptionsIds);
 
 
 //        // Sync Hosting Plans
@@ -131,8 +135,8 @@ class PhyreServer extends Model
         $ssh = new SSH2($this->ip);
         if ($ssh->login($this->username, $this->password)) {
 
-            $output = $ssh->exec('cd /usr/local/phyre/web && /usr/local/phyre/php/bin/php artisan apache:ping-websites-with-curl');
-            dd($output);
+//            $output = $ssh->exec('cd /usr/local/phyre/web && /usr/local/phyre/php/bin/php artisan apache:ping-websites-with-curl');
+//            dd($output);
 
             $output = '';
             $output .= $ssh->exec('wget https://raw.githubusercontent.com/CloudVisionApps/PhyrePanel/main/update/update-web-panel.sh -O /usr/local/phyre/update/update-web-panel.sh');