From 39c0c7c5496de86838222c06b64c136ed7305ef2 Mon Sep 17 00:00:00 2001 From: Pierre-Henry Soria Date: Mon, 14 Feb 2022 07:36:27 +1030 Subject: [PATCH] [#977 CountryRestriction] Update execution order + comments --- .../processing/CountryRestrictionCoreFormProcess.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/_protected/app/system/core/forms/processing/CountryRestrictionCoreFormProcess.php b/_protected/app/system/core/forms/processing/CountryRestrictionCoreFormProcess.php index 67fb48bac5..66e9406efa 100644 --- a/_protected/app/system/core/forms/processing/CountryRestrictionCoreFormProcess.php +++ b/_protected/app/system/core/forms/processing/CountryRestrictionCoreFormProcess.php @@ -29,17 +29,18 @@ public function __construct(string $sTable) $this->sTable = $sTable; $oUserModel = new UserCoreModel; - - // First, clear everything - $oUserModel->clearCountries($this->sTable); - - // Then, reindex the table $aCountries = (array)$this->httpRequest->post('countries'); + + // Validation: Make sure at least one country has been selected if ($this->areCountriesNotSet($aCountries)) { \PFBC\Form::setError('form_country_restriction', t('You need to select at least one country.')); return; } + // Firstly, clear everything + $oUserModel->clearCountries($this->sTable); + + // Secondly, reindex the table foreach ($aCountries as $sCountry) { if ($this->isEligibleToAdd($sCountry)) { $oUserModel->addCountry($sCountry, $this->sTable);