Skip to content

Commit 8884ab9

Browse files
authored
Merge pull request #741 from favicode/feature/bulk-update-for-acl-items
Bulk update for ACL items in CLI
2 parents 0584eb0 + a27f696 commit 8884ab9

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

Diff for: Console/Command/SuperUserCommand.php

+22-3
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ private function updateSuIps()
232232

233233
$this->deleteIps($aclItems, $aclId);
234234

235+
$updatedIpList = [];
235236
foreach ($ipList as $ip) {
236237
if ($ip[0] == '!') {
237238
$ip = ltrim($ip, '!');
@@ -254,9 +255,22 @@ private function updateSuIps()
254255
throw new \Exception(__($msg));
255256
}
256257

257-
$this->api->upsertAclItem($aclId, $ipParts[0], 0, $comment, $subnet);
258+
$ipInformation = [
259+
'op' => 'create',
260+
'ip' => $ipParts[0],
261+
'negated' => 0,
262+
'comment' => $comment
263+
];
264+
265+
if ($subnet) {
266+
$ipInformation['subnet'] = $subnet;
267+
}
268+
269+
$updatedIpList[] = $ipInformation;
258270
}
259271

272+
$this->api->bulkAclItems($aclId, $updatedIpList);
273+
260274
$this->sendWebHook('*Admin IPs list has been updated*');
261275

262276
$msg = 'Admin IPs list has been updated';
@@ -307,9 +321,14 @@ private function hasIps($acl)
307321
*/
308322
private function deleteIps($aclItems, $aclId)
309323
{
310-
foreach ($aclItems as $key => $value) {
311-
$this->api->deleteAclItem($aclId, $value->id);
324+
$items = [];
325+
foreach ($aclItems as $item) {
326+
$items[] = [
327+
'op' => 'delete',
328+
'id' => $item->id
329+
];
312330
}
331+
$this->api->bulkAclItems($aclId, $items);
313332
}
314333

315334
/**

Diff for: Model/Api.php

+14
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,20 @@ public function deleteAclItem($aclId, $aclItemId)
14441444
return $result;
14451445
}
14461446

1447+
public function bulkAclItems($aclId, $aclItems)
1448+
{
1449+
$url = $this->_getApiServiceUri() . 'acl/' . rawurlencode($aclId ?? '') . '/entries' ;
1450+
1451+
// per documentation, maximum payload for bulk API is 1000
1452+
$chunkedItems = array_chunk($aclItems, 1000);
1453+
1454+
foreach ($chunkedItems as $items) {
1455+
$payload['entries'] = $items;
1456+
1457+
$this->_fetch($url, Request::METHOD_PATCH, json_encode($payload));
1458+
}
1459+
}
1460+
14471461
/**
14481462
* Update single ACL entry
14491463
*

0 commit comments

Comments
 (0)