Update PhyreServer.php

This commit is contained in:
Bozhidar Slaveykov 2024-04-07 15:20:17 +03:00
parent e26c1a0aad
commit 2d941960f4

View file

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