From d59328cefbb8495158468e64df9e2b805aae26fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Dion?= Date: Sat, 20 Nov 2021 10:17:23 +0100 Subject: [PATCH 1/3] add method for json when array --- .../ElasticsearchIndexController.php | 12 +-- .../MappingsSettingsAliasesSubscriber.php | 64 ------------- src/Form/EventListener/MetadataSubscriber.php | 42 --------- .../ElasticsearchComponentTemplateType.php | 29 +++--- src/Form/Type/ElasticsearchIlmPolicyType.php | 72 +++------------ .../ElasticsearchIndexTemplateLegacyType.php | 21 ++--- .../Type/ElasticsearchIndexTemplateType.php | 29 +++--- src/Form/Type/ElasticsearchIndexType.php | 15 ++- src/Form/Type/ElasticsearchPipelineType.php | 38 ++------ src/Form/Type/ElasticsearchRoleType.php | 47 ++-------- src/Form/Type/ElasticsearchUserType.php | 9 +- .../ElasticsearchComponentTemplateModel.php | 38 ++++++-- src/Model/ElasticsearchIlmPolicyModel.php | 92 +++++++++++++++---- src/Model/ElasticsearchIndexModel.php | 2 + .../ElasticsearchIndexTemplateLegacyModel.php | 12 +-- src/Model/ElasticsearchIndexTemplateModel.php | 37 +++++--- src/Model/ElasticsearchPipelineModel.php | 44 +++++++-- src/Model/ElasticsearchRoleModel.php | 51 ++++++++-- src/Model/ElasticsearchSnapshotModel.php | 17 +++- src/Model/ElasticsearchUserModel.php | 1 + .../ElasticsearchRoleUserModelTrait.php | 18 +++- .../MappingsSettingsAliasesModelTrait.php | 54 +++++++++-- .../ElasticsearchIlmControllerTest.php | 2 +- .../ElasticsearchIndexControllerTest.php | 4 +- .../ElasticsearchPipelineControllerTest.php | 4 +- ...lasticsearchComponentTemplateModelTest.php | 8 +- .../Model/ElasticsearchIlmPolicyModelTest.php | 9 +- tests/Model/ElasticsearchIndexModelTest.php | 6 +- ...sticsearchIndexTemplateLegacyModelTest.php | 6 +- .../ElasticsearchIndexTemplateModelTest.php | 8 +- .../Model/ElasticsearchPipelineModelTest.php | 4 +- tests/Model/ElasticsearchRoleModelTest.php | 2 + 32 files changed, 399 insertions(+), 398 deletions(-) delete mode 100644 src/Form/EventListener/MappingsSettingsAliasesSubscriber.php delete mode 100644 src/Form/EventListener/MetadataSubscriber.php diff --git a/src/Controller/ElasticsearchIndexController.php b/src/Controller/ElasticsearchIndexController.php index 16a56ec6..0a4a47d9 100644 --- a/src/Controller/ElasticsearchIndexController.php +++ b/src/Controller/ElasticsearchIndexController.php @@ -341,11 +341,11 @@ public function create(Request $request): Response if ($form->isSubmitted() && $form->isValid()) { try { $json = []; - if ($index->getSettings()) { - $json['settings'] = $index->getSettings(); + if ($index->getSettingsJson()) { + $json['settings'] = json_decode($index->getSettingsJson(), true); } - if ($index->getMappings()) { - $json['mappings'] = $index->getMappings(); + if ($index->getMappingsJson()) { + $json['mappings'] = json_decode($index->getMappingsJson(), true); } $callRequest = new CallRequestModel(); $callRequest->setMethod('PUT'); @@ -406,8 +406,8 @@ public function update(Request $request, string $index): Response if ($form->isSubmitted() && $form->isValid()) { try { - if ($index->getMappings()) { - $json = $index->getMappings(); + if ($index->getMappingsJson()) { + $json = json_decode($index->getMappingsJson(), true); $callRequest = new CallRequestModel(); $callRequest->setMethod('PUT'); $callRequest->setPath('/'.$index->getName().'/_mapping'); diff --git a/src/Form/EventListener/MappingsSettingsAliasesSubscriber.php b/src/Form/EventListener/MappingsSettingsAliasesSubscriber.php deleted file mode 100644 index 6592762a..00000000 --- a/src/Form/EventListener/MappingsSettingsAliasesSubscriber.php +++ /dev/null @@ -1,64 +0,0 @@ - 'postSetData', - FormEvents::POST_SUBMIT => 'postSubmit', - ]; - } - - public function postSetData(FormEvent $event): void - { - $form = $event->getForm(); - - if ($form->has('mappings') && $form->get('mappings')->getData()) { - $fieldOptions = $form->get('mappings')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('mappings')->getData(), JSON_PRETTY_PRINT); - $form->add('mappings', TextareaType::class, $fieldOptions); - } - - if ($form->has('settings') && $form->get('settings')->getData()) { - $fieldOptions = $form->get('settings')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('settings')->getData(), JSON_PRETTY_PRINT); - $form->add('settings', TextareaType::class, $fieldOptions); - } - - if ($form->has('aliases') && $form->get('aliases')->getData()) { - $fieldOptions = $form->get('aliases')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('aliases')->getData(), JSON_PRETTY_PRINT); - $form->add('aliases', TextareaType::class, $fieldOptions); - } - } - - public function postSubmit(FormEvent $event): void - { - $form = $event->getForm(); - $data = $event->getData(); - - if ($form->has('mappings') && $form->get('mappings')->getData()) { - $data->setMappings(json_decode($form->get('mappings')->getData(), true)); - $event->setData($data); - } - - if ($form->has('settings') && $form->get('settings')->getData()) { - $data->setSettings(json_decode($form->get('settings')->getData(), true)); - $event->setData($data); - } - - if ($form->has('aliases') && $form->get('aliases')->getData()) { - $data->setAliases(json_decode($form->get('aliases')->getData(), true)); - $event->setData($data); - } - } -} diff --git a/src/Form/EventListener/MetadataSubscriber.php b/src/Form/EventListener/MetadataSubscriber.php deleted file mode 100644 index 94adb33f..00000000 --- a/src/Form/EventListener/MetadataSubscriber.php +++ /dev/null @@ -1,42 +0,0 @@ - 'postSetData', - FormEvents::POST_SUBMIT => 'postSubmit', - ]; - } - - public function postSetData(FormEvent $event): void - { - $form = $event->getForm(); - - if ($form->has('metadata') && $form->get('metadata')->getData()) { - $fieldOptions = $form->get('metadata')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('metadata')->getData(), JSON_PRETTY_PRINT); - $form->add('metadata', TextareaType::class, $fieldOptions); - } - } - - public function postSubmit(FormEvent $event): void - { - $form = $event->getForm(); - $data = $event->getData(); - - if ($form->has('metadata') && $form->get('metadata')->getData()) { - $data->setMetadata(json_decode($form->get('metadata')->getData(), true)); - $event->setData($data); - } - } -} diff --git a/src/Form/Type/ElasticsearchComponentTemplateType.php b/src/Form/Type/ElasticsearchComponentTemplateType.php index d4f1a588..d5f070c4 100644 --- a/src/Form/Type/ElasticsearchComponentTemplateType.php +++ b/src/Form/Type/ElasticsearchComponentTemplateType.php @@ -3,8 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MappingsSettingsAliasesSubscriber; -use App\Form\EventListener\MetadataSubscriber; use App\Manager\ElasticsearchComponentTemplateManager; use App\Model\CallRequestModel; use App\Model\ElasticsearchComponentTemplateModel; @@ -43,10 +41,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $fields[] = 'name'; } $fields[] = 'version'; - $fields[] = 'settings'; - $fields[] = 'mappings'; - $fields[] = 'aliases'; - $fields[] = 'metadata'; + $fields[] = 'settings_json'; + $fields[] = 'mappings_json'; + $fields[] = 'aliases_json'; + $fields[] = 'metadata_json'; foreach ($fields as $field) { switch ($field) { @@ -76,8 +74,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'settings': - $builder->add('settings', TextareaType::class, [ + case 'settings_json': + $builder->add('settings_json', TextareaType::class, [ 'label' => 'settings', 'required' => false, 'constraints' => [ @@ -87,8 +85,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'mappings': - $builder->add('mappings', TextareaType::class, [ + case 'mappings_json': + $builder->add('mappings_json', TextareaType::class, [ 'label' => 'mappings', 'required' => false, 'constraints' => [ @@ -101,8 +99,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'aliases': - $builder->add('aliases', TextareaType::class, [ + case 'aliases_json': + $builder->add('aliases_json', TextareaType::class, [ 'label' => 'aliases', 'required' => false, 'constraints' => [ @@ -112,8 +110,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'metadata': - $builder->add('metadata', TextareaType::class, [ + case 'metadata_json': + $builder->add('metadata_json', TextareaType::class, [ 'label' => 'metadata', 'required' => false, 'constraints' => [ @@ -141,9 +139,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MappingsSettingsAliasesSubscriber()); - $builder->addEventSubscriber(new MetadataSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchIlmPolicyType.php b/src/Form/Type/ElasticsearchIlmPolicyType.php index a38148f2..0fcc397d 100644 --- a/src/Form/Type/ElasticsearchIlmPolicyType.php +++ b/src/Form/Type/ElasticsearchIlmPolicyType.php @@ -38,10 +38,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void if ('create' == $options['context']) { $fields[] = 'name'; } - $fields[] = 'hot'; - $fields[] = 'warm'; - $fields[] = 'cold'; - $fields[] = 'delete'; + $fields[] = 'hot_json'; + $fields[] = 'warm_json'; + $fields[] = 'cold_json'; + $fields[] = 'delete_json'; foreach ($fields as $field) { switch ($field) { @@ -56,8 +56,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'hot': - $builder->add('hot', TextareaType::class, [ + case 'hot_json': + $builder->add('hot_json', TextareaType::class, [ 'label' => 'hot', 'required' => false, 'constraints' => [ @@ -67,8 +67,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'warm': - $builder->add('warm', TextareaType::class, [ + case 'warm_json': + $builder->add('warm_json', TextareaType::class, [ 'label' => 'warm', 'required' => false, 'constraints' => [ @@ -81,8 +81,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'cold': - $builder->add('cold', TextareaType::class, [ + case 'cold_json': + $builder->add('cold_json', TextareaType::class, [ 'label' => 'cold', 'required' => false, 'constraints' => [ @@ -92,8 +92,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'delete': - $builder->add('delete', TextareaType::class, [ + case 'delete_json': + $builder->add('delete_json', TextareaType::class, [ 'label' => 'delete', 'required' => false, 'constraints' => [ @@ -106,34 +106,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } - $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { - $form = $event->getForm(); - - if ($form->has('hot') && $form->get('hot')->getData()) { - $fieldOptions = $form->get('hot')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('hot')->getData(), JSON_PRETTY_PRINT); - $form->add('hot', TextareaType::class, $fieldOptions); - } - - if ($form->has('warm') && $form->get('warm')->getData()) { - $fieldOptions = $form->get('warm')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('warm')->getData(), JSON_PRETTY_PRINT); - $form->add('warm', TextareaType::class, $fieldOptions); - } - - if ($form->has('cold') && $form->get('cold')->getData()) { - $fieldOptions = $form->get('cold')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('cold')->getData(), JSON_PRETTY_PRINT); - $form->add('cold', TextareaType::class, $fieldOptions); - } - - if ($form->has('delete') && $form->get('delete')->getData()) { - $fieldOptions = $form->get('delete')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('delete')->getData(), JSON_PRETTY_PRINT); - $form->add('delete', TextareaType::class, $fieldOptions); - } - }); - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($options) { $form = $event->getForm(); $data = $event->getData(); @@ -149,26 +121,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } } - - if ($form->has('hot') && $form->get('hot')->getData()) { - $data->setHot(json_decode($form->get('hot')->getData(), true)); - $event->setData($data); - } - - if ($form->has('warm') && $form->get('warm')->getData()) { - $data->setWarm(json_decode($form->get('warm')->getData(), true)); - $event->setData($data); - } - - if ($form->has('cold') && $form->get('cold')->getData()) { - $data->setCold(json_decode($form->get('cold')->getData(), true)); - $event->setData($data); - } - - if ($form->has('delete') && $form->get('delete')->getData()) { - $data->setDelete(json_decode($form->get('delete')->getData(), true)); - $event->setData($data); - } }); } diff --git a/src/Form/Type/ElasticsearchIndexTemplateLegacyType.php b/src/Form/Type/ElasticsearchIndexTemplateLegacyType.php index ab1ea7ea..d07a0068 100644 --- a/src/Form/Type/ElasticsearchIndexTemplateLegacyType.php +++ b/src/Form/Type/ElasticsearchIndexTemplateLegacyType.php @@ -3,7 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MappingsSettingsAliasesSubscriber; use App\Manager\CallManager; use App\Manager\ElasticsearchIndexTemplateLegacyManager; use App\Model\CallRequestModel; @@ -53,9 +52,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } $fields[] = 'version'; $fields[] = 'order'; - $fields[] = 'settings'; - $fields[] = 'mappings'; - $fields[] = 'aliases'; + $fields[] = 'settings_json'; + $fields[] = 'mappings_json'; + $fields[] = 'aliases_json'; foreach ($fields as $field) { switch ($field) { @@ -117,8 +116,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'settings': - $builder->add('settings', TextareaType::class, [ + case 'settings_json': + $builder->add('settings_json', TextareaType::class, [ 'label' => 'settings', 'required' => false, 'constraints' => [ @@ -128,8 +127,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'mappings': - $builder->add('mappings', TextareaType::class, [ + case 'mappings_json': + $builder->add('mappings_json', TextareaType::class, [ 'label' => 'mappings', 'required' => false, 'constraints' => [ @@ -142,8 +141,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'aliases': - $builder->add('aliases', TextareaType::class, [ + case 'aliases_json': + $builder->add('aliases_json', TextareaType::class, [ 'label' => 'aliases', 'required' => false, 'constraints' => [ @@ -171,8 +170,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MappingsSettingsAliasesSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchIndexTemplateType.php b/src/Form/Type/ElasticsearchIndexTemplateType.php index 38dc0666..3dea6fab 100644 --- a/src/Form/Type/ElasticsearchIndexTemplateType.php +++ b/src/Form/Type/ElasticsearchIndexTemplateType.php @@ -3,8 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MappingsSettingsAliasesSubscriber; -use App\Form\EventListener\MetadataSubscriber; use App\Manager\CallManager; use App\Manager\ElasticsearchIndexTemplateManager; use App\Model\CallRequestModel; @@ -55,10 +53,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $fields[] = 'data_stream'; } $fields[] = 'composed_of'; - $fields[] = 'settings'; - $fields[] = 'mappings'; - $fields[] = 'aliases'; - $fields[] = 'metadata'; + $fields[] = 'settings_json'; + $fields[] = 'mappings_json'; + $fields[] = 'aliases_json'; + $fields[] = 'metadata_json'; foreach ($fields as $field) { switch ($field) { @@ -131,8 +129,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'settings': - $builder->add('settings', TextareaType::class, [ + case 'settings_json': + $builder->add('settings_json', TextareaType::class, [ 'label' => 'settings', 'required' => false, 'constraints' => [ @@ -142,8 +140,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'mappings': - $builder->add('mappings', TextareaType::class, [ + case 'mappings_json': + $builder->add('mappings_json', TextareaType::class, [ 'label' => 'mappings', 'required' => false, 'constraints' => [ @@ -156,8 +154,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'aliases': - $builder->add('aliases', TextareaType::class, [ + case 'aliases_json': + $builder->add('aliases_json', TextareaType::class, [ 'label' => 'aliases', 'required' => false, 'constraints' => [ @@ -167,8 +165,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'metadata': - $builder->add('metadata', TextareaType::class, [ + case 'metadata_json': + $builder->add('metadata_json', TextareaType::class, [ 'label' => 'metadata', 'required' => false, 'constraints' => [ @@ -196,9 +194,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MappingsSettingsAliasesSubscriber()); - $builder->addEventSubscriber(new MetadataSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchIndexType.php b/src/Form/Type/ElasticsearchIndexType.php index c1fa7e7d..3c3a3f4c 100644 --- a/src/Form/Type/ElasticsearchIndexType.php +++ b/src/Form/Type/ElasticsearchIndexType.php @@ -3,7 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MappingsSettingsAliasesSubscriber; use App\Manager\ElasticsearchIndexManager; use App\Model\CallRequestModel; use App\Model\ElasticsearchIndexModel; @@ -38,9 +37,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void if ('create' == $options['context']) { $fields[] = 'name'; - $fields[] = 'settings'; + $fields[] = 'settings_json'; } - $fields[] = 'mappings'; + $fields[] = 'mappings_json'; foreach ($fields as $field) { switch ($field) { @@ -56,8 +55,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); break; - case 'settings': - $builder->add('settings', TextareaType::class, [ + case 'settings_json': + $builder->add('settings_json', TextareaType::class, [ 'label' => 'settings', 'required' => false, 'constraints' => [ @@ -65,8 +64,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); break; - case 'mappings': - $builder->add('mappings', TextareaType::class, [ + case 'mappings_json': + $builder->add('mappings_json', TextareaType::class, [ 'label' => 'mappings', 'required' => false, 'constraints' => [ @@ -95,8 +94,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MappingsSettingsAliasesSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchPipelineType.php b/src/Form/Type/ElasticsearchPipelineType.php index cba8ed20..2bc1f34e 100644 --- a/src/Form/Type/ElasticsearchPipelineType.php +++ b/src/Form/Type/ElasticsearchPipelineType.php @@ -42,8 +42,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } $fields[] = 'description'; $fields[] = 'version'; - $fields[] = 'processors'; - $fields[] = 'on_failure'; + $fields[] = 'processors_json'; + $fields[] = 'on_failure_json'; foreach ($fields as $field) { switch ($field) { @@ -78,8 +78,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); break; - case 'processors': - $builder->add('processors', TextareaType::class, [ + case 'processors_json': + $builder->add('processors_json', TextareaType::class, [ 'label' => 'processors', 'required' => true, 'constraints' => [ @@ -93,8 +93,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'on_failure': - $builder->add('on_failure', TextareaType::class, [ + case 'on_failure_json': + $builder->add('on_failure_json', TextareaType::class, [ 'label' => 'on_failure', 'required' => false, 'constraints' => [ @@ -107,22 +107,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } - $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { - $form = $event->getForm(); - - if ($form->has('processors') && $form->get('processors')->getData()) { - $fieldOptions = $form->get('processors')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('processors')->getData(), JSON_PRETTY_PRINT); - $form->add('processors', TextareaType::class, $fieldOptions); - } - - if ($form->has('on_failure') && $form->get('on_failure')->getData()) { - $fieldOptions = $form->get('on_failure')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('on_failure')->getData(), JSON_PRETTY_PRINT); - $form->add('on_failure', TextareaType::class, $fieldOptions); - } - }); - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($options) { $form = $event->getForm(); $data = $event->getData(); @@ -138,16 +122,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } } - - if ($form->has('processors') && $form->get('processors')->getData()) { - $data->setProcessors(json_decode($form->get('processors')->getData(), true)); - $event->setData($data); - } - - if ($form->has('on_failure') && $form->get('on_failure')->getData()) { - $data->setOnFailure(json_decode($form->get('on_failure')->getData(), true)); - $event->setData($data); - } }); } diff --git a/src/Form/Type/ElasticsearchRoleType.php b/src/Form/Type/ElasticsearchRoleType.php index 55a5be1d..f0770d68 100644 --- a/src/Form/Type/ElasticsearchRoleType.php +++ b/src/Form/Type/ElasticsearchRoleType.php @@ -3,7 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MetadataSubscriber; use App\Manager\ElasticsearchRoleManager; use App\Model\CallRequestModel; use App\Model\ElasticsearchRoleModel; @@ -42,9 +41,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } $fields[] = 'cluster'; $fields[] = 'run_as'; - $fields[] = 'indices'; - $fields[] = 'applications'; - $fields[] = 'metadata'; + $fields[] = 'indices_json'; + $fields[] = 'applications_json'; + $fields[] = 'metadata_json'; foreach ($fields as $field) { switch ($field) { @@ -90,8 +89,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'indices': - $builder->add('indices', TextareaType::class, [ + case 'indices_json': + $builder->add('indices_json', TextareaType::class, [ 'label' => 'indices', 'required' => false, 'constraints' => [ @@ -101,8 +100,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'applications': - $builder->add('applications', TextareaType::class, [ + case 'applications_json': + $builder->add('applications_json', TextareaType::class, [ 'label' => 'applications', 'required' => false, 'constraints' => [ @@ -115,8 +114,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'metadata': - $builder->add('metadata', TextareaType::class, [ + case 'metadata_json': + $builder->add('metadata_json', TextareaType::class, [ 'label' => 'metadata', 'required' => false, 'constraints' => [ @@ -129,22 +128,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } - $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { - $form = $event->getForm(); - - if ($form->has('indices') && $form->get('indices')->getData()) { - $fieldOptions = $form->get('indices')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('indices')->getData(), JSON_PRETTY_PRINT); - $form->add('indices', TextareaType::class, $fieldOptions); - } - - if ($form->has('applications') && $form->get('applications')->getData()) { - $fieldOptions = $form->get('applications')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('applications')->getData(), JSON_PRETTY_PRINT); - $form->add('applications', TextareaType::class, $fieldOptions); - } - }); - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($options) { $form = $event->getForm(); $data = $event->getData(); @@ -160,19 +143,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } } - - if ($form->has('indices') && $form->get('indices')->getData()) { - $data->setIndices(json_decode($form->get('indices')->getData(), true)); - $event->setData($data); - } - - if ($form->has('applications') && $form->get('applications')->getData()) { - $data->setApplications(json_decode($form->get('applications')->getData(), true)); - $event->setData($data); - } }); - - $builder->addEventSubscriber(new MetadataSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchUserType.php b/src/Form/Type/ElasticsearchUserType.php index 37cfa5b4..2340def2 100644 --- a/src/Form/Type/ElasticsearchUserType.php +++ b/src/Form/Type/ElasticsearchUserType.php @@ -3,7 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MetadataSubscriber; use App\Manager\ElasticsearchUserManager; use App\Model\CallRequestModel; use App\Model\ElasticsearchUserModel; @@ -50,7 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $fields[] = 'email'; $fields[] = 'full_name'; $fields[] = 'roles'; - $fields[] = 'metadata'; + $fields[] = 'metadata_json'; foreach ($fields as $field) { switch ($field) { @@ -132,8 +131,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); break; - case 'metadata': - $builder->add('metadata', TextareaType::class, [ + case 'metadata_json': + $builder->add('metadata_json', TextareaType::class, [ 'label' => 'metadata', 'required' => false, 'constraints' => [ @@ -159,8 +158,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MetadataSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Model/ElasticsearchComponentTemplateModel.php b/src/Model/ElasticsearchComponentTemplateModel.php index 8a721da4..c649e4ae 100644 --- a/src/Model/ElasticsearchComponentTemplateModel.php +++ b/src/Model/ElasticsearchComponentTemplateModel.php @@ -13,7 +13,9 @@ class ElasticsearchComponentTemplateModel extends AbstractAppModel private $version; - private $metadata; + private ?array $metadata = null; + + private ?string $metadataJson = null; public function getName(): ?string { @@ -44,13 +46,25 @@ public function getMetadata(): ?array return $this->metadata; } - public function setMetadata($metadata): self + public function setMetadata(?array $metadata): self { $this->metadata = $metadata; return $this; } + public function getMetadataJson(): ?string + { + return $this->metadataJson; + } + + public function setMetadataJson(?string $metadataJson): self + { + $this->metadataJson = $metadataJson; + + return $this; + } + public function isManaged(): ?bool { return true === isset($this->getMetadata()['managed']) && true === $this->getMetadata()['managed']; @@ -69,15 +83,19 @@ public function convert(?array $template): self } if (true === isset($template['component_template']['template']['settings']) && 0 < count($template['component_template']['template']['settings'])) { $this->setSettings($template['component_template']['template']['settings']); + $this->setSettingsJson(json_encode($template['component_template']['template']['settings'], JSON_PRETTY_PRINT)); } if (true === isset($template['component_template']['template']['mappings']) && 0 < count($template['component_template']['template']['mappings'])) { $this->setMappings($template['component_template']['template']['mappings']); + $this->setMappingsJson(json_encode($template['component_template']['template']['mappings'], JSON_PRETTY_PRINT)); } if (true === isset($template['component_template']['template']['aliases']) && 0 < count($template['component_template']['template']['aliases'])) { $this->setAliases($template['component_template']['template']['aliases']); + $this->setAliasesJson(json_encode($template['component_template']['template']['aliases'], JSON_PRETTY_PRINT)); } if (true === isset($template['component_template']['_meta']) && 0 < count($template['component_template']['_meta'])) { $this->setMetadata($template['component_template']['_meta']); + $this->setMetadataJson(json_encode($template['component_template']['_meta'], JSON_PRETTY_PRINT)); } return $this; @@ -93,20 +111,20 @@ public function getJson(): array $json['version'] = $this->getVersion(); } - if ($this->getSettings()) { - $json['template']['settings'] = $this->getSettings(); + if ($this->getSettingsJson()) { + $json['template']['settings'] = json_decode($this->getSettingsJson(), true); } - if ($this->getMappings()) { - $json['template']['mappings'] = $this->getMappings(); + if ($this->getMappingsJson()) { + $json['template']['mappings'] = json_decode($this->getMappingsJson(), true); } - if ($this->getAliases()) { - $json['template']['aliases'] = $this->getAliases(); + if ($this->getAliasesJson()) { + $json['template']['aliases'] = json_decode($this->getAliasesJson(), true); } - if ($this->getMetadata()) { - $json['_meta'] = $this->getMetadata(); + if ($this->getMetadataJson()) { + $json['_meta'] = json_decode($this->getMetadataJson(), true); } if (0 == count($json['template'])) { diff --git a/src/Model/ElasticsearchIlmPolicyModel.php b/src/Model/ElasticsearchIlmPolicyModel.php index 6a637486..9df1cc32 100644 --- a/src/Model/ElasticsearchIlmPolicyModel.php +++ b/src/Model/ElasticsearchIlmPolicyModel.php @@ -12,13 +12,21 @@ class ElasticsearchIlmPolicyModel extends AbstractAppModel private $modifiedDate; - private $hot; + private ?array $hot = null; - private $warm; + private ?string $hotJson = null; - private $cold; + private ?array $warm = null; - private $delete; + private ?string $warmJson = null; + + private ?array $cold = null; + + private ?string $coldJson = null; + + private ?array $delete = null; + + private ?string $deleteJson = null; private $phases; @@ -63,49 +71,97 @@ public function getHot(): ?array return $this->hot; } - public function setHot($hot): self + public function setHot(?array $hot): self { $this->hot = $hot; return $this; } + public function getHotJson(): ?string + { + return $this->hotJson; + } + + public function setHotJson(?string $hotJson): self + { + $this->hotJson = $hotJson; + + return $this; + } + public function getWarm(): ?array { return $this->warm; } - public function setWarm($warm): self + public function setWarm(?array $warm): self { $this->warm = $warm; return $this; } + public function getWarmJson(): ?string + { + return $this->warmJson; + } + + public function setWarmJson(?string $warmJson): self + { + $this->warmJson = $warmJson; + + return $this; + } + public function getCold(): ?array { return $this->cold; } - public function setCold($cold): self + public function setCold(?array $cold): self { $this->cold = $cold; return $this; } + public function getColdJson(): ?string + { + return $this->coldJson; + } + + public function setColdJson(?string $coldJson): self + { + $this->coldJson = $coldJson; + + return $this; + } + public function getDelete(): ?array { return $this->delete; } - public function setDelete($delete): self + public function setDelete(?array $delete): self { $this->delete = $delete; return $this; } + public function getDeleteJson(): ?string + { + return $this->deleteJson; + } + + public function setDeleteJson(?string $deleteJson): self + { + $this->deleteJson = $deleteJson; + + return $this; + } + public function getPhases(): ?array { return $this->phases; @@ -140,15 +196,19 @@ public function convert(?array $policy): self if (true === isset($policy['policy']['phases']['hot'])) { $this->setHot($policy['policy']['phases']['hot']); + $this->setHotJson(json_encode($policy['policy']['phases']['hot'], JSON_PRETTY_PRINT)); } if (true === isset($policy['policy']['phases']['warm'])) { $this->setWarm($policy['policy']['phases']['warm']); + $this->setWarmJson(json_encode($policy['policy']['phases']['warm'], JSON_PRETTY_PRINT)); } if (true === isset($policy['policy']['phases']['cold'])) { $this->setCold($policy['policy']['phases']['cold']); + $this->setColdJson(json_encode($policy['policy']['phases']['cold'], JSON_PRETTY_PRINT)); } if (true === isset($policy['policy']['phases']['delete'])) { $this->setDelete($policy['policy']['phases']['delete']); + $this->setDeleteJson(json_encode($policy['policy']['phases']['delete'], JSON_PRETTY_PRINT)); } } @@ -163,20 +223,20 @@ public function getJson(): array ], ]; - if ($this->getHot()) { - $json['policy']['phases']['hot'] = $this->getHot(); + if ($this->getHotJson()) { + $json['policy']['phases']['hot'] = json_decode($this->getHotJson(), true); } - if ($this->getWarm()) { - $json['policy']['phases']['warm'] = $this->getWarm(); + if ($this->getWarmJson()) { + $json['policy']['phases']['warm'] = json_decode($this->getWarmJson(), true); } - if ($this->getCold()) { - $json['policy']['phases']['cold'] = $this->getCold(); + if ($this->getColdJson()) { + $json['policy']['phases']['cold'] = json_decode($this->getColdJson(), true); } - if ($this->getDelete()) { - $json['policy']['phases']['delete'] = $this->getDelete(); + if ($this->getDeleteJson()) { + $json['policy']['phases']['delete'] = json_decode($this->getDeleteJson(), true); } return $json; diff --git a/src/Model/ElasticsearchIndexModel.php b/src/Model/ElasticsearchIndexModel.php index 1d1934f5..778c76be 100644 --- a/src/Model/ElasticsearchIndexModel.php +++ b/src/Model/ElasticsearchIndexModel.php @@ -281,10 +281,12 @@ public function convert(?array $index): self if (true === isset($index['settings']) && 0 < count($index['settings'])) { $this->setSettings($index['settings']); + $this->setSettingsJson(json_encode($index['settings'], JSON_PRETTY_PRINT)); } if (true === isset($index['mappings']) && 0 < count($index['mappings'])) { $this->setMappings($index['mappings']); + $this->setMappingsJson(json_encode($index['mappings'], JSON_PRETTY_PRINT)); } if (true === isset($index['mappings_flat']) && 0 < count($index['mappings_flat'])) { diff --git a/src/Model/ElasticsearchIndexTemplateLegacyModel.php b/src/Model/ElasticsearchIndexTemplateLegacyModel.php index ab3c27e4..7b2b2c32 100644 --- a/src/Model/ElasticsearchIndexTemplateLegacyModel.php +++ b/src/Model/ElasticsearchIndexTemplateLegacyModel.php @@ -142,16 +142,16 @@ public function getJson(): array $json['order'] = $this->getOrder(); } - if ($this->getSettings()) { - $json['settings'] = $this->getSettings(); + if ($this->getSettingsJson()) { + $json['settings'] = json_decode($this->getSettingsJson(), true); } - if ($this->getMappings()) { - $json['mappings'] = $this->getMappings(); + if ($this->getMappingsJson()) { + $json['mappings'] = json_decode($this->getMappingsJson(), true); } - if ($this->getAliases()) { - $json['aliases'] = $this->getAliases(); + if ($this->getAliasesJson()) { + $json['aliases'] = json_decode($this->getAliasesJson(), true); } return $json; diff --git a/src/Model/ElasticsearchIndexTemplateModel.php b/src/Model/ElasticsearchIndexTemplateModel.php index e51582fb..b46f061a 100644 --- a/src/Model/ElasticsearchIndexTemplateModel.php +++ b/src/Model/ElasticsearchIndexTemplateModel.php @@ -19,7 +19,9 @@ class ElasticsearchIndexTemplateModel extends AbstractAppModel private $composedOf; - private $metadata; + private ?array $metadata = null; + + private ?string $metadataJson = null; private $dataStream; @@ -88,13 +90,25 @@ public function getMetadata(): ?array return $this->metadata; } - public function setMetadata($metadata): self + public function setMetadata(?array $metadata): self { $this->metadata = $metadata; return $this; } + public function getMetadataJson(): ?string + { + return $this->metadataJson; + } + + public function setMetadataJson(?string $metadataJson): self + { + $this->metadataJson = $metadataJson; + + return $this; + } + public function getDataStream(): ?bool { return $this->dataStream; @@ -154,6 +168,7 @@ public function convert(?array $template): self } if (true === isset($template['index_template']['_meta']) && 0 < count($template['index_template']['_meta'])) { $this->setMetadata($template['index_template']['_meta']); + $this->setMetadataJson(json_encode($template['index_template']['_meta'], JSON_PRETTY_PRINT)); } if (true === isset($template['index_template']['data_stream'])) { $this->setDataStream(true); @@ -181,24 +196,24 @@ public function getJson(): array $json['composed_of'] = $this->getComposedOf(); } - if ($this->getSettings() || $this->getMappings() || $this->getAliases()) { + if ($this->getSettingsJson() || $this->getMappingsJson() || $this->getAliasesJson()) { $json['template'] = []; } - if ($this->getSettings()) { - $json['template']['settings'] = $this->getSettings(); + if ($this->getSettingsJson()) { + $json['template']['settings'] = json_decode($this->getSettingsJson(), true); } - if ($this->getMappings()) { - $json['template']['mappings'] = $this->getMappings(); + if ($this->getMappingsJson()) { + $json['template']['mappings'] = json_decode($this->getMappingsJson(), true); } - if ($this->getAliases()) { - $json['template']['aliases'] = $this->getAliases(); + if ($this->getAliasesJson()) { + $json['template']['aliases'] = json_decode($this->getAliasesJson(), true); } - if ($this->getMetadata()) { - $json['_meta'] = $this->getMetadata(); + if ($this->getMetadataJson()) { + $json['_meta'] = json_decode($this->getMetadataJson(), true); } if ($this->getDataStream()) { diff --git a/src/Model/ElasticsearchPipelineModel.php b/src/Model/ElasticsearchPipelineModel.php index 7e9af2dd..c48ee9f7 100644 --- a/src/Model/ElasticsearchPipelineModel.php +++ b/src/Model/ElasticsearchPipelineModel.php @@ -12,9 +12,13 @@ class ElasticsearchPipelineModel extends AbstractAppModel private $description; - private $processors; + private ?array $processors = null; - private $onFailure; + private ?string $processorsJson = null; + + private ?array $onFailure = null; + + private ?string $onFailureJson = null; public function getName(): ?string { @@ -57,25 +61,49 @@ public function getProcessors(): ?array return $this->processors; } - public function setProcessors($processors): self + public function setProcessors(?array $processors): self { $this->processors = $processors; return $this; } + public function getProcessorsJson(): ?string + { + return $this->processorsJson; + } + + public function setProcessorsJson(?string $processorsJson): self + { + $this->processorsJson = $processorsJson; + + return $this; + } + public function getOnFailure(): ?array { return $this->onFailure; } - public function setOnFailure($onFailure): self + public function setOnFailure(?array $onFailure): self { $this->onFailure = $onFailure; return $this; } + public function getOnFailureJson(): ?string + { + return $this->onFailureJson; + } + + public function setOnFailureJson(?string $onFailureJson): self + { + $this->onFailureJson = $onFailureJson; + + return $this; + } + public function isSystem(): ?bool { return '.' == substr($this->getName(), 0, 1); @@ -92,9 +120,11 @@ public function convert(?array $pipeline): self } if (true === isset($pipeline['processors']) && 0 < count($pipeline['processors'])) { $this->setProcessors($pipeline['processors']); + $this->setProcessorsJson(json_encode($pipeline['processors'], JSON_PRETTY_PRINT)); } if (true === isset($pipeline['on_failure']) && 0 < count($pipeline['on_failure'])) { $this->setOnFailure($pipeline['on_failure']); + $this->setOnFailureJson(json_encode($pipeline['on_failure'], JSON_PRETTY_PRINT)); } return $this; } @@ -102,7 +132,7 @@ public function convert(?array $pipeline): self public function getJson(): array { $json = [ - 'processors' => $this->getProcessors(), + 'processors' => json_decode($this->getProcessorsJson(), true), ]; if ($this->getVersion()) { @@ -113,8 +143,8 @@ public function getJson(): array $json['description'] = $this->getDescription(); } - if ($this->getOnFailure()) { - $json['on_failure'] = $this->getOnFailure(); + if ($this->getOnFailureJson()) { + $json['on_failure'] = json_decode($this->getOnFailureJson(), true); } return $json; diff --git a/src/Model/ElasticsearchRoleModel.php b/src/Model/ElasticsearchRoleModel.php index 85aeb03a..737f802b 100644 --- a/src/Model/ElasticsearchRoleModel.php +++ b/src/Model/ElasticsearchRoleModel.php @@ -11,11 +11,15 @@ class ElasticsearchRoleModel extends AbstractAppModel private $name; - private $applications; + private ?array $applications = null; + + private ?string $applicationsJson = null; private $cluster; - private $indices; + private ?array $indices = null; + + private ?string $indicesJson = null; private $runAs; @@ -36,13 +40,25 @@ public function getApplications(): ?array return $this->applications; } - public function setApplications($applications): self + public function setApplications(?array $applications): self { $this->applications = $applications; return $this; } + public function getApplicationsJson(): ?string + { + return $this->applicationsJson; + } + + public function setApplicationsJson(?string $applicationsJson): self + { + $this->applicationsJson = $applicationsJson; + + return $this; + } + public function getCluster(): ?array { return $this->cluster; @@ -60,13 +76,25 @@ public function getIndices(): ?array return $this->indices; } - public function setIndices($indices): self + public function setIndices(?array $indices): self { $this->indices = $indices; return $this; } + public function getIndicesJson(): ?string + { + return $this->indicesJson; + } + + public function setIndicesJson(?string $indicesJson): self + { + $this->indicesJson = $indicesJson; + + return $this; + } + public function getRunAs(): ?array { return $this->runAs; @@ -86,12 +114,15 @@ public function convert(?array $role): self $this->setRunAs($role['run_as']); if (true === isset($role['indices']) && 0 < count($role['indices'])) { $this->setIndices($role['indices']); + $this->setIndicesJson(json_encode($role['indices'], JSON_PRETTY_PRINT)); } if (true === isset($role['applications']) && 0 < count($role['applications'])) { $this->setApplications($role['applications']); + $this->setApplicationsJson(json_encode($role['applications'], JSON_PRETTY_PRINT)); } if (true === isset($role['metadata']) && 0 < count($role['metadata'])) { $this->setMetadata($role['metadata']); + $this->setMetadataJson(json_encode($role['metadata'], JSON_PRETTY_PRINT)); } return $this; } @@ -103,16 +134,16 @@ public function getJson(): array 'run_as' => $this->getRunAs(), ]; - if ($this->getApplications()) { - $json['applications'] = $this->getApplications(); + if ($this->getApplicationsJson()) { + $json['applications'] = json_decode($this->getApplicationsJson(), true); } - if ($this->getIndices()) { - $json['indices'] = $this->getIndices(); + if ($this->getIndicesJson()) { + $json['indices'] = json_decode($this->getIndicesJson(), true); } - if ($this->getMetadata()) { - $json['metadata'] = $this->getMetadata(); + if ($this->getMetadataJson()) { + $json['metadata'] = json_decode($this->getMetadataJson(), true); } return $json; diff --git a/src/Model/ElasticsearchSnapshotModel.php b/src/Model/ElasticsearchSnapshotModel.php index 3844ca44..b3cfb131 100644 --- a/src/Model/ElasticsearchSnapshotModel.php +++ b/src/Model/ElasticsearchSnapshotModel.php @@ -25,7 +25,9 @@ class ElasticsearchSnapshotModel extends AbstractAppModel private $duration; - private $metadata; + private ?array $metadata = null; + + private ?string $metadataJson = null; public function __construct() { @@ -140,6 +142,18 @@ public function setMetadata(?array $metadata): self return $this; } + public function getMetadataJson(): ?string + { + return $this->metadataJson; + } + + public function setMetadataJson(?string $metadataJson): self + { + $this->metadataJson = $metadataJson; + + return $this; + } + public function convert(?array $snapshot): self { $this->setName($snapshot['snapshot']); @@ -175,6 +189,7 @@ public function convert(?array $snapshot): self if (true === isset($snapshot['metadata'])) { $this->setMetadata($snapshot['metadata']); + $this->setMetadataJson(json_encode($snapshot['metadata'], JSON_PRETTY_PRINT)); } return $this; diff --git a/src/Model/ElasticsearchUserModel.php b/src/Model/ElasticsearchUserModel.php index 6812085a..bf9dfab9 100644 --- a/src/Model/ElasticsearchUserModel.php +++ b/src/Model/ElasticsearchUserModel.php @@ -123,6 +123,7 @@ public function convert(?array $user): self $this->setEnabled($user['enabled']); if (true === isset($user['metadata']) && 0 < count($user['metadata'])) { $this->setMetadata($user['metadata']); + $this->setMetadataJson(json_encode($user['metadata'], JSON_PRETTY_PRINT)); } return $this; } diff --git a/src/Traits/ElasticsearchRoleUserModelTrait.php b/src/Traits/ElasticsearchRoleUserModelTrait.php index d44d8156..120e6a1d 100644 --- a/src/Traits/ElasticsearchRoleUserModelTrait.php +++ b/src/Traits/ElasticsearchRoleUserModelTrait.php @@ -4,20 +4,34 @@ trait ElasticsearchRoleUserModelTrait { - private $metadata; + private ?array $metadata = null; + + private ?string $metadataJson = null; public function getMetadata(): ?array { return $this->metadata; } - public function setMetadata($metadata): self + public function setMetadata(?array $metadata): self { $this->metadata = $metadata; return $this; } + public function getMetadataJson(): ?string + { + return $this->metadataJson; + } + + public function setMetadataJson(?string $metadataJson): self + { + $this->metadataJson = $metadataJson; + + return $this; + } + public function isReserved(): ?bool { return true === isset($this->getMetadata()['_reserved']) && true === $this->getMetadata()['_reserved']; diff --git a/src/Traits/MappingsSettingsAliasesModelTrait.php b/src/Traits/MappingsSettingsAliasesModelTrait.php index 23d8bd07..0d60d507 100644 --- a/src/Traits/MappingsSettingsAliasesModelTrait.php +++ b/src/Traits/MappingsSettingsAliasesModelTrait.php @@ -4,24 +4,42 @@ trait MappingsSettingsAliasesModelTrait { - private $settings; + private ?array $settings = null; - private $mappings; + private ?string $settingsJson = null; - private $aliases; + private ?array $mappings = null; + + private ?string $mappingsJson = null; + + private ?array $aliases = null; + + private ?string $aliasesJson = null; public function getSettings(): ?array { return $this->settings; } - public function setSettings($settings): self + public function setSettings(?array $settings): self { $this->settings = $settings; return $this; } + public function getSettingsJson(): ?string + { + return $this->settingsJson; + } + + public function setSettingsJson(?string $settingsJson): self + { + $this->settingsJson = $settingsJson; + + return $this; + } + public function getSetting($key): ?string { return $this->settings[$key] ?? false; @@ -39,22 +57,46 @@ public function getMappings(): ?array return $this->mappings; } - public function setMappings($mappings): self + public function setMappings(?array $mappings): self { $this->mappings = $mappings; return $this; } + public function getMappingsJson(): ?string + { + return $this->mappingsJson; + } + + public function setMappingsJson(?string $mappingsJson): self + { + $this->mappingsJson = $mappingsJson; + + return $this; + } + public function getAliases(): ?array { return $this->aliases; } - public function setAliases($aliases): self + public function setAliases(?array $aliases): self { $this->aliases = $aliases; return $this; } + + public function getAliasesJson(): ?string + { + return $this->aliasesJson; + } + + public function setAliasesJson(?string $aliasesJson): self + { + $this->aliasesJson = $aliasesJson; + + return $this; + } } diff --git a/tests/Controller/ElasticsearchIlmControllerTest.php b/tests/Controller/ElasticsearchIlmControllerTest.php index e555e247..a87c004e 100644 --- a/tests/Controller/ElasticsearchIlmControllerTest.php +++ b/tests/Controller/ElasticsearchIlmControllerTest.php @@ -58,7 +58,7 @@ public function testCreate(): void $values = [ 'data[name]' => GENERATED_NAME, - 'data[hot]' => '{ + 'data[hot_json]' => '{ "min_age": "0ms", "actions": { "rollover": { diff --git a/tests/Controller/ElasticsearchIndexControllerTest.php b/tests/Controller/ElasticsearchIndexControllerTest.php index c57c5f05..937e7f91 100644 --- a/tests/Controller/ElasticsearchIndexControllerTest.php +++ b/tests/Controller/ElasticsearchIndexControllerTest.php @@ -64,7 +64,7 @@ public function testCreate(): void 'data[name]' => GENERATED_NAME, ]; if (true === $this->callManager->checkVersion('7.0')) { - $values['data[mappings]'] = file_get_contents(__DIR__.'/../../src/DataFixtures/es-test-mappings.json'); + $values['data[mappings_json]'] = file_get_contents(__DIR__.'/../../src/DataFixtures/es-test-mappings.json'); } $this->client->submitForm('Submit', $values); @@ -90,7 +90,7 @@ public function testCreateSystem(): void 'data[name]' => GENERATED_NAME_SYSTEM, ]; if (true === $this->callManager->checkVersion('7.0')) { - $values['data[mappings]'] = file_get_contents(__DIR__.'/../../src/DataFixtures/es-test-mappings.json'); + $values['data[mappings_json]'] = file_get_contents(__DIR__.'/../../src/DataFixtures/es-test-mappings.json'); } $this->client->submitForm('Submit', $values); diff --git a/tests/Controller/ElasticsearchPipelineControllerTest.php b/tests/Controller/ElasticsearchPipelineControllerTest.php index f31ee5e2..cc4bdb1e 100644 --- a/tests/Controller/ElasticsearchPipelineControllerTest.php +++ b/tests/Controller/ElasticsearchPipelineControllerTest.php @@ -41,7 +41,7 @@ public function testCreate(): void $values = [ 'data[name]' => GENERATED_NAME, - 'data[processors]' => '[]', + 'data[processors_json]' => '[]', ]; $this->client->submitForm('Submit', $values); @@ -79,7 +79,7 @@ public function testCreateCopy(): void $this->assertSelectorTextSame('h3', 'Create pipeline'); $values = [ - 'data[processors]' => '[]', + 'data[processors_json]' => '[]', ]; $this->client->submitForm('Submit', $values); diff --git a/tests/Model/ElasticsearchComponentTemplateModelTest.php b/tests/Model/ElasticsearchComponentTemplateModelTest.php index 556564fe..d5883094 100644 --- a/tests/Model/ElasticsearchComponentTemplateModelTest.php +++ b/tests/Model/ElasticsearchComponentTemplateModelTest.php @@ -12,15 +12,15 @@ public function test(): void $template = new ElasticsearchComponentTemplateModel(); $template->setName('name'); $template->setVersion(1); - $template->setSettings(''); $template->setSettings([]); + $template->setSettingsJson(json_encode([])); $template->setSetting('setting-key', 'setting-value'); - $template->setMappings(''); $template->setMappings(['mappings']); - $template->setAliases(''); + $template->setMappingsJson(json_encode(['mappings'])); $template->setAliases(['aliases']); - $template->setMetadata(''); + $template->setAliasesJson(json_encode(['aliases'])); $template->setMetadata(['metadata']); + $template->setMetadataJson(json_encode(['metadata'])); $this->assertEquals($template->getName(), 'name'); $this->assertEquals(strval($template), 'name'); diff --git a/tests/Model/ElasticsearchIlmPolicyModelTest.php b/tests/Model/ElasticsearchIlmPolicyModelTest.php index 5b05fd8e..f680b57d 100644 --- a/tests/Model/ElasticsearchIlmPolicyModelTest.php +++ b/tests/Model/ElasticsearchIlmPolicyModelTest.php @@ -12,16 +12,15 @@ public function test(): void $policy = new ElasticsearchIlmPolicyModel(); $policy->setName('name'); $policy->setVersion(1); - $policy->setPhases(''); $policy->setPhases(['phases']); - $policy->setHot(''); $policy->setHot(['hot']); - $policy->setWarm(''); + $policy->setHotJson(json_encode(['hot'])); $policy->setWarm(['warm']); - $policy->setCold(''); + $policy->setWarmJson(json_encode(['warm'])); $policy->setCold(['cold']); - $policy->setDelete(''); + $policy->setColdJson(json_encode(['cold'])); $policy->setDelete(['delete']); + $policy->setDeleteJson(json_encode(['delete'])); $this->assertEquals($policy->getName(), 'name'); $this->assertEquals(strval($policy), 'name'); diff --git a/tests/Model/ElasticsearchIndexModelTest.php b/tests/Model/ElasticsearchIndexModelTest.php index ffc4bd3e..e8502a5a 100644 --- a/tests/Model/ElasticsearchIndexModelTest.php +++ b/tests/Model/ElasticsearchIndexModelTest.php @@ -21,14 +21,14 @@ public function test(): void $index->setPrimarySize(5); $index->setTotalSize(6); $index->setCreationDate('creation-date'); - $index->setSettings(''); $index->setSettings([]); + $index->setSettingsJson(json_encode([])); $index->setSetting('setting-key', 'setting-value'); - $index->setMappings(''); $index->setMappings(['mappings']); + $index->setMappingsJson(json_encode(['mappings'])); $index->setMappingsFlat(['mapping-field' => ['type' => 'mapping-type']]); - $index->setAliases(''); $index->setAliases(['aliases']); + $index->setAliasesJson(json_encode(['aliases'])); $this->assertEquals($index->getName(), 'name'); $this->assertEquals(strval($index), 'name'); diff --git a/tests/Model/ElasticsearchIndexTemplateLegacyModelTest.php b/tests/Model/ElasticsearchIndexTemplateLegacyModelTest.php index 1fe50d0a..e541f002 100644 --- a/tests/Model/ElasticsearchIndexTemplateLegacyModelTest.php +++ b/tests/Model/ElasticsearchIndexTemplateLegacyModelTest.php @@ -15,13 +15,13 @@ public function test(): void $template->setTemplate('template'); $template->setVersion(1); $template->setOrder(2); - $template->setSettings(''); $template->setSettings([]); + $template->setSettingsJson(json_encode([])); $template->setSetting('setting-key', 'setting-value'); - $template->setMappings(''); $template->setMappings(['mappings']); - $template->setAliases(''); + $template->setMappingsJson(json_encode(['mappings'])); $template->setAliases(['aliases']); + $template->setAliasesJson(json_encode(['aliases'])); $this->assertEquals($template->getName(), 'name'); $this->assertEquals(strval($template), 'name'); diff --git a/tests/Model/ElasticsearchIndexTemplateModelTest.php b/tests/Model/ElasticsearchIndexTemplateModelTest.php index c8ea3d71..c4bf8242 100644 --- a/tests/Model/ElasticsearchIndexTemplateModelTest.php +++ b/tests/Model/ElasticsearchIndexTemplateModelTest.php @@ -14,15 +14,15 @@ public function test(): void $template->setIndexPatterns('index-patterns'); $template->setVersion(1); $template->setPriority(2); - $template->setSettings(''); $template->setSettings([]); + $template->setSettingsJson(json_encode([])); $template->setSetting('setting-key', 'setting-value'); - $template->setMappings(''); $template->setMappings(['mappings']); - $template->setAliases(''); + $template->setMappingsJson(json_encode(['mappings'])); $template->setAliases(['aliases']); - $template->setMetadata(''); + $template->setAliasesJson(json_encode(['aliases'])); $template->setMetadata(['metadata']); + $template->setMetadataJson(json_encode(['metadata'])); $template->setComposedOf(['composedof']); $template->setDataStream(true); diff --git a/tests/Model/ElasticsearchPipelineModelTest.php b/tests/Model/ElasticsearchPipelineModelTest.php index c4263b5c..ae97981a 100644 --- a/tests/Model/ElasticsearchPipelineModelTest.php +++ b/tests/Model/ElasticsearchPipelineModelTest.php @@ -13,10 +13,10 @@ public function test(): void $pipeline->setName('name'); $pipeline->setVersion(1); $pipeline->setDescription('description'); - $pipeline->setProcessors(''); $pipeline->setProcessors(['processors']); - $pipeline->setOnFailure(''); + $pipeline->setProcessorsJson(json_encode(['processors'])); $pipeline->setOnFailure(['onfailure']); + $pipeline->setOnFailureJson(json_encode(['onfailure'])); $this->assertEquals($pipeline->getName(), 'name'); $this->assertEquals(strval($pipeline), 'name'); diff --git a/tests/Model/ElasticsearchRoleModelTest.php b/tests/Model/ElasticsearchRoleModelTest.php index 5bf36a2a..f84d3a02 100644 --- a/tests/Model/ElasticsearchRoleModelTest.php +++ b/tests/Model/ElasticsearchRoleModelTest.php @@ -12,8 +12,10 @@ public function test(): void $role = new ElasticsearchRoleModel(); $role->setName('name'); $role->setApplications(['applications']); + $role->setApplicationsJson(json_encode(['applications'])); $role->setCluster(['cluster']); $role->setIndices(['indices']); + $role->setIndicesJson(json_encode(['indices'])); $role->setRunAs(['run-as']); $role->setMetadata(['metadata']); From ca64fca9fd52f98832e6c353dece5c5d45efdcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Dion?= Date: Sat, 20 Nov 2021 10:17:23 +0100 Subject: [PATCH 2/3] refactoring models + phpstan level 6 --- .../ElasticsearchIndexController.php | 12 +-- .../MappingsSettingsAliasesSubscriber.php | 64 ------------- src/Form/EventListener/MetadataSubscriber.php | 42 --------- .../ElasticsearchComponentTemplateType.php | 29 +++--- src/Form/Type/ElasticsearchIlmPolicyType.php | 72 +++------------ .../ElasticsearchIndexTemplateLegacyType.php | 21 ++--- .../Type/ElasticsearchIndexTemplateType.php | 29 +++--- src/Form/Type/ElasticsearchIndexType.php | 15 ++- src/Form/Type/ElasticsearchPipelineType.php | 38 ++------ src/Form/Type/ElasticsearchRoleType.php | 47 ++-------- src/Form/Type/ElasticsearchUserType.php | 9 +- .../ElasticsearchComponentTemplateModel.php | 38 ++++++-- src/Model/ElasticsearchIlmPolicyModel.php | 92 +++++++++++++++---- src/Model/ElasticsearchIndexModel.php | 2 + .../ElasticsearchIndexTemplateLegacyModel.php | 12 +-- src/Model/ElasticsearchIndexTemplateModel.php | 37 +++++--- src/Model/ElasticsearchPipelineModel.php | 44 +++++++-- src/Model/ElasticsearchRoleModel.php | 51 ++++++++-- src/Model/ElasticsearchSnapshotModel.php | 17 +++- src/Model/ElasticsearchUserModel.php | 1 + .../ElasticsearchRoleUserModelTrait.php | 18 +++- .../MappingsSettingsAliasesModelTrait.php | 54 +++++++++-- .../ElasticsearchIlmControllerTest.php | 2 +- .../ElasticsearchIndexControllerTest.php | 4 +- .../ElasticsearchPipelineControllerTest.php | 4 +- ...lasticsearchComponentTemplateModelTest.php | 8 +- .../Model/ElasticsearchIlmPolicyModelTest.php | 9 +- tests/Model/ElasticsearchIndexModelTest.php | 6 +- ...sticsearchIndexTemplateLegacyModelTest.php | 6 +- .../ElasticsearchIndexTemplateModelTest.php | 8 +- .../Model/ElasticsearchPipelineModelTest.php | 4 +- tests/Model/ElasticsearchRoleModelTest.php | 2 + 32 files changed, 399 insertions(+), 398 deletions(-) delete mode 100644 src/Form/EventListener/MappingsSettingsAliasesSubscriber.php delete mode 100644 src/Form/EventListener/MetadataSubscriber.php diff --git a/src/Controller/ElasticsearchIndexController.php b/src/Controller/ElasticsearchIndexController.php index 16a56ec6..0a4a47d9 100644 --- a/src/Controller/ElasticsearchIndexController.php +++ b/src/Controller/ElasticsearchIndexController.php @@ -341,11 +341,11 @@ public function create(Request $request): Response if ($form->isSubmitted() && $form->isValid()) { try { $json = []; - if ($index->getSettings()) { - $json['settings'] = $index->getSettings(); + if ($index->getSettingsJson()) { + $json['settings'] = json_decode($index->getSettingsJson(), true); } - if ($index->getMappings()) { - $json['mappings'] = $index->getMappings(); + if ($index->getMappingsJson()) { + $json['mappings'] = json_decode($index->getMappingsJson(), true); } $callRequest = new CallRequestModel(); $callRequest->setMethod('PUT'); @@ -406,8 +406,8 @@ public function update(Request $request, string $index): Response if ($form->isSubmitted() && $form->isValid()) { try { - if ($index->getMappings()) { - $json = $index->getMappings(); + if ($index->getMappingsJson()) { + $json = json_decode($index->getMappingsJson(), true); $callRequest = new CallRequestModel(); $callRequest->setMethod('PUT'); $callRequest->setPath('/'.$index->getName().'/_mapping'); diff --git a/src/Form/EventListener/MappingsSettingsAliasesSubscriber.php b/src/Form/EventListener/MappingsSettingsAliasesSubscriber.php deleted file mode 100644 index 6592762a..00000000 --- a/src/Form/EventListener/MappingsSettingsAliasesSubscriber.php +++ /dev/null @@ -1,64 +0,0 @@ - 'postSetData', - FormEvents::POST_SUBMIT => 'postSubmit', - ]; - } - - public function postSetData(FormEvent $event): void - { - $form = $event->getForm(); - - if ($form->has('mappings') && $form->get('mappings')->getData()) { - $fieldOptions = $form->get('mappings')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('mappings')->getData(), JSON_PRETTY_PRINT); - $form->add('mappings', TextareaType::class, $fieldOptions); - } - - if ($form->has('settings') && $form->get('settings')->getData()) { - $fieldOptions = $form->get('settings')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('settings')->getData(), JSON_PRETTY_PRINT); - $form->add('settings', TextareaType::class, $fieldOptions); - } - - if ($form->has('aliases') && $form->get('aliases')->getData()) { - $fieldOptions = $form->get('aliases')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('aliases')->getData(), JSON_PRETTY_PRINT); - $form->add('aliases', TextareaType::class, $fieldOptions); - } - } - - public function postSubmit(FormEvent $event): void - { - $form = $event->getForm(); - $data = $event->getData(); - - if ($form->has('mappings') && $form->get('mappings')->getData()) { - $data->setMappings(json_decode($form->get('mappings')->getData(), true)); - $event->setData($data); - } - - if ($form->has('settings') && $form->get('settings')->getData()) { - $data->setSettings(json_decode($form->get('settings')->getData(), true)); - $event->setData($data); - } - - if ($form->has('aliases') && $form->get('aliases')->getData()) { - $data->setAliases(json_decode($form->get('aliases')->getData(), true)); - $event->setData($data); - } - } -} diff --git a/src/Form/EventListener/MetadataSubscriber.php b/src/Form/EventListener/MetadataSubscriber.php deleted file mode 100644 index 94adb33f..00000000 --- a/src/Form/EventListener/MetadataSubscriber.php +++ /dev/null @@ -1,42 +0,0 @@ - 'postSetData', - FormEvents::POST_SUBMIT => 'postSubmit', - ]; - } - - public function postSetData(FormEvent $event): void - { - $form = $event->getForm(); - - if ($form->has('metadata') && $form->get('metadata')->getData()) { - $fieldOptions = $form->get('metadata')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('metadata')->getData(), JSON_PRETTY_PRINT); - $form->add('metadata', TextareaType::class, $fieldOptions); - } - } - - public function postSubmit(FormEvent $event): void - { - $form = $event->getForm(); - $data = $event->getData(); - - if ($form->has('metadata') && $form->get('metadata')->getData()) { - $data->setMetadata(json_decode($form->get('metadata')->getData(), true)); - $event->setData($data); - } - } -} diff --git a/src/Form/Type/ElasticsearchComponentTemplateType.php b/src/Form/Type/ElasticsearchComponentTemplateType.php index d4f1a588..d5f070c4 100644 --- a/src/Form/Type/ElasticsearchComponentTemplateType.php +++ b/src/Form/Type/ElasticsearchComponentTemplateType.php @@ -3,8 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MappingsSettingsAliasesSubscriber; -use App\Form\EventListener\MetadataSubscriber; use App\Manager\ElasticsearchComponentTemplateManager; use App\Model\CallRequestModel; use App\Model\ElasticsearchComponentTemplateModel; @@ -43,10 +41,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $fields[] = 'name'; } $fields[] = 'version'; - $fields[] = 'settings'; - $fields[] = 'mappings'; - $fields[] = 'aliases'; - $fields[] = 'metadata'; + $fields[] = 'settings_json'; + $fields[] = 'mappings_json'; + $fields[] = 'aliases_json'; + $fields[] = 'metadata_json'; foreach ($fields as $field) { switch ($field) { @@ -76,8 +74,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'settings': - $builder->add('settings', TextareaType::class, [ + case 'settings_json': + $builder->add('settings_json', TextareaType::class, [ 'label' => 'settings', 'required' => false, 'constraints' => [ @@ -87,8 +85,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'mappings': - $builder->add('mappings', TextareaType::class, [ + case 'mappings_json': + $builder->add('mappings_json', TextareaType::class, [ 'label' => 'mappings', 'required' => false, 'constraints' => [ @@ -101,8 +99,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'aliases': - $builder->add('aliases', TextareaType::class, [ + case 'aliases_json': + $builder->add('aliases_json', TextareaType::class, [ 'label' => 'aliases', 'required' => false, 'constraints' => [ @@ -112,8 +110,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'metadata': - $builder->add('metadata', TextareaType::class, [ + case 'metadata_json': + $builder->add('metadata_json', TextareaType::class, [ 'label' => 'metadata', 'required' => false, 'constraints' => [ @@ -141,9 +139,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MappingsSettingsAliasesSubscriber()); - $builder->addEventSubscriber(new MetadataSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchIlmPolicyType.php b/src/Form/Type/ElasticsearchIlmPolicyType.php index a38148f2..0fcc397d 100644 --- a/src/Form/Type/ElasticsearchIlmPolicyType.php +++ b/src/Form/Type/ElasticsearchIlmPolicyType.php @@ -38,10 +38,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void if ('create' == $options['context']) { $fields[] = 'name'; } - $fields[] = 'hot'; - $fields[] = 'warm'; - $fields[] = 'cold'; - $fields[] = 'delete'; + $fields[] = 'hot_json'; + $fields[] = 'warm_json'; + $fields[] = 'cold_json'; + $fields[] = 'delete_json'; foreach ($fields as $field) { switch ($field) { @@ -56,8 +56,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'hot': - $builder->add('hot', TextareaType::class, [ + case 'hot_json': + $builder->add('hot_json', TextareaType::class, [ 'label' => 'hot', 'required' => false, 'constraints' => [ @@ -67,8 +67,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'warm': - $builder->add('warm', TextareaType::class, [ + case 'warm_json': + $builder->add('warm_json', TextareaType::class, [ 'label' => 'warm', 'required' => false, 'constraints' => [ @@ -81,8 +81,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'cold': - $builder->add('cold', TextareaType::class, [ + case 'cold_json': + $builder->add('cold_json', TextareaType::class, [ 'label' => 'cold', 'required' => false, 'constraints' => [ @@ -92,8 +92,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'delete': - $builder->add('delete', TextareaType::class, [ + case 'delete_json': + $builder->add('delete_json', TextareaType::class, [ 'label' => 'delete', 'required' => false, 'constraints' => [ @@ -106,34 +106,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } - $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { - $form = $event->getForm(); - - if ($form->has('hot') && $form->get('hot')->getData()) { - $fieldOptions = $form->get('hot')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('hot')->getData(), JSON_PRETTY_PRINT); - $form->add('hot', TextareaType::class, $fieldOptions); - } - - if ($form->has('warm') && $form->get('warm')->getData()) { - $fieldOptions = $form->get('warm')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('warm')->getData(), JSON_PRETTY_PRINT); - $form->add('warm', TextareaType::class, $fieldOptions); - } - - if ($form->has('cold') && $form->get('cold')->getData()) { - $fieldOptions = $form->get('cold')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('cold')->getData(), JSON_PRETTY_PRINT); - $form->add('cold', TextareaType::class, $fieldOptions); - } - - if ($form->has('delete') && $form->get('delete')->getData()) { - $fieldOptions = $form->get('delete')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('delete')->getData(), JSON_PRETTY_PRINT); - $form->add('delete', TextareaType::class, $fieldOptions); - } - }); - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($options) { $form = $event->getForm(); $data = $event->getData(); @@ -149,26 +121,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } } - - if ($form->has('hot') && $form->get('hot')->getData()) { - $data->setHot(json_decode($form->get('hot')->getData(), true)); - $event->setData($data); - } - - if ($form->has('warm') && $form->get('warm')->getData()) { - $data->setWarm(json_decode($form->get('warm')->getData(), true)); - $event->setData($data); - } - - if ($form->has('cold') && $form->get('cold')->getData()) { - $data->setCold(json_decode($form->get('cold')->getData(), true)); - $event->setData($data); - } - - if ($form->has('delete') && $form->get('delete')->getData()) { - $data->setDelete(json_decode($form->get('delete')->getData(), true)); - $event->setData($data); - } }); } diff --git a/src/Form/Type/ElasticsearchIndexTemplateLegacyType.php b/src/Form/Type/ElasticsearchIndexTemplateLegacyType.php index ab1ea7ea..d07a0068 100644 --- a/src/Form/Type/ElasticsearchIndexTemplateLegacyType.php +++ b/src/Form/Type/ElasticsearchIndexTemplateLegacyType.php @@ -3,7 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MappingsSettingsAliasesSubscriber; use App\Manager\CallManager; use App\Manager\ElasticsearchIndexTemplateLegacyManager; use App\Model\CallRequestModel; @@ -53,9 +52,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } $fields[] = 'version'; $fields[] = 'order'; - $fields[] = 'settings'; - $fields[] = 'mappings'; - $fields[] = 'aliases'; + $fields[] = 'settings_json'; + $fields[] = 'mappings_json'; + $fields[] = 'aliases_json'; foreach ($fields as $field) { switch ($field) { @@ -117,8 +116,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'settings': - $builder->add('settings', TextareaType::class, [ + case 'settings_json': + $builder->add('settings_json', TextareaType::class, [ 'label' => 'settings', 'required' => false, 'constraints' => [ @@ -128,8 +127,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'mappings': - $builder->add('mappings', TextareaType::class, [ + case 'mappings_json': + $builder->add('mappings_json', TextareaType::class, [ 'label' => 'mappings', 'required' => false, 'constraints' => [ @@ -142,8 +141,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'aliases': - $builder->add('aliases', TextareaType::class, [ + case 'aliases_json': + $builder->add('aliases_json', TextareaType::class, [ 'label' => 'aliases', 'required' => false, 'constraints' => [ @@ -171,8 +170,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MappingsSettingsAliasesSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchIndexTemplateType.php b/src/Form/Type/ElasticsearchIndexTemplateType.php index 38dc0666..3dea6fab 100644 --- a/src/Form/Type/ElasticsearchIndexTemplateType.php +++ b/src/Form/Type/ElasticsearchIndexTemplateType.php @@ -3,8 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MappingsSettingsAliasesSubscriber; -use App\Form\EventListener\MetadataSubscriber; use App\Manager\CallManager; use App\Manager\ElasticsearchIndexTemplateManager; use App\Model\CallRequestModel; @@ -55,10 +53,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $fields[] = 'data_stream'; } $fields[] = 'composed_of'; - $fields[] = 'settings'; - $fields[] = 'mappings'; - $fields[] = 'aliases'; - $fields[] = 'metadata'; + $fields[] = 'settings_json'; + $fields[] = 'mappings_json'; + $fields[] = 'aliases_json'; + $fields[] = 'metadata_json'; foreach ($fields as $field) { switch ($field) { @@ -131,8 +129,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'settings': - $builder->add('settings', TextareaType::class, [ + case 'settings_json': + $builder->add('settings_json', TextareaType::class, [ 'label' => 'settings', 'required' => false, 'constraints' => [ @@ -142,8 +140,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'mappings': - $builder->add('mappings', TextareaType::class, [ + case 'mappings_json': + $builder->add('mappings_json', TextareaType::class, [ 'label' => 'mappings', 'required' => false, 'constraints' => [ @@ -156,8 +154,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'aliases': - $builder->add('aliases', TextareaType::class, [ + case 'aliases_json': + $builder->add('aliases_json', TextareaType::class, [ 'label' => 'aliases', 'required' => false, 'constraints' => [ @@ -167,8 +165,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'metadata': - $builder->add('metadata', TextareaType::class, [ + case 'metadata_json': + $builder->add('metadata_json', TextareaType::class, [ 'label' => 'metadata', 'required' => false, 'constraints' => [ @@ -196,9 +194,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MappingsSettingsAliasesSubscriber()); - $builder->addEventSubscriber(new MetadataSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchIndexType.php b/src/Form/Type/ElasticsearchIndexType.php index c1fa7e7d..3c3a3f4c 100644 --- a/src/Form/Type/ElasticsearchIndexType.php +++ b/src/Form/Type/ElasticsearchIndexType.php @@ -3,7 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MappingsSettingsAliasesSubscriber; use App\Manager\ElasticsearchIndexManager; use App\Model\CallRequestModel; use App\Model\ElasticsearchIndexModel; @@ -38,9 +37,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void if ('create' == $options['context']) { $fields[] = 'name'; - $fields[] = 'settings'; + $fields[] = 'settings_json'; } - $fields[] = 'mappings'; + $fields[] = 'mappings_json'; foreach ($fields as $field) { switch ($field) { @@ -56,8 +55,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); break; - case 'settings': - $builder->add('settings', TextareaType::class, [ + case 'settings_json': + $builder->add('settings_json', TextareaType::class, [ 'label' => 'settings', 'required' => false, 'constraints' => [ @@ -65,8 +64,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); break; - case 'mappings': - $builder->add('mappings', TextareaType::class, [ + case 'mappings_json': + $builder->add('mappings_json', TextareaType::class, [ 'label' => 'mappings', 'required' => false, 'constraints' => [ @@ -95,8 +94,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MappingsSettingsAliasesSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchPipelineType.php b/src/Form/Type/ElasticsearchPipelineType.php index cba8ed20..2bc1f34e 100644 --- a/src/Form/Type/ElasticsearchPipelineType.php +++ b/src/Form/Type/ElasticsearchPipelineType.php @@ -42,8 +42,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } $fields[] = 'description'; $fields[] = 'version'; - $fields[] = 'processors'; - $fields[] = 'on_failure'; + $fields[] = 'processors_json'; + $fields[] = 'on_failure_json'; foreach ($fields as $field) { switch ($field) { @@ -78,8 +78,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); break; - case 'processors': - $builder->add('processors', TextareaType::class, [ + case 'processors_json': + $builder->add('processors_json', TextareaType::class, [ 'label' => 'processors', 'required' => true, 'constraints' => [ @@ -93,8 +93,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'on_failure': - $builder->add('on_failure', TextareaType::class, [ + case 'on_failure_json': + $builder->add('on_failure_json', TextareaType::class, [ 'label' => 'on_failure', 'required' => false, 'constraints' => [ @@ -107,22 +107,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } - $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { - $form = $event->getForm(); - - if ($form->has('processors') && $form->get('processors')->getData()) { - $fieldOptions = $form->get('processors')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('processors')->getData(), JSON_PRETTY_PRINT); - $form->add('processors', TextareaType::class, $fieldOptions); - } - - if ($form->has('on_failure') && $form->get('on_failure')->getData()) { - $fieldOptions = $form->get('on_failure')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('on_failure')->getData(), JSON_PRETTY_PRINT); - $form->add('on_failure', TextareaType::class, $fieldOptions); - } - }); - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($options) { $form = $event->getForm(); $data = $event->getData(); @@ -138,16 +122,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } } - - if ($form->has('processors') && $form->get('processors')->getData()) { - $data->setProcessors(json_decode($form->get('processors')->getData(), true)); - $event->setData($data); - } - - if ($form->has('on_failure') && $form->get('on_failure')->getData()) { - $data->setOnFailure(json_decode($form->get('on_failure')->getData(), true)); - $event->setData($data); - } }); } diff --git a/src/Form/Type/ElasticsearchRoleType.php b/src/Form/Type/ElasticsearchRoleType.php index 55a5be1d..f0770d68 100644 --- a/src/Form/Type/ElasticsearchRoleType.php +++ b/src/Form/Type/ElasticsearchRoleType.php @@ -3,7 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MetadataSubscriber; use App\Manager\ElasticsearchRoleManager; use App\Model\CallRequestModel; use App\Model\ElasticsearchRoleModel; @@ -42,9 +41,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } $fields[] = 'cluster'; $fields[] = 'run_as'; - $fields[] = 'indices'; - $fields[] = 'applications'; - $fields[] = 'metadata'; + $fields[] = 'indices_json'; + $fields[] = 'applications_json'; + $fields[] = 'metadata_json'; foreach ($fields as $field) { switch ($field) { @@ -90,8 +89,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'indices': - $builder->add('indices', TextareaType::class, [ + case 'indices_json': + $builder->add('indices_json', TextareaType::class, [ 'label' => 'indices', 'required' => false, 'constraints' => [ @@ -101,8 +100,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'applications': - $builder->add('applications', TextareaType::class, [ + case 'applications_json': + $builder->add('applications_json', TextareaType::class, [ 'label' => 'applications', 'required' => false, 'constraints' => [ @@ -115,8 +114,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'help_html' => true, ]); break; - case 'metadata': - $builder->add('metadata', TextareaType::class, [ + case 'metadata_json': + $builder->add('metadata_json', TextareaType::class, [ 'label' => 'metadata', 'required' => false, 'constraints' => [ @@ -129,22 +128,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } - $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { - $form = $event->getForm(); - - if ($form->has('indices') && $form->get('indices')->getData()) { - $fieldOptions = $form->get('indices')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('indices')->getData(), JSON_PRETTY_PRINT); - $form->add('indices', TextareaType::class, $fieldOptions); - } - - if ($form->has('applications') && $form->get('applications')->getData()) { - $fieldOptions = $form->get('applications')->getConfig()->getOptions(); - $fieldOptions['data'] = json_encode($form->get('applications')->getData(), JSON_PRETTY_PRINT); - $form->add('applications', TextareaType::class, $fieldOptions); - } - }); - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($options) { $form = $event->getForm(); $data = $event->getData(); @@ -160,19 +143,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } } - - if ($form->has('indices') && $form->get('indices')->getData()) { - $data->setIndices(json_decode($form->get('indices')->getData(), true)); - $event->setData($data); - } - - if ($form->has('applications') && $form->get('applications')->getData()) { - $data->setApplications(json_decode($form->get('applications')->getData(), true)); - $event->setData($data); - } }); - - $builder->addEventSubscriber(new MetadataSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/ElasticsearchUserType.php b/src/Form/Type/ElasticsearchUserType.php index 37cfa5b4..2340def2 100644 --- a/src/Form/Type/ElasticsearchUserType.php +++ b/src/Form/Type/ElasticsearchUserType.php @@ -3,7 +3,6 @@ namespace App\Form\Type; -use App\Form\EventListener\MetadataSubscriber; use App\Manager\ElasticsearchUserManager; use App\Model\CallRequestModel; use App\Model\ElasticsearchUserModel; @@ -50,7 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $fields[] = 'email'; $fields[] = 'full_name'; $fields[] = 'roles'; - $fields[] = 'metadata'; + $fields[] = 'metadata_json'; foreach ($fields as $field) { switch ($field) { @@ -132,8 +131,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); break; - case 'metadata': - $builder->add('metadata', TextareaType::class, [ + case 'metadata_json': + $builder->add('metadata_json', TextareaType::class, [ 'label' => 'metadata', 'required' => false, 'constraints' => [ @@ -159,8 +158,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } }); - - $builder->addEventSubscriber(new MetadataSubscriber()); } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Model/ElasticsearchComponentTemplateModel.php b/src/Model/ElasticsearchComponentTemplateModel.php index 8a721da4..c649e4ae 100644 --- a/src/Model/ElasticsearchComponentTemplateModel.php +++ b/src/Model/ElasticsearchComponentTemplateModel.php @@ -13,7 +13,9 @@ class ElasticsearchComponentTemplateModel extends AbstractAppModel private $version; - private $metadata; + private ?array $metadata = null; + + private ?string $metadataJson = null; public function getName(): ?string { @@ -44,13 +46,25 @@ public function getMetadata(): ?array return $this->metadata; } - public function setMetadata($metadata): self + public function setMetadata(?array $metadata): self { $this->metadata = $metadata; return $this; } + public function getMetadataJson(): ?string + { + return $this->metadataJson; + } + + public function setMetadataJson(?string $metadataJson): self + { + $this->metadataJson = $metadataJson; + + return $this; + } + public function isManaged(): ?bool { return true === isset($this->getMetadata()['managed']) && true === $this->getMetadata()['managed']; @@ -69,15 +83,19 @@ public function convert(?array $template): self } if (true === isset($template['component_template']['template']['settings']) && 0 < count($template['component_template']['template']['settings'])) { $this->setSettings($template['component_template']['template']['settings']); + $this->setSettingsJson(json_encode($template['component_template']['template']['settings'], JSON_PRETTY_PRINT)); } if (true === isset($template['component_template']['template']['mappings']) && 0 < count($template['component_template']['template']['mappings'])) { $this->setMappings($template['component_template']['template']['mappings']); + $this->setMappingsJson(json_encode($template['component_template']['template']['mappings'], JSON_PRETTY_PRINT)); } if (true === isset($template['component_template']['template']['aliases']) && 0 < count($template['component_template']['template']['aliases'])) { $this->setAliases($template['component_template']['template']['aliases']); + $this->setAliasesJson(json_encode($template['component_template']['template']['aliases'], JSON_PRETTY_PRINT)); } if (true === isset($template['component_template']['_meta']) && 0 < count($template['component_template']['_meta'])) { $this->setMetadata($template['component_template']['_meta']); + $this->setMetadataJson(json_encode($template['component_template']['_meta'], JSON_PRETTY_PRINT)); } return $this; @@ -93,20 +111,20 @@ public function getJson(): array $json['version'] = $this->getVersion(); } - if ($this->getSettings()) { - $json['template']['settings'] = $this->getSettings(); + if ($this->getSettingsJson()) { + $json['template']['settings'] = json_decode($this->getSettingsJson(), true); } - if ($this->getMappings()) { - $json['template']['mappings'] = $this->getMappings(); + if ($this->getMappingsJson()) { + $json['template']['mappings'] = json_decode($this->getMappingsJson(), true); } - if ($this->getAliases()) { - $json['template']['aliases'] = $this->getAliases(); + if ($this->getAliasesJson()) { + $json['template']['aliases'] = json_decode($this->getAliasesJson(), true); } - if ($this->getMetadata()) { - $json['_meta'] = $this->getMetadata(); + if ($this->getMetadataJson()) { + $json['_meta'] = json_decode($this->getMetadataJson(), true); } if (0 == count($json['template'])) { diff --git a/src/Model/ElasticsearchIlmPolicyModel.php b/src/Model/ElasticsearchIlmPolicyModel.php index 6a637486..9df1cc32 100644 --- a/src/Model/ElasticsearchIlmPolicyModel.php +++ b/src/Model/ElasticsearchIlmPolicyModel.php @@ -12,13 +12,21 @@ class ElasticsearchIlmPolicyModel extends AbstractAppModel private $modifiedDate; - private $hot; + private ?array $hot = null; - private $warm; + private ?string $hotJson = null; - private $cold; + private ?array $warm = null; - private $delete; + private ?string $warmJson = null; + + private ?array $cold = null; + + private ?string $coldJson = null; + + private ?array $delete = null; + + private ?string $deleteJson = null; private $phases; @@ -63,49 +71,97 @@ public function getHot(): ?array return $this->hot; } - public function setHot($hot): self + public function setHot(?array $hot): self { $this->hot = $hot; return $this; } + public function getHotJson(): ?string + { + return $this->hotJson; + } + + public function setHotJson(?string $hotJson): self + { + $this->hotJson = $hotJson; + + return $this; + } + public function getWarm(): ?array { return $this->warm; } - public function setWarm($warm): self + public function setWarm(?array $warm): self { $this->warm = $warm; return $this; } + public function getWarmJson(): ?string + { + return $this->warmJson; + } + + public function setWarmJson(?string $warmJson): self + { + $this->warmJson = $warmJson; + + return $this; + } + public function getCold(): ?array { return $this->cold; } - public function setCold($cold): self + public function setCold(?array $cold): self { $this->cold = $cold; return $this; } + public function getColdJson(): ?string + { + return $this->coldJson; + } + + public function setColdJson(?string $coldJson): self + { + $this->coldJson = $coldJson; + + return $this; + } + public function getDelete(): ?array { return $this->delete; } - public function setDelete($delete): self + public function setDelete(?array $delete): self { $this->delete = $delete; return $this; } + public function getDeleteJson(): ?string + { + return $this->deleteJson; + } + + public function setDeleteJson(?string $deleteJson): self + { + $this->deleteJson = $deleteJson; + + return $this; + } + public function getPhases(): ?array { return $this->phases; @@ -140,15 +196,19 @@ public function convert(?array $policy): self if (true === isset($policy['policy']['phases']['hot'])) { $this->setHot($policy['policy']['phases']['hot']); + $this->setHotJson(json_encode($policy['policy']['phases']['hot'], JSON_PRETTY_PRINT)); } if (true === isset($policy['policy']['phases']['warm'])) { $this->setWarm($policy['policy']['phases']['warm']); + $this->setWarmJson(json_encode($policy['policy']['phases']['warm'], JSON_PRETTY_PRINT)); } if (true === isset($policy['policy']['phases']['cold'])) { $this->setCold($policy['policy']['phases']['cold']); + $this->setColdJson(json_encode($policy['policy']['phases']['cold'], JSON_PRETTY_PRINT)); } if (true === isset($policy['policy']['phases']['delete'])) { $this->setDelete($policy['policy']['phases']['delete']); + $this->setDeleteJson(json_encode($policy['policy']['phases']['delete'], JSON_PRETTY_PRINT)); } } @@ -163,20 +223,20 @@ public function getJson(): array ], ]; - if ($this->getHot()) { - $json['policy']['phases']['hot'] = $this->getHot(); + if ($this->getHotJson()) { + $json['policy']['phases']['hot'] = json_decode($this->getHotJson(), true); } - if ($this->getWarm()) { - $json['policy']['phases']['warm'] = $this->getWarm(); + if ($this->getWarmJson()) { + $json['policy']['phases']['warm'] = json_decode($this->getWarmJson(), true); } - if ($this->getCold()) { - $json['policy']['phases']['cold'] = $this->getCold(); + if ($this->getColdJson()) { + $json['policy']['phases']['cold'] = json_decode($this->getColdJson(), true); } - if ($this->getDelete()) { - $json['policy']['phases']['delete'] = $this->getDelete(); + if ($this->getDeleteJson()) { + $json['policy']['phases']['delete'] = json_decode($this->getDeleteJson(), true); } return $json; diff --git a/src/Model/ElasticsearchIndexModel.php b/src/Model/ElasticsearchIndexModel.php index 1d1934f5..778c76be 100644 --- a/src/Model/ElasticsearchIndexModel.php +++ b/src/Model/ElasticsearchIndexModel.php @@ -281,10 +281,12 @@ public function convert(?array $index): self if (true === isset($index['settings']) && 0 < count($index['settings'])) { $this->setSettings($index['settings']); + $this->setSettingsJson(json_encode($index['settings'], JSON_PRETTY_PRINT)); } if (true === isset($index['mappings']) && 0 < count($index['mappings'])) { $this->setMappings($index['mappings']); + $this->setMappingsJson(json_encode($index['mappings'], JSON_PRETTY_PRINT)); } if (true === isset($index['mappings_flat']) && 0 < count($index['mappings_flat'])) { diff --git a/src/Model/ElasticsearchIndexTemplateLegacyModel.php b/src/Model/ElasticsearchIndexTemplateLegacyModel.php index ab3c27e4..7b2b2c32 100644 --- a/src/Model/ElasticsearchIndexTemplateLegacyModel.php +++ b/src/Model/ElasticsearchIndexTemplateLegacyModel.php @@ -142,16 +142,16 @@ public function getJson(): array $json['order'] = $this->getOrder(); } - if ($this->getSettings()) { - $json['settings'] = $this->getSettings(); + if ($this->getSettingsJson()) { + $json['settings'] = json_decode($this->getSettingsJson(), true); } - if ($this->getMappings()) { - $json['mappings'] = $this->getMappings(); + if ($this->getMappingsJson()) { + $json['mappings'] = json_decode($this->getMappingsJson(), true); } - if ($this->getAliases()) { - $json['aliases'] = $this->getAliases(); + if ($this->getAliasesJson()) { + $json['aliases'] = json_decode($this->getAliasesJson(), true); } return $json; diff --git a/src/Model/ElasticsearchIndexTemplateModel.php b/src/Model/ElasticsearchIndexTemplateModel.php index e51582fb..b46f061a 100644 --- a/src/Model/ElasticsearchIndexTemplateModel.php +++ b/src/Model/ElasticsearchIndexTemplateModel.php @@ -19,7 +19,9 @@ class ElasticsearchIndexTemplateModel extends AbstractAppModel private $composedOf; - private $metadata; + private ?array $metadata = null; + + private ?string $metadataJson = null; private $dataStream; @@ -88,13 +90,25 @@ public function getMetadata(): ?array return $this->metadata; } - public function setMetadata($metadata): self + public function setMetadata(?array $metadata): self { $this->metadata = $metadata; return $this; } + public function getMetadataJson(): ?string + { + return $this->metadataJson; + } + + public function setMetadataJson(?string $metadataJson): self + { + $this->metadataJson = $metadataJson; + + return $this; + } + public function getDataStream(): ?bool { return $this->dataStream; @@ -154,6 +168,7 @@ public function convert(?array $template): self } if (true === isset($template['index_template']['_meta']) && 0 < count($template['index_template']['_meta'])) { $this->setMetadata($template['index_template']['_meta']); + $this->setMetadataJson(json_encode($template['index_template']['_meta'], JSON_PRETTY_PRINT)); } if (true === isset($template['index_template']['data_stream'])) { $this->setDataStream(true); @@ -181,24 +196,24 @@ public function getJson(): array $json['composed_of'] = $this->getComposedOf(); } - if ($this->getSettings() || $this->getMappings() || $this->getAliases()) { + if ($this->getSettingsJson() || $this->getMappingsJson() || $this->getAliasesJson()) { $json['template'] = []; } - if ($this->getSettings()) { - $json['template']['settings'] = $this->getSettings(); + if ($this->getSettingsJson()) { + $json['template']['settings'] = json_decode($this->getSettingsJson(), true); } - if ($this->getMappings()) { - $json['template']['mappings'] = $this->getMappings(); + if ($this->getMappingsJson()) { + $json['template']['mappings'] = json_decode($this->getMappingsJson(), true); } - if ($this->getAliases()) { - $json['template']['aliases'] = $this->getAliases(); + if ($this->getAliasesJson()) { + $json['template']['aliases'] = json_decode($this->getAliasesJson(), true); } - if ($this->getMetadata()) { - $json['_meta'] = $this->getMetadata(); + if ($this->getMetadataJson()) { + $json['_meta'] = json_decode($this->getMetadataJson(), true); } if ($this->getDataStream()) { diff --git a/src/Model/ElasticsearchPipelineModel.php b/src/Model/ElasticsearchPipelineModel.php index 7e9af2dd..c48ee9f7 100644 --- a/src/Model/ElasticsearchPipelineModel.php +++ b/src/Model/ElasticsearchPipelineModel.php @@ -12,9 +12,13 @@ class ElasticsearchPipelineModel extends AbstractAppModel private $description; - private $processors; + private ?array $processors = null; - private $onFailure; + private ?string $processorsJson = null; + + private ?array $onFailure = null; + + private ?string $onFailureJson = null; public function getName(): ?string { @@ -57,25 +61,49 @@ public function getProcessors(): ?array return $this->processors; } - public function setProcessors($processors): self + public function setProcessors(?array $processors): self { $this->processors = $processors; return $this; } + public function getProcessorsJson(): ?string + { + return $this->processorsJson; + } + + public function setProcessorsJson(?string $processorsJson): self + { + $this->processorsJson = $processorsJson; + + return $this; + } + public function getOnFailure(): ?array { return $this->onFailure; } - public function setOnFailure($onFailure): self + public function setOnFailure(?array $onFailure): self { $this->onFailure = $onFailure; return $this; } + public function getOnFailureJson(): ?string + { + return $this->onFailureJson; + } + + public function setOnFailureJson(?string $onFailureJson): self + { + $this->onFailureJson = $onFailureJson; + + return $this; + } + public function isSystem(): ?bool { return '.' == substr($this->getName(), 0, 1); @@ -92,9 +120,11 @@ public function convert(?array $pipeline): self } if (true === isset($pipeline['processors']) && 0 < count($pipeline['processors'])) { $this->setProcessors($pipeline['processors']); + $this->setProcessorsJson(json_encode($pipeline['processors'], JSON_PRETTY_PRINT)); } if (true === isset($pipeline['on_failure']) && 0 < count($pipeline['on_failure'])) { $this->setOnFailure($pipeline['on_failure']); + $this->setOnFailureJson(json_encode($pipeline['on_failure'], JSON_PRETTY_PRINT)); } return $this; } @@ -102,7 +132,7 @@ public function convert(?array $pipeline): self public function getJson(): array { $json = [ - 'processors' => $this->getProcessors(), + 'processors' => json_decode($this->getProcessorsJson(), true), ]; if ($this->getVersion()) { @@ -113,8 +143,8 @@ public function getJson(): array $json['description'] = $this->getDescription(); } - if ($this->getOnFailure()) { - $json['on_failure'] = $this->getOnFailure(); + if ($this->getOnFailureJson()) { + $json['on_failure'] = json_decode($this->getOnFailureJson(), true); } return $json; diff --git a/src/Model/ElasticsearchRoleModel.php b/src/Model/ElasticsearchRoleModel.php index 85aeb03a..737f802b 100644 --- a/src/Model/ElasticsearchRoleModel.php +++ b/src/Model/ElasticsearchRoleModel.php @@ -11,11 +11,15 @@ class ElasticsearchRoleModel extends AbstractAppModel private $name; - private $applications; + private ?array $applications = null; + + private ?string $applicationsJson = null; private $cluster; - private $indices; + private ?array $indices = null; + + private ?string $indicesJson = null; private $runAs; @@ -36,13 +40,25 @@ public function getApplications(): ?array return $this->applications; } - public function setApplications($applications): self + public function setApplications(?array $applications): self { $this->applications = $applications; return $this; } + public function getApplicationsJson(): ?string + { + return $this->applicationsJson; + } + + public function setApplicationsJson(?string $applicationsJson): self + { + $this->applicationsJson = $applicationsJson; + + return $this; + } + public function getCluster(): ?array { return $this->cluster; @@ -60,13 +76,25 @@ public function getIndices(): ?array return $this->indices; } - public function setIndices($indices): self + public function setIndices(?array $indices): self { $this->indices = $indices; return $this; } + public function getIndicesJson(): ?string + { + return $this->indicesJson; + } + + public function setIndicesJson(?string $indicesJson): self + { + $this->indicesJson = $indicesJson; + + return $this; + } + public function getRunAs(): ?array { return $this->runAs; @@ -86,12 +114,15 @@ public function convert(?array $role): self $this->setRunAs($role['run_as']); if (true === isset($role['indices']) && 0 < count($role['indices'])) { $this->setIndices($role['indices']); + $this->setIndicesJson(json_encode($role['indices'], JSON_PRETTY_PRINT)); } if (true === isset($role['applications']) && 0 < count($role['applications'])) { $this->setApplications($role['applications']); + $this->setApplicationsJson(json_encode($role['applications'], JSON_PRETTY_PRINT)); } if (true === isset($role['metadata']) && 0 < count($role['metadata'])) { $this->setMetadata($role['metadata']); + $this->setMetadataJson(json_encode($role['metadata'], JSON_PRETTY_PRINT)); } return $this; } @@ -103,16 +134,16 @@ public function getJson(): array 'run_as' => $this->getRunAs(), ]; - if ($this->getApplications()) { - $json['applications'] = $this->getApplications(); + if ($this->getApplicationsJson()) { + $json['applications'] = json_decode($this->getApplicationsJson(), true); } - if ($this->getIndices()) { - $json['indices'] = $this->getIndices(); + if ($this->getIndicesJson()) { + $json['indices'] = json_decode($this->getIndicesJson(), true); } - if ($this->getMetadata()) { - $json['metadata'] = $this->getMetadata(); + if ($this->getMetadataJson()) { + $json['metadata'] = json_decode($this->getMetadataJson(), true); } return $json; diff --git a/src/Model/ElasticsearchSnapshotModel.php b/src/Model/ElasticsearchSnapshotModel.php index 3844ca44..b3cfb131 100644 --- a/src/Model/ElasticsearchSnapshotModel.php +++ b/src/Model/ElasticsearchSnapshotModel.php @@ -25,7 +25,9 @@ class ElasticsearchSnapshotModel extends AbstractAppModel private $duration; - private $metadata; + private ?array $metadata = null; + + private ?string $metadataJson = null; public function __construct() { @@ -140,6 +142,18 @@ public function setMetadata(?array $metadata): self return $this; } + public function getMetadataJson(): ?string + { + return $this->metadataJson; + } + + public function setMetadataJson(?string $metadataJson): self + { + $this->metadataJson = $metadataJson; + + return $this; + } + public function convert(?array $snapshot): self { $this->setName($snapshot['snapshot']); @@ -175,6 +189,7 @@ public function convert(?array $snapshot): self if (true === isset($snapshot['metadata'])) { $this->setMetadata($snapshot['metadata']); + $this->setMetadataJson(json_encode($snapshot['metadata'], JSON_PRETTY_PRINT)); } return $this; diff --git a/src/Model/ElasticsearchUserModel.php b/src/Model/ElasticsearchUserModel.php index 6812085a..bf9dfab9 100644 --- a/src/Model/ElasticsearchUserModel.php +++ b/src/Model/ElasticsearchUserModel.php @@ -123,6 +123,7 @@ public function convert(?array $user): self $this->setEnabled($user['enabled']); if (true === isset($user['metadata']) && 0 < count($user['metadata'])) { $this->setMetadata($user['metadata']); + $this->setMetadataJson(json_encode($user['metadata'], JSON_PRETTY_PRINT)); } return $this; } diff --git a/src/Traits/ElasticsearchRoleUserModelTrait.php b/src/Traits/ElasticsearchRoleUserModelTrait.php index d44d8156..120e6a1d 100644 --- a/src/Traits/ElasticsearchRoleUserModelTrait.php +++ b/src/Traits/ElasticsearchRoleUserModelTrait.php @@ -4,20 +4,34 @@ trait ElasticsearchRoleUserModelTrait { - private $metadata; + private ?array $metadata = null; + + private ?string $metadataJson = null; public function getMetadata(): ?array { return $this->metadata; } - public function setMetadata($metadata): self + public function setMetadata(?array $metadata): self { $this->metadata = $metadata; return $this; } + public function getMetadataJson(): ?string + { + return $this->metadataJson; + } + + public function setMetadataJson(?string $metadataJson): self + { + $this->metadataJson = $metadataJson; + + return $this; + } + public function isReserved(): ?bool { return true === isset($this->getMetadata()['_reserved']) && true === $this->getMetadata()['_reserved']; diff --git a/src/Traits/MappingsSettingsAliasesModelTrait.php b/src/Traits/MappingsSettingsAliasesModelTrait.php index 23d8bd07..0d60d507 100644 --- a/src/Traits/MappingsSettingsAliasesModelTrait.php +++ b/src/Traits/MappingsSettingsAliasesModelTrait.php @@ -4,24 +4,42 @@ trait MappingsSettingsAliasesModelTrait { - private $settings; + private ?array $settings = null; - private $mappings; + private ?string $settingsJson = null; - private $aliases; + private ?array $mappings = null; + + private ?string $mappingsJson = null; + + private ?array $aliases = null; + + private ?string $aliasesJson = null; public function getSettings(): ?array { return $this->settings; } - public function setSettings($settings): self + public function setSettings(?array $settings): self { $this->settings = $settings; return $this; } + public function getSettingsJson(): ?string + { + return $this->settingsJson; + } + + public function setSettingsJson(?string $settingsJson): self + { + $this->settingsJson = $settingsJson; + + return $this; + } + public function getSetting($key): ?string { return $this->settings[$key] ?? false; @@ -39,22 +57,46 @@ public function getMappings(): ?array return $this->mappings; } - public function setMappings($mappings): self + public function setMappings(?array $mappings): self { $this->mappings = $mappings; return $this; } + public function getMappingsJson(): ?string + { + return $this->mappingsJson; + } + + public function setMappingsJson(?string $mappingsJson): self + { + $this->mappingsJson = $mappingsJson; + + return $this; + } + public function getAliases(): ?array { return $this->aliases; } - public function setAliases($aliases): self + public function setAliases(?array $aliases): self { $this->aliases = $aliases; return $this; } + + public function getAliasesJson(): ?string + { + return $this->aliasesJson; + } + + public function setAliasesJson(?string $aliasesJson): self + { + $this->aliasesJson = $aliasesJson; + + return $this; + } } diff --git a/tests/Controller/ElasticsearchIlmControllerTest.php b/tests/Controller/ElasticsearchIlmControllerTest.php index e555e247..a87c004e 100644 --- a/tests/Controller/ElasticsearchIlmControllerTest.php +++ b/tests/Controller/ElasticsearchIlmControllerTest.php @@ -58,7 +58,7 @@ public function testCreate(): void $values = [ 'data[name]' => GENERATED_NAME, - 'data[hot]' => '{ + 'data[hot_json]' => '{ "min_age": "0ms", "actions": { "rollover": { diff --git a/tests/Controller/ElasticsearchIndexControllerTest.php b/tests/Controller/ElasticsearchIndexControllerTest.php index c57c5f05..937e7f91 100644 --- a/tests/Controller/ElasticsearchIndexControllerTest.php +++ b/tests/Controller/ElasticsearchIndexControllerTest.php @@ -64,7 +64,7 @@ public function testCreate(): void 'data[name]' => GENERATED_NAME, ]; if (true === $this->callManager->checkVersion('7.0')) { - $values['data[mappings]'] = file_get_contents(__DIR__.'/../../src/DataFixtures/es-test-mappings.json'); + $values['data[mappings_json]'] = file_get_contents(__DIR__.'/../../src/DataFixtures/es-test-mappings.json'); } $this->client->submitForm('Submit', $values); @@ -90,7 +90,7 @@ public function testCreateSystem(): void 'data[name]' => GENERATED_NAME_SYSTEM, ]; if (true === $this->callManager->checkVersion('7.0')) { - $values['data[mappings]'] = file_get_contents(__DIR__.'/../../src/DataFixtures/es-test-mappings.json'); + $values['data[mappings_json]'] = file_get_contents(__DIR__.'/../../src/DataFixtures/es-test-mappings.json'); } $this->client->submitForm('Submit', $values); diff --git a/tests/Controller/ElasticsearchPipelineControllerTest.php b/tests/Controller/ElasticsearchPipelineControllerTest.php index f31ee5e2..cc4bdb1e 100644 --- a/tests/Controller/ElasticsearchPipelineControllerTest.php +++ b/tests/Controller/ElasticsearchPipelineControllerTest.php @@ -41,7 +41,7 @@ public function testCreate(): void $values = [ 'data[name]' => GENERATED_NAME, - 'data[processors]' => '[]', + 'data[processors_json]' => '[]', ]; $this->client->submitForm('Submit', $values); @@ -79,7 +79,7 @@ public function testCreateCopy(): void $this->assertSelectorTextSame('h3', 'Create pipeline'); $values = [ - 'data[processors]' => '[]', + 'data[processors_json]' => '[]', ]; $this->client->submitForm('Submit', $values); diff --git a/tests/Model/ElasticsearchComponentTemplateModelTest.php b/tests/Model/ElasticsearchComponentTemplateModelTest.php index 556564fe..d5883094 100644 --- a/tests/Model/ElasticsearchComponentTemplateModelTest.php +++ b/tests/Model/ElasticsearchComponentTemplateModelTest.php @@ -12,15 +12,15 @@ public function test(): void $template = new ElasticsearchComponentTemplateModel(); $template->setName('name'); $template->setVersion(1); - $template->setSettings(''); $template->setSettings([]); + $template->setSettingsJson(json_encode([])); $template->setSetting('setting-key', 'setting-value'); - $template->setMappings(''); $template->setMappings(['mappings']); - $template->setAliases(''); + $template->setMappingsJson(json_encode(['mappings'])); $template->setAliases(['aliases']); - $template->setMetadata(''); + $template->setAliasesJson(json_encode(['aliases'])); $template->setMetadata(['metadata']); + $template->setMetadataJson(json_encode(['metadata'])); $this->assertEquals($template->getName(), 'name'); $this->assertEquals(strval($template), 'name'); diff --git a/tests/Model/ElasticsearchIlmPolicyModelTest.php b/tests/Model/ElasticsearchIlmPolicyModelTest.php index 5b05fd8e..f680b57d 100644 --- a/tests/Model/ElasticsearchIlmPolicyModelTest.php +++ b/tests/Model/ElasticsearchIlmPolicyModelTest.php @@ -12,16 +12,15 @@ public function test(): void $policy = new ElasticsearchIlmPolicyModel(); $policy->setName('name'); $policy->setVersion(1); - $policy->setPhases(''); $policy->setPhases(['phases']); - $policy->setHot(''); $policy->setHot(['hot']); - $policy->setWarm(''); + $policy->setHotJson(json_encode(['hot'])); $policy->setWarm(['warm']); - $policy->setCold(''); + $policy->setWarmJson(json_encode(['warm'])); $policy->setCold(['cold']); - $policy->setDelete(''); + $policy->setColdJson(json_encode(['cold'])); $policy->setDelete(['delete']); + $policy->setDeleteJson(json_encode(['delete'])); $this->assertEquals($policy->getName(), 'name'); $this->assertEquals(strval($policy), 'name'); diff --git a/tests/Model/ElasticsearchIndexModelTest.php b/tests/Model/ElasticsearchIndexModelTest.php index ffc4bd3e..e8502a5a 100644 --- a/tests/Model/ElasticsearchIndexModelTest.php +++ b/tests/Model/ElasticsearchIndexModelTest.php @@ -21,14 +21,14 @@ public function test(): void $index->setPrimarySize(5); $index->setTotalSize(6); $index->setCreationDate('creation-date'); - $index->setSettings(''); $index->setSettings([]); + $index->setSettingsJson(json_encode([])); $index->setSetting('setting-key', 'setting-value'); - $index->setMappings(''); $index->setMappings(['mappings']); + $index->setMappingsJson(json_encode(['mappings'])); $index->setMappingsFlat(['mapping-field' => ['type' => 'mapping-type']]); - $index->setAliases(''); $index->setAliases(['aliases']); + $index->setAliasesJson(json_encode(['aliases'])); $this->assertEquals($index->getName(), 'name'); $this->assertEquals(strval($index), 'name'); diff --git a/tests/Model/ElasticsearchIndexTemplateLegacyModelTest.php b/tests/Model/ElasticsearchIndexTemplateLegacyModelTest.php index 1fe50d0a..e541f002 100644 --- a/tests/Model/ElasticsearchIndexTemplateLegacyModelTest.php +++ b/tests/Model/ElasticsearchIndexTemplateLegacyModelTest.php @@ -15,13 +15,13 @@ public function test(): void $template->setTemplate('template'); $template->setVersion(1); $template->setOrder(2); - $template->setSettings(''); $template->setSettings([]); + $template->setSettingsJson(json_encode([])); $template->setSetting('setting-key', 'setting-value'); - $template->setMappings(''); $template->setMappings(['mappings']); - $template->setAliases(''); + $template->setMappingsJson(json_encode(['mappings'])); $template->setAliases(['aliases']); + $template->setAliasesJson(json_encode(['aliases'])); $this->assertEquals($template->getName(), 'name'); $this->assertEquals(strval($template), 'name'); diff --git a/tests/Model/ElasticsearchIndexTemplateModelTest.php b/tests/Model/ElasticsearchIndexTemplateModelTest.php index c8ea3d71..c4bf8242 100644 --- a/tests/Model/ElasticsearchIndexTemplateModelTest.php +++ b/tests/Model/ElasticsearchIndexTemplateModelTest.php @@ -14,15 +14,15 @@ public function test(): void $template->setIndexPatterns('index-patterns'); $template->setVersion(1); $template->setPriority(2); - $template->setSettings(''); $template->setSettings([]); + $template->setSettingsJson(json_encode([])); $template->setSetting('setting-key', 'setting-value'); - $template->setMappings(''); $template->setMappings(['mappings']); - $template->setAliases(''); + $template->setMappingsJson(json_encode(['mappings'])); $template->setAliases(['aliases']); - $template->setMetadata(''); + $template->setAliasesJson(json_encode(['aliases'])); $template->setMetadata(['metadata']); + $template->setMetadataJson(json_encode(['metadata'])); $template->setComposedOf(['composedof']); $template->setDataStream(true); diff --git a/tests/Model/ElasticsearchPipelineModelTest.php b/tests/Model/ElasticsearchPipelineModelTest.php index c4263b5c..ae97981a 100644 --- a/tests/Model/ElasticsearchPipelineModelTest.php +++ b/tests/Model/ElasticsearchPipelineModelTest.php @@ -13,10 +13,10 @@ public function test(): void $pipeline->setName('name'); $pipeline->setVersion(1); $pipeline->setDescription('description'); - $pipeline->setProcessors(''); $pipeline->setProcessors(['processors']); - $pipeline->setOnFailure(''); + $pipeline->setProcessorsJson(json_encode(['processors'])); $pipeline->setOnFailure(['onfailure']); + $pipeline->setOnFailureJson(json_encode(['onfailure'])); $this->assertEquals($pipeline->getName(), 'name'); $this->assertEquals(strval($pipeline), 'name'); diff --git a/tests/Model/ElasticsearchRoleModelTest.php b/tests/Model/ElasticsearchRoleModelTest.php index 5bf36a2a..f84d3a02 100644 --- a/tests/Model/ElasticsearchRoleModelTest.php +++ b/tests/Model/ElasticsearchRoleModelTest.php @@ -12,8 +12,10 @@ public function test(): void $role = new ElasticsearchRoleModel(); $role->setName('name'); $role->setApplications(['applications']); + $role->setApplicationsJson(json_encode(['applications'])); $role->setCluster(['cluster']); $role->setIndices(['indices']); + $role->setIndicesJson(json_encode(['indices'])); $role->setRunAs(['run-as']); $role->setMetadata(['metadata']); From 266112985c8576e2cf3ed998ab3987113e127bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Dion?= Date: Sat, 20 Nov 2021 16:26:35 +0100 Subject: [PATCH 3/3] - --- src/Command/GenerateFaviconsCommand.php | 2 +- src/Exception/CallException.php | 2 +- src/Exception/ConnectionException.php | 2 +- src/Manager/AppNotificationManager.php | 8 ++++---- src/Manager/ElasticsearchClusterManager.php | 8 ++++---- src/Manager/ElasticsearchIndexManager.php | 2 +- src/Manager/ElasticsearchNodeManager.php | 2 +- src/Manager/ElasticsearchRoleManager.php | 2 +- src/Manager/ElasticsearchSnapshotManager.php | 2 +- src/Model/AppNotificationModel.php | 2 +- src/Model/AppSubscriptionModel.php | 5 ++--- src/Model/AppUserModel.php | 4 ++-- src/Security/Voter/AbstractAppVoter.php | 4 +++- src/Traits/MappingsSettingsAliasesModelTrait.php | 2 +- 14 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/Command/GenerateFaviconsCommand.php b/src/Command/GenerateFaviconsCommand.php index 2d2e6bb5..7773d5e2 100644 --- a/src/Command/GenerateFaviconsCommand.php +++ b/src/Command/GenerateFaviconsCommand.php @@ -35,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::SUCCESS; } - private function generateFavicon($color, $size): void + private function generateFavicon(string $color, int $size): void { $file = __DIR__.'/../../public/favicon-'.$color.'-'.$size.'.png'; diff --git a/src/Exception/CallException.php b/src/Exception/CallException.php index da4e1ce3..1ed39f30 100644 --- a/src/Exception/CallException.php +++ b/src/Exception/CallException.php @@ -6,7 +6,7 @@ class CallException extends RuntimeException { - public function __construct($message) + public function __construct(string $message) { parent::__construct($message); } diff --git a/src/Exception/ConnectionException.php b/src/Exception/ConnectionException.php index 843c957a..993c3163 100644 --- a/src/Exception/ConnectionException.php +++ b/src/Exception/ConnectionException.php @@ -6,7 +6,7 @@ class ConnectionException extends RuntimeException { - public function __construct($message) + public function __construct(string $message) { parent::__construct($message); } diff --git a/src/Manager/AppNotificationManager.php b/src/Manager/AppNotificationManager.php index 4f3a7e26..cc2ca186 100644 --- a/src/Manager/AppNotificationManager.php +++ b/src/Manager/AppNotificationManager.php @@ -36,7 +36,7 @@ class AppNotificationManager extends AbstractAppManager /** * @required */ - public function setClusterManager(ElasticsearchClusterManager $elasticsearchClusterManager) + public function setClusterManager(ElasticsearchClusterManager $elasticsearchClusterManager): void { $this->elasticsearchClusterManager = $elasticsearchClusterManager; } @@ -44,7 +44,7 @@ public function setClusterManager(ElasticsearchClusterManager $elasticsearchClus /** * @required */ - public function setNodeManager(ElasticsearchNodeManager $elasticsearchNodeManager) + public function setNodeManager(ElasticsearchNodeManager $elasticsearchNodeManager): void { $this->elasticsearchNodeManager = $elasticsearchNodeManager; } @@ -262,12 +262,12 @@ public function compareInfo(array $previousInfo, array $lastInfo): array return $notifications; } - public function infoFileExists() + public function infoFileExists(): bool { return file_exists($this->filename); } - private function getColor($value) + private function getColor(string $value): string { switch ($value) { case 'license_1_day': diff --git a/src/Manager/ElasticsearchClusterManager.php b/src/Manager/ElasticsearchClusterManager.php index 65e90529..72f67e38 100644 --- a/src/Manager/ElasticsearchClusterManager.php +++ b/src/Manager/ElasticsearchClusterManager.php @@ -9,7 +9,7 @@ class ElasticsearchClusterManager extends AbstractAppManager { - public function getClusterHealth() + public function getClusterHealth(): array { $callRequest = new CallRequestModel(); $callRequest->setPath('/_cluster/health'); @@ -25,7 +25,7 @@ public function getClusterStats(): array return $callResponse->getContent(); } - public function getClusterSettings() + public function getClusterSettings(): array { $callRequest = new CallRequestModel(); $callRequest->setPath('/_cluster/settings'); @@ -45,7 +45,7 @@ public function getClusterSettings() return $clusterSettings; } - public function getMaintenanceTable() + public function getMaintenanceTable(): array { return [ ['es_version' => '1.0.0', 'eol_date' => '2015-08-12', 'maintained_until' => '1.1.0'], @@ -96,7 +96,7 @@ public function getMaintenanceTable() ]; } - public function getClusterSettingsNotDynamic() + public function getClusterSettingsNotDynamic(): array { return [ 'bootstrap.ctrlhandler', diff --git a/src/Manager/ElasticsearchIndexManager.php b/src/Manager/ElasticsearchIndexManager.php index 6ab5f798..4087dd29 100644 --- a/src/Manager/ElasticsearchIndexManager.php +++ b/src/Manager/ElasticsearchIndexManager.php @@ -222,7 +222,7 @@ public function emptyByName(string $name): CallResponseModel return $this->callManager->call($callRequest); } - private function mappingsFlat(array $properties, string $prefix = '') + private function mappingsFlat(array $properties, string $prefix = ''): array { $mappingsFlat = []; foreach ($properties as $property => $keys) { diff --git a/src/Manager/ElasticsearchNodeManager.php b/src/Manager/ElasticsearchNodeManager.php index 62ece656..7721e31a 100644 --- a/src/Manager/ElasticsearchNodeManager.php +++ b/src/Manager/ElasticsearchNodeManager.php @@ -199,7 +199,7 @@ public function selectNodes(?array $filter = []): array return $nodes; } - public function filterletters() + public function filterletters(): array { return [ 'm' => 'master', diff --git a/src/Manager/ElasticsearchRoleManager.php b/src/Manager/ElasticsearchRoleManager.php index e80cca1e..750096ec 100644 --- a/src/Manager/ElasticsearchRoleManager.php +++ b/src/Manager/ElasticsearchRoleManager.php @@ -145,7 +145,7 @@ public function selectRoles(): array return $roles; } - public function getPrivileges() + public function getPrivileges(): array { if (true === $this->callManager->hasFeature('builtin_privileges')) { $callRequest = new CallRequestModel(); diff --git a/src/Manager/ElasticsearchSnapshotManager.php b/src/Manager/ElasticsearchSnapshotManager.php index 6a9fe7f4..2c8bf095 100644 --- a/src/Manager/ElasticsearchSnapshotManager.php +++ b/src/Manager/ElasticsearchSnapshotManager.php @@ -41,7 +41,7 @@ public function getByNameAndRepository(string $name, string $repository): ?Elast return $snapshotModel; } - public function getAll($repositories, array $filter = []): array + public function getAll(array $repositories, array $filter = []): array { $snapshots = []; diff --git a/src/Model/AppNotificationModel.php b/src/Model/AppNotificationModel.php index 8429c75e..eec7a116 100644 --- a/src/Model/AppNotificationModel.php +++ b/src/Model/AppNotificationModel.php @@ -138,7 +138,7 @@ public function getEmoji(): ?string } } - public static function getTypes() + public static function getTypes(): array { return [ self::TYPE_CLUSTER_HEALTH, diff --git a/src/Model/AppSubscriptionModel.php b/src/Model/AppSubscriptionModel.php index e483652d..2b5db65b 100644 --- a/src/Model/AppSubscriptionModel.php +++ b/src/Model/AppSubscriptionModel.php @@ -167,14 +167,13 @@ public function getNotifications(): ?array return array_values($this->notifications); } - public function setNotifications($notifications): self + public function setNotifications(?array $notifications): self { $this->notifications = $notifications; return $this; } - public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; @@ -239,7 +238,7 @@ public function __toString(): string return $this->id; } - public static function getTypes() + public static function getTypes(): array { return [ self::TYPE_PUSH, diff --git a/src/Model/AppUserModel.php b/src/Model/AppUserModel.php index 8b3f9448..60f1a1a7 100644 --- a/src/Model/AppUserModel.php +++ b/src/Model/AppUserModel.php @@ -167,12 +167,12 @@ public function getSalt(): ?string /** * @see UserInterface */ - public function eraseCredentials() + public function eraseCredentials(): void { // If you store any temporary, sensitive data on the user, clear it here } - public function currentUserAdmin($userConnected): bool + public function currentUserAdmin(UserInterface $userConnected): bool { if ($this->getId() == $userConnected->getId() && true === in_array('ROLE_ADMIN', $this->roles)) { return true; diff --git a/src/Security/Voter/AbstractAppVoter.php b/src/Security/Voter/AbstractAppVoter.php index 0051fb33..5026f0df 100644 --- a/src/Security/Voter/AbstractAppVoter.php +++ b/src/Security/Voter/AbstractAppVoter.php @@ -27,7 +27,7 @@ public function __construct(Security $security, AppRoleManager $appRoleManager) } } - public function isGranted(string $attribute) + public function isGranted(string $attribute): bool { if ($this->security->isGranted('ROLE_ADMIN')) { return true; @@ -36,5 +36,7 @@ public function isGranted(string $attribute) if (true === isset($this->permissions[$this->module]) && true === in_array($attribute, $this->permissions[$this->module])) { return true; } + + return false; } } diff --git a/src/Traits/MappingsSettingsAliasesModelTrait.php b/src/Traits/MappingsSettingsAliasesModelTrait.php index 0d60d507..c2ec8598 100644 --- a/src/Traits/MappingsSettingsAliasesModelTrait.php +++ b/src/Traits/MappingsSettingsAliasesModelTrait.php @@ -40,7 +40,7 @@ public function setSettingsJson(?string $settingsJson): self return $this; } - public function getSetting($key): ?string + public function getSetting(string $key): ?string { return $this->settings[$key] ?? false; }