Skip to content

Commit

Permalink
Plug the validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Oct 29, 2024
1 parent 4e3f652 commit 26cce52
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames;
use PrestaShop\Module\AutoUpgrade\Router\Routes;
use PrestaShop\Module\AutoUpgrade\Twig\PageSelectors;
use PrestaShop\Module\AutoUpgrade\Twig\UpdateSteps;
use Symfony\Component\HttpFoundation\JsonResponse;

Expand Down Expand Up @@ -65,11 +66,27 @@ public function saveOption(): JsonResponse
$upgradeConfiguration = $this->upgradeContainer->getUpgradeConfiguration();
$upgradeConfigurationStorage = $this->upgradeContainer->getUpgradeConfigurationStorage();

// TODO: Call the validator

$upgradeConfiguration->merge([
$config = [
$name => $this->request->request->getBoolean('value'),
]);
];

// TODO: Remove after rebase
$upgradeConfiguration->validate($config);
// TODO: Uncomment after rebase
// $error = $this->upgradeContainer->getConfigurationValidator()->validate($config);
if (!empty($error)) {
$params = array_merge($this->getParams(), ['error' => $error]);
return AjaxResponseBuilder::hydrationResponse(
PageSelectors::STEP_PARENT_ID,
$this->getTwig()->render(
'@ModuleAutoUpgrade/steps/' . $this->getStepTemplate() . '.html.twig',
$params
),
$this->displayRouteInUrl()
);
}

$upgradeConfiguration->merge($config);

$success = $upgradeConfigurationStorage->save($upgradeConfiguration, UpgradeFileNames::CONFIG_FILENAME);
return new JsonResponse(['success' => $success]);
Expand Down Expand Up @@ -97,9 +114,21 @@ protected function getParams(): array
'form_route_to_save' => Routes::UPDATE_STEP_UPDATE_OPTIONS_SAVE_OPTION,
'form_route_to_submit' => Routes::UPDATE_STEP_UPDATE_OPTIONS_SUBMIT_FORM,

'default_deactive_non_native_modules' => $upgradeConfiguration->shouldDeactivateCustomModules(),
'default_regenerate_email_templates' => $upgradeConfiguration->shouldRegenerateMailTemplates(),
'disable_all_overrides' => !$upgradeConfiguration->isOverrideAllowed(),
'form_fields' => [
'deactive_non_native_modules' => [
'field' => 'PS_AUTOUP_CUSTOM_MOD_DESACT',
'value' => $upgradeConfiguration->shouldDeactivateCustomModules(),
],
'regenerate_email_templates' => [
'field' => 'PS_AUTOUP_REGEN_EMAIL',
'value' => $upgradeConfiguration->shouldRegenerateMailTemplates(),
],
'disable_all_overrides' => [
'field' => 'PS_DISABLE_OVERRIDES',
'value' => !$upgradeConfiguration->isOverrideAllowed(),
],
],

]
);
}
Expand Down
35 changes: 26 additions & 9 deletions views/templates/steps/update-options.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
required: true,
disabled: true
},
BoolName: "PS_AUTOUP_CUSTOM_MOD_DESACT",
BoolId: "PS_AUTOUP_CUSTOM_MOD_DESACT",
val: default_deactive_non_native_modules
BoolName: form_fields.deactive_non_native_modules.field,
BoolId: form_fields.deactive_non_native_modules.field,
val: form_fields.deactive_non_native_modules.value
} %}

{% include "@ModuleAutoUpgrade/components/render-bool.html.twig" with {
Expand All @@ -39,9 +39,9 @@
required: true,
disabled: true
},
BoolName: "PS_AUTOUP_REGEN_EMAIL",
BoolId: "PS_AUTOUP_REGEN_EMAIL",
val: default_regenerate_email_templates
BoolName: form_fields.regenerate_email_templates.field,
BoolId: form_fields.regenerate_email_templates.field,
val: form_fields.regenerate_email_templates.value,
} %}

{% include "@ModuleAutoUpgrade/components/render-select.html.twig" with {
Expand Down Expand Up @@ -74,11 +74,28 @@
required: true,
disabled: true
},
BoolName: "PS_DISABLE_OVERRIDES",
BoolId: "PS_DISABLE_OVERRIDES",
val: disable_all_overrides
BoolName: form_fields.disable_all_overrides.field,
BoolId: form_fields.disable_all_overrides.field,
val: form_fields.disable_all_overrides.value,
} %}
{% if error[form_fields.disable_all_overrides.field] %}
<div class="error-message">
<i class="material-icons">error</i>
{{ error[form_fields.disable_all_overrides.field] }}
</div>
{% endif %}
</form>
{% if error %}
<div class="local-archive__alert">
{% include "@ModuleAutoUpgrade/components/alert.html.twig" with {
title: "",
message: error|first,
alertStatus: "warning",
buttonLabel: "",
buttonUrl: "",
} %}
</div>
{% endif %}
{% endblock %}

{% block buttons_inner %}
Expand Down

0 comments on commit 26cce52

Please sign in to comment.