From 2d941960f4ab3c288ca7f925d4fb6eee1d7e29c5 Mon Sep 17 00:00:00 2001 From: Bozhidar Slaveykov Date: Sun, 7 Apr 2024 15:20:17 +0300 Subject: [PATCH] Update PhyreServer.php --- web/app/Models/PhyreServer.php | 44 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/web/app/Models/PhyreServer.php b/web/app/Models/PhyreServer.php index b68af9c..57ed31d 100644 --- a/web/app/Models/PhyreServer.php +++ b/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); - - if (isset($getExternalHostingSubscriptions['data']['HostingSubscriptions'])) { - $externalHostingSubscriptionsIds = []; - foreach ($getExternalHostingSubscriptions['data']['HostingSubscriptions'] as $externalHostingSubscriptions) { - $externalHostingSubscriptionsIds[] = $externalHostingSubscriptions['id']; - } - - // 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(); - } + $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; } - } + $findHostingSubscription->domain = $phyreServerHostingSubscription['domain']; + $findHostingSubscription->save(); + + + } } - 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');