diff --git a/pub/api/classes/API_inserve.php b/pub/api/classes/API_inserve.php index e7390ff..e5df3c4 100644 --- a/pub/api/classes/API_inserve.php +++ b/pub/api/classes/API_inserve.php @@ -286,7 +286,7 @@ class API_inserve extends API $sizes = array_column($disks, 'disk_space'); $server_disks_count = array_sum($sizes); } - return $server_disks_count; + return (int)ceil($server_disks_count); } private function buildCountObject(string $serverUuid, string $key): array @@ -294,11 +294,11 @@ class API_inserve extends API return [ 'countSentri' => 0, 'countInserve' => 0, - 'sentriCompanyId' => 0, 'SentriStatus' => 0, 'subscriptionInserveExists' => false, 'subscriptionInserveId' => false, - 'subscriptionInserveCompanyId' => false, + 'subscriptionSentriCompanyName' => false, + 'subscriptionInserveCompanyName' => false, 'subscriptionInserveName' => false, 'subscriptionInserveStatus' => 0, 'md5' => md5($serverUuid . ':' . $key), @@ -338,11 +338,6 @@ class API_inserve extends API public function syncServerLicencesToInserve() { - # Get all the linked companies - $this->getLinkedCompanies(); - $allCompanies = json_decode($this->response, true); - $allCompaniesIds = array_column($allCompanies['matched'], 'id', 'company_id'); - # first get the current subscriptions $this->getCloudSubscriptions(); $allInserveCloudSubscriptions = json_decode($this->response, true); @@ -361,7 +356,7 @@ class API_inserve extends API 'id' => (int)$subscription['id'], 'quantity' => (int)$subscription['quantity'], 'status' => (int)$subscription['status'], - 'cloud_distribution_company_id' => (int)$subscription['cloud_distribution_company_id'], + 'company_name' => $subscription['company_name'], 'name' => $subscription['name'], ]; } @@ -421,19 +416,18 @@ class API_inserve extends API if (isset($inserveLookup[$md5])) { # Subscription already exists in Inserve $item['SentriStatus'] = $sentriStatus; - $item['sentriCompanyId'] = (int)$allCompaniesIds[$row['company_source_id']] ?? 0; $item['subscriptionInserveExists'] = true; $item['subscriptionInserveId'] = $inserveLookup[$item['md5']]['id']; $item['countInserve'] = $inserveLookup[$item['md5']]['quantity']; - $item['subscriptionInserveCompanyId'] = $inserveLookup[$item['md5']]['cloud_distribution_company_id']; + $item['subscriptionSentriCompanyName'] = $row['company_name']; + $item['subscriptionInserveCompanyName'] = $inserveLookup[$item['md5']]['company_name']; $item['subscriptionInserveName'] = $inserveLookup[$item['md5']]['name']; - //$item['subscriptionInserveStatus'] = $inserveLookup[$item['md5']]['status']; + $item['subscriptionInserveStatus'] = $inserveLookup[$item['md5']]['status']; } else { # Subscription does not exist in Inserve - $item['sentriCompanyId'] = (int)$allCompaniesIds[$row['company_source_id']] ?? 0; + $item['subscriptionSentriCompanyName'] = $row['company_name']; $item['subscriptionInserveExists'] = false; $item['subscriptionInserveId'] = false; $item['countInserve'] = 0; - $item['subscriptionInserveCompanyId'] = false; } } unset($item); @@ -487,9 +481,9 @@ class API_inserve extends API "cloud_distribution_id" => $item['md5'], #md5 hash based on the server_uuid from sentri and the subscription name (e.g. server_cpu_count) "cloud_subscription_id" => "sentri-servers", # Mark all the sentri-servers subscriptions so we can filter the subscriptions better "name" => $item['subscriptionSentriName'], + "company_name" => $item['subscriptionSentriCompanyName'], "quantity" => ($row['server_state'] === 'deleted') ? 0 : $item['countSentri'], "cloud_distributor" => $this->cloudDistributor, - "cloud_distribution_company_id" => $item['sentriCompanyId'], # this is generated by inserve "status" => $item['SentriStatus'], "period_type" => 0, # 0 = monthly, 1 = annual, 2 = one time cost "start_date" => date('Y-m-d') @@ -500,26 +494,55 @@ class API_inserve extends API continue; } - // update the subscription if the countInserve and countSentri don't match - // Or when sentriCompanyId and subscriptionInserveCompanyId don't match - if (( - (int)$item['countInserve'] !== (int)$item['countSentri'] || - (int)$item['sentriCompanyId'] !== (int)$item['subscriptionInserveCompanyId'] || - (int)$item['SentriStatus'] !== (int)$item['subscriptionInserveStatus'] || - $item['subscriptionSentriName'] !== $item['subscriptionInserveName'] - ) - && $item['subscriptionInserveExists'] !== false + $countMismatch = + (int)$item['subscriptionInserveStatus'] !== 5 && // Do not update the cound when license status is 5 (removed) in Inserve + (int)$item['countInserve'] !== (int)$item['countSentri']; + $statusMismatch = (int)$item['SentriStatus'] !== (int)$item['subscriptionInserveStatus']; + $nameMismatch = $item['subscriptionSentriName'] !== $item['subscriptionInserveName']; + $companyMismatch = $item['subscriptionSentriCompanyName'] !== $item['subscriptionInserveCompanyName']; + $subscriptionExists = $item['subscriptionInserveExists'] !== false; + + if ( + ($countMismatch || + $statusMismatch || + $nameMismatch || + $companyMismatch) + && $subscriptionExists ) { + $output = false; + if ($output) { + echo "

Update triggered because:

"; + + if ($countMismatch) { + echo "Count differs: Inserve={$item['countInserve']} Sentri={$item['countSentri']}
"; + } + + if ($statusMismatch) { + echo "Status differs: Inserve={$item['subscriptionInserveStatus']} Sentri={$item['SentriStatus']}
"; + } + + if ($nameMismatch) { + echo "Name differs: Inserve='{$item['subscriptionInserveName']}' Sentri='{$item['subscriptionSentriName']}'
"; + } + + if ($companyMismatch) { + echo "Company differs: Inserve='{$item['subscriptionInserveCompanyName']}' Sentri='{$item['subscriptionSentriCompanyName']}'
"; + } + + if (!$subscriptionExists) { + echo "Subscription does not exist.
"; + } + } + $payload = [ "quantity" => ($row['server_state'] === 'deleted') ? 0 : $item['countSentri'], "cloud_distributor" => $this->cloudDistributor, - "cloud_distribution_company_id" => (int)$item['sentriCompanyId'], + "company_name" => $item['subscriptionSentriCompanyName'], "name" => $item['subscriptionSentriName'], "status" => $item['SentriStatus'] ]; $this->updateCloudSubscription($item['subscriptionInserveId'], $payload); - } } } diff --git a/pub/api/v1/sources/inserve/sync-cloud-distributor/index.php b/pub/api/v1/sources/inserve/sync-cloud-distributor/index.php deleted file mode 100644 index eda868b..0000000 --- a/pub/api/v1/sources/inserve/sync-cloud-distributor/index.php +++ /dev/null @@ -1,22 +0,0 @@ -request_method === 'GET' || $API_inserve->request_method === 'POST') { - # This syncs the company id's from Sentri to the Inserve cloudDistributor - # These are the same id's but it Inserve requires it to be synced to the cloudDistributor - $API_inserve->checkPermissions('servers', 'RW'); - $API_inserve->setupConnection(); - - $API_inserve->syncCompaniesFromSentri(); - - - $API_inserve->apiOutput(200, ['success' => 'Sync is done successfully']); -} \ No newline at end of file diff --git a/pub/api/v1/sources/inserve/sync-server-licenses/index.php b/pub/api/v1/sources/inserve/sync-server-licenses/index.php index 2216828..17345d6 100644 --- a/pub/api/v1/sources/inserve/sync-server-licenses/index.php +++ b/pub/api/v1/sources/inserve/sync-server-licenses/index.php @@ -13,7 +13,6 @@ if ($API_inserve->request_method === 'GET' || $API_inserve->request_method === ' $API_inserve->checkPermissions('servers', 'RW'); $API_inserve->setupConnection(); - $API_inserve->syncCompaniesFromSentri(); $API_inserve->syncServerLicencesToInserve(); $API_inserve->apiOutput(200, ['success' => 'Sync is done successfully']); diff --git a/pub/api/v1/sources/inserve/sync-server-subscriptions/index.php b/pub/api/v1/sources/inserve/sync-server-subscriptions/index.php index bb22a37..9ff8a11 100644 --- a/pub/api/v1/sources/inserve/sync-server-subscriptions/index.php +++ b/pub/api/v1/sources/inserve/sync-server-subscriptions/index.php @@ -13,7 +13,6 @@ if ($API_inserve->request_method === 'GET' || $API_inserve->request_method === ' $API_inserve->checkPermissions('servers', 'RW'); $API_inserve->setupConnection(); - $API_inserve->syncCompaniesFromSentri(); $API_inserve->syncServerSubscriptionsToInserve(); $API_inserve->apiOutput(200, ['success' => 'Sync is done successfully']); diff --git a/pub/bin/locales/en.php b/pub/bin/locales/en.php index 41c32d0..4211b98 100644 --- a/pub/bin/locales/en.php +++ b/pub/bin/locales/en.php @@ -300,8 +300,6 @@ return [ 'source_custom_data' => "Custom source data", 'settings' => 'settings', 'source_description' => 'Enter the necessary API details to set up and configure your connection to the Inserve API. This allows Sentri to communicate with Inserve and retrieve the data it needs. ', - 'source_inserve_sync_cloud' => 'Sync cloud distributor companies', - 'source_inserve_sync_cloud_desc' => 'This API call synchronizes active companies in Sentri with the corresponding cloud distributor companies in Inserve. These cloud distributor companies are required to associate Sentri server licenses with companies in Inserve.', 'source_inserve_sync_companies' => 'Sync companies from Inserve to Sentri', 'source_inserve_sync_companies_desc' => 'This API call retrieves all companies from Inserve and creates or updates them in Sentri.', 'source_inserve_sync_licenses' => 'Sync servers licenses', diff --git a/pub/bin/locales/nl.php b/pub/bin/locales/nl.php index 4aaeae9..74ba575 100644 --- a/pub/bin/locales/nl.php +++ b/pub/bin/locales/nl.php @@ -300,8 +300,6 @@ return [ 'source_custom_data' => "Custom bron data", 'settings' => 'insetellingen', 'source_description' => 'Voer de benodigde API-gegevens in om uw verbinding met de Inserve API in te stellen en te configureren. Dit stelt Sentri in staat om te communiceren met Inserve en de benodigde gegevens op te halen.', - 'source_inserve_sync_cloud' => 'Synchroniseer cloud-distributeurbedrijven', - 'source_inserve_sync_cloud_desc' => 'Deze API-call synchroniseert actieve bedrijven in Sentri met de bijbehorende cloud-distributeurbedrijven in Inserve. Deze cloud-distributeurbedrijven zijn nodig om Sentri-serverlicenties te koppelen aan bedrijven in Inserve.', 'source_inserve_sync_companies' => 'Synchroniseer bedrijven van Inserve naar Sentri.', 'source_inserve_sync_companies_desc' => 'Deze API-call haalt alle bedrijven op uit Inserve en maakt ze aan of werkt ze bij in Sentri.', 'source_inserve_sync_licenses' => 'Synchroniseer serverlicenties.', diff --git a/pub/bin/pages/portal-management/sources/pageSourceInserve.php b/pub/bin/pages/portal-management/sources/pageSourceInserve.php index 82dde1d..425698e 100644 --- a/pub/bin/pages/portal-management/sources/pageSourceInserve.php +++ b/pub/bin/pages/portal-management/sources/pageSourceInserve.php @@ -129,25 +129,6 @@ $pageNavbar->outPutNavbar(); - checkPermissions('servers', 'RW', true)) { ?> -
-
-
-
-
- -

-
- -
-
-
- - checkPermissions('servers', 'RW', true)) { ?>