This commit is contained in:
Bozhidar Slaveykov 2024-04-06 20:40:03 +03:00
parent d2efad470e
commit 5a4eb09c55
2 changed files with 36 additions and 5 deletions

View file

@ -18,6 +18,12 @@ class PhyreApiSDK
$this->username = $username;
}
public function getCustomers()
{
$response = $this->sendRequest('customers', [], 'GET');
return $response;
}
public function createCustomer($data)
{
$response = $this->sendRequest('customers', $data, 'POST');

View file

@ -31,13 +31,38 @@ class PhyreServer extends Model
public function syncResources()
{
// Sync Hosting Plans
$getHostingPlans = HostingPlan::all();
if ($getHostingPlans->count() > 0) {
foreach ($getHostingPlans as $hostingPlan) {
// Sync customers
$customerExternalIds = [];
$getCustomers = Customer::where('phyre_server_id', $this->id)->get();
if ($getCustomers->count() > 0) {
foreach ($getCustomers as $customer) {
$customerExternalIds[] = $customer->external_id;
}
}
$phyreApiSDK = new PhyreApiSDK($this->ip, 8443, $this->username, $this->password);
$getExternalCustomers = $phyreApiSDK->getCustomers();
if (isset($getExternalCustomers['data']['customers'])) {
$externalCustomerIds = [];
foreach ($getExternalCustomers['data']['customers'] as $externalCustomer) {
$externalCustomerIds[] = $externalCustomer['id'];
}
foreach ($customerExternalIds as $customerExternalId) {
if (!in_array($customerExternalId, $externalCustomerIds)) {
$getCustomer = Customer::where('external_id', $customerExternalId)->first();
if ($getCustomer) {
$getCustomer->delete();
}
}
}
}
// // Sync Hosting Plans
// $getHostingPlans = HostingPlan::all();
// if ($getHostingPlans->count() > 0) {
// foreach ($getHostingPlans as $hostingPlan) {
//
// }
// }
}
public function healthCheck()