From c48af8fac0fcc524bb2949e970e72ee714d60cf0 Mon Sep 17 00:00:00 2001 From: Jim Safley Date: Thu, 21 Nov 2024 19:11:25 -0500 Subject: [PATCH 1/3] Add setting for batch chunk size (#2237) --- application/src/Form/SettingForm.php | 14 ++++++++++++++ application/src/Job/BatchDelete.php | 3 ++- application/src/Job/BatchUpdate.php | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/application/src/Form/SettingForm.php b/application/src/Form/SettingForm.php index 659f97b899..fc4d7bf0c0 100644 --- a/application/src/Form/SettingForm.php +++ b/application/src/Form/SettingForm.php @@ -331,6 +331,20 @@ public function init() ], ]); + $this->add([ + 'name' => 'batch_chunk_size', + 'type' => 'number', + 'options' => [ + 'element_group' => 'editing', + 'label' => 'Batch chunk size', // @translate + 'info' => 'Enter the size of each chunk of resources when batch editing and deleting.' + ], + 'attributes' => [ + 'id' => 'batch_chunk_size', + 'value' => $this->settings->get('batch_chunk_size', 100), + ], + ]); + // Search element group $this->add([ diff --git a/application/src/Job/BatchDelete.php b/application/src/Job/BatchDelete.php index 7e6b712939..fbd76485a1 100644 --- a/application/src/Job/BatchDelete.php +++ b/application/src/Job/BatchDelete.php @@ -11,7 +11,8 @@ public function perform() $response = $api->search($resource, $query, ['returnScalar' => 'id']); // Batch delete the resources in chunks. - foreach (array_chunk($response->getContent(), 100) as $idsChunk) { + $batchChunkSize = $settings->get('batch_chunk_size', 100); + foreach (array_chunk($response->getContent(), $batchChunkSize) as $idsChunk) { if ($this->shouldStop()) { return; } diff --git a/application/src/Job/BatchUpdate.php b/application/src/Job/BatchUpdate.php index 33741aeb0c..6e61357f4d 100644 --- a/application/src/Job/BatchUpdate.php +++ b/application/src/Job/BatchUpdate.php @@ -6,6 +6,7 @@ class BatchUpdate extends AbstractJob public function perform() { $api = $this->getServiceLocator()->get('Omeka\ApiManager'); + $settings = $this->getServiceLocator()->get('Omeka\Settings'); $resource = $this->getArg('resource'); $query = $this->getArg('query', []); @@ -16,7 +17,8 @@ public function perform() $response = $api->search($resource, $query, ['returnScalar' => 'id']); // Batch update the resources in chunks. - foreach (array_chunk($response->getContent(), 100) as $idsChunk) { + $batchChunkSize = $settings->get('batch_chunk_size', 100); + foreach (array_chunk($response->getContent(), $batchChunkSize) as $idsChunk) { if ($this->shouldStop()) { return; } From c51788f55ab5f4fd7d31675aef3138986a52c23c Mon Sep 17 00:00:00 2001 From: Jim Safley Date: Fri, 22 Nov 2024 08:33:01 -0500 Subject: [PATCH 2/3] Fix cs, translate --- application/src/Form/SettingForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/Form/SettingForm.php b/application/src/Form/SettingForm.php index fc4d7bf0c0..c28a1ec142 100644 --- a/application/src/Form/SettingForm.php +++ b/application/src/Form/SettingForm.php @@ -337,7 +337,7 @@ public function init() 'options' => [ 'element_group' => 'editing', 'label' => 'Batch chunk size', // @translate - 'info' => 'Enter the size of each chunk of resources when batch editing and deleting.' + 'info' => 'Enter the size of each chunk of resources when batch editing and deleting.', // @translate ], 'attributes' => [ 'id' => 'batch_chunk_size', From 4e6c6945e7a0fb3804b28cb7772fb0143f34a134 Mon Sep 17 00:00:00 2001 From: Jim Safley Date: Mon, 25 Nov 2024 13:59:22 -0500 Subject: [PATCH 3/3] Add needed settings service --- application/src/Job/BatchDelete.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/src/Job/BatchDelete.php b/application/src/Job/BatchDelete.php index fbd76485a1..eafc40e6b7 100644 --- a/application/src/Job/BatchDelete.php +++ b/application/src/Job/BatchDelete.php @@ -6,6 +6,7 @@ class BatchDelete extends AbstractJob public function perform() { $api = $this->getServiceLocator()->get('Omeka\ApiManager'); + $settings = $this->getServiceLocator()->get('Omeka\Settings'); $resource = $this->getArg('resource'); $query = $this->getArg('query', []); $response = $api->search($resource, $query, ['returnScalar' => 'id']);