diff --git a/Console/Command/SuperUserCommand.php b/Console/Command/SuperUserCommand.php
index 97e4f161..6d647396 100644
--- a/Console/Command/SuperUserCommand.php
+++ b/Console/Command/SuperUserCommand.php
@@ -227,10 +227,20 @@ private function updateSuIps()
throw new \Exception(__($msg));
}
$aclId = $acl->id;
- $aclItems = $this->api->aclItemsList($aclId);
$comment = 'Added for Maintenance Mode';
- $this->deleteIps($aclItems, $aclId);
+ do {
+
+ // Per default, Fastly returns 100 IP addresses in one call - we fetch until we clear all of them
+ $aclItems = $this->api->aclItemsList($aclId);
+ if (!$aclItems) {
+ break;
+ }
+ $numberOfItems = count($aclItems);
+ $this->output->writeln('' . "Deleting $numberOfItems IP addresses" . '');
+ $this->deleteIps($aclItems, $aclId);
+
+ } while (true);
$updatedIpList = [];
foreach ($ipList as $ip) {
@@ -269,6 +279,8 @@ private function updateSuIps()
$updatedIpList[] = $ipInformation;
}
+ $numberOfUpdatedIp = count($updatedIpList);
+ $this->output->writeln('' . "Updating list with $numberOfUpdatedIp IP addresses" . '');
$this->api->bulkAclItems($aclId, $updatedIpList);
$this->sendWebHook('*Admin IPs list has been updated*');
diff --git a/Model/Api.php b/Model/Api.php
index 04b97d71..c1e2d66e 100644
--- a/Model/Api.php
+++ b/Model/Api.php
@@ -1448,13 +1448,19 @@ public function bulkAclItems($aclId, $aclItems)
{
$url = $this->_getApiServiceUri() . 'acl/' . rawurlencode($aclId ?? '') . '/entries' ;
- // per documentation, maximum payload for bulk API is 1000
- $chunkedItems = array_chunk($aclItems, 1000);
+ // per documentation, the maximum payload for bulk API is 1000, but it can cause connection timeout
+ $chunkedItems = array_chunk($aclItems, 200);
foreach ($chunkedItems as $items) {
$payload['entries'] = $items;
- $this->_fetch($url, Request::METHOD_PATCH, json_encode($payload));
+ $isSuccess = $this->_fetch($url, Request::METHOD_PATCH, json_encode($payload));
+
+ if (!$isSuccess) {
+ $errorMessage = $this->errorMessage ?? '';
+
+ throw new \Exception('Error while doing bulk ACL items update: ' . $errorMessage);
+ }
}
}