Skip to content

Commit 43e99d5

Browse files
handle string/array for SLM indices
1 parent 18b6d1a commit 43e99d5

File tree

5 files changed

+20
-27
lines changed

5 files changed

+20
-27
lines changed

src/Form/Type/ElasticsearchSlmPolicyType.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
102102
]);
103103
break;
104104
case 'indices':
105-
$builder->add('indices', ChoiceType::class, [
106-
'multiple' => true,
107-
'choices' => $options['indices'],
108-
'choice_label' => static function ($choice, $key, $value) use ($options) {
109-
return $options['indices'][$key];
110-
},
111-
'choice_translation_domain' => false,
105+
$builder->add('indices', TextType::class, [
112106
'label' => 'indices',
113107
'required' => false,
114108
'attr' => [

src/Model/ElasticsearchSlmPolicyModel.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ class ElasticsearchSlmPolicyModel extends AbstractAppModel
1414

1515
private ?string $repository = null;
1616

17-
/**
18-
* @var array<mixed>|null $indices
19-
*/
20-
private ?array $indices = null;
17+
private ?string $indices = null;
2118

2219
private ?string $schedule = null;
2320

@@ -97,24 +94,23 @@ public function setRepository(?string $repository): self
9794
return $this;
9895
}
9996

100-
/**
101-
* @return array<mixed>|null
102-
*/
103-
public function getIndices(): ?array
97+
public function getIndices(): ?string
10498
{
10599
return $this->indices;
106100
}
107101

108-
/**
109-
* @param array<mixed>|null $indices
110-
*/
111-
public function setIndices(?array $indices): self
102+
public function setIndices(?string $indices): self
112103
{
113104
$this->indices = $indices;
114105

115106
return $this;
116107
}
117108

109+
public function getIndicesToArray(): array
110+
{
111+
return explode(',', $this->indices);
112+
}
113+
118114
public function getSchedule(): ?string
119115
{
120116
return $this->schedule;
@@ -346,7 +342,11 @@ public function convert(?array $policy): self
346342
}
347343

348344
if (true === isset($policy['policy']['config']['indices'])) {
349-
$this->setIndices($policy['policy']['config']['indices']);
345+
$indices = $policy['policy']['config']['indices'];
346+
if (true === is_array($indices)) {
347+
$indices = implode(',', $indices);
348+
}
349+
$this->setIndices($indices);
350350
}
351351

352352
if (true === isset($policy['policy']['retention']['expire_after'])) {
@@ -412,7 +412,7 @@ public function getJson(): array
412412
];
413413

414414
if ($this->getIndices()) {
415-
$json['config']['indices'] = $this->getIndices();
415+
$json['config']['indices'] = $this->getIndicesToArray();
416416
} else {
417417
$json['config']['indices'] = ['*'];
418418
}

templates/Modules/slm/slm_read.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
{{ appImport.dashboardKpi({'title': 'include_global_state'|trans, 'badge': {'title': ('boolean.' ~ policy.includeGlobalState)|trans, 'context': policy.includeGlobalState}}) }}
9191
</div>
9292

93-
{% if 0 < policy.indices|length %}
93+
{% if 0 < policy.indicesToArray|length %}
9494
{% embed 'Embed/table_embed.html.twig' %}
9595
{% import 'Import/app_import.html.twig' as appImport %}
9696

@@ -101,7 +101,7 @@
101101
{% endblock %}
102102

103103
{% block tbody %}
104-
{% for index in policy.indices %}
104+
{% for index in policy.indicesToArray %}
105105
<tr>
106106
<td>{{ index }}</td>
107107
</tr>

tests/Model/ElasticsearchSlmPolicyModelTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function test(): void
2020
$policy->setPartial(true);
2121
$policy->setIncludeGlobalState(true);
2222

23-
$policy->setIndices(['indices']);
23+
$policy->setIndices('indices');
2424
$policy->setLastSuccess(['lastsuccess']);
2525
$policy->setLastFailure(['lastfailure']);
2626
$policy->setStats(['stats']);
@@ -56,8 +56,7 @@ public function test(): void
5656
$this->assertEquals($policy->getIncludeGlobalState(), true);
5757
$this->assertIsBool($policy->getIncludeGlobalState());
5858

59-
$this->assertEquals($policy->getIndices(), ['indices']);
60-
$this->assertIsArray($policy->getIndices());
59+
$this->assertEquals($policy->getIndices(), 'indices');
6160

6261
$this->assertEquals($policy->getLastSuccess(), ['lastsuccess']);
6362
$this->assertIsArray($policy->getLastSuccess());

translations/messages.en.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ help_form:
339339
name: "A unique identifier for this policy."
340340
snapshot_name: "The name for the snapshots. A unique identifier is automatically added to each name. Supports <a class=\"text-light\" rel=\"noreferrer\" target=\"_blank\" href=\"https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html#date-math-index-names\">date math expressions</a>."
341341
repository: "The repository where you want to store the snapshots."
342-
indices: "Indices to back up."
342+
indices: "Indices to back up (separated by commas)."
343343
schedule: "The frequency at which to take the snapshots. Use <a class=\"text-light\" rel=\"noreferrer\" target=\"_blank\" href=\"https://www.elastic.co/guide/en/elasticsearch/reference/current/trigger-schedule.html#schedule-cron\">cron expression</a>."
344344
expire_after: "The time to wait before deleting snapshots."
345345
min_count: "The minimum number of snapshots to store in your cluster."

0 commit comments

Comments
 (0)