Changes in server license creation due to Inserve removing creation of cloud distributor companies.
This commit is contained in:
@@ -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 "<h3>Update triggered because:</h3>";
|
||||
|
||||
if ($countMismatch) {
|
||||
echo "Count differs: Inserve={$item['countInserve']} Sentri={$item['countSentri']}<br>";
|
||||
}
|
||||
|
||||
if ($statusMismatch) {
|
||||
echo "Status differs: Inserve={$item['subscriptionInserveStatus']} Sentri={$item['SentriStatus']}<br>";
|
||||
}
|
||||
|
||||
if ($nameMismatch) {
|
||||
echo "Name differs: Inserve='{$item['subscriptionInserveName']}' Sentri='{$item['subscriptionSentriName']}'<br>";
|
||||
}
|
||||
|
||||
if ($companyMismatch) {
|
||||
echo "Company differs: Inserve='{$item['subscriptionInserveCompanyName']}' Sentri='{$item['subscriptionSentriCompanyName']}'<br>";
|
||||
}
|
||||
|
||||
if (!$subscriptionExists) {
|
||||
echo "Subscription does not exist.<br>";
|
||||
}
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use api\classes\API_inserve;
|
||||
|
||||
session_start();
|
||||
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/api/classes/API_inserve.php";
|
||||
|
||||
|
||||
$API_inserve = new API_inserve();
|
||||
|
||||
if ($API_inserve->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']);
|
||||
}
|
||||
@@ -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']);
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -129,25 +129,6 @@ $pageNavbar->outPutNavbar();
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($GLOBALS['modules_enabled']['servers'] && $API->checkPermissions('servers', 'RW', true)) { ?>
|
||||
<div class="col d-flex">
|
||||
<form method="post" action="/api/v1/sources/inserve/sync-cloud-distributor/" class="w-100">
|
||||
<div class="card h-100 w-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><?php echo __('source_inserve_sync_cloud') ?></h5>
|
||||
<input type="hidden" name="_return" value="/portal-management/sources/inserve">
|
||||
<p class="card-text"><?php echo __('source_inserve_sync_cloud_desc') ?></p>
|
||||
</div>
|
||||
<div class="card-footer mt-auto">
|
||||
<button class="btn btn-primary">
|
||||
<i class="fa-solid fa-arrow-rotate-right"></i> <?php echo __('sync') ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($GLOBALS['modules_enabled']['servers'] && $API->checkPermissions('servers', 'RW', true)) { ?>
|
||||
<div class="col d-flex">
|
||||
<form method="post" action="/api/v1/sources/inserve/sync-server-licenses/" class="w-100">
|
||||
|
||||
Reference in New Issue
Block a user