From 5caf1659cf335c1ea926534b7cfbf3f738c3b0f8 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Thu, 19 Jan 2023 10:27:23 +0100 Subject: [PATCH 1/4] fix: [command:fastEnrolment] Coorrectly display missing organisation instead of throwing an error --- src/Command/FastUserEnrolmentCommand.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Command/FastUserEnrolmentCommand.php b/src/Command/FastUserEnrolmentCommand.php index 5385c31..2fee372 100644 --- a/src/Command/FastUserEnrolmentCommand.php +++ b/src/Command/FastUserEnrolmentCommand.php @@ -199,20 +199,22 @@ class FastUserEnrolmentCommand extends Command $this->loadModel('Organisations'); $updatedData = []; foreach ($data as $entry) { - $new = [ - 'individual_id' => $this->getIndividualByEmail($entry[$this->individual_email_column]), - 'organisation_id' => $this->getOrganisationsByName($entry[$this->organisation_name_column]), - 'type' => $this->alignment_type, - 'individual_email' => $entry[$this->individual_email_column], - ]; - if (empty($new['organisation_id'])) { + $individual = $this->getIndividualByEmail($entry[$this->individual_email_column]); + $organisation = $this->getOrganisationsByName($entry[$this->organisation_name_column]); + if (empty($individual)) { $this->io->error("Error while parsing source data. Could not find organisation with name: " . $entry[$this->organisation_name_column]); die(1); } - if (empty($new['individual_id'])) { + if (empty($organisation)) { $this->io->error("Error while parsing source data. Could not find individuals with email: " . $entry[$this->individual_email_column]); die(1); } + $new = [ + 'individual_id' => $individual->id, + 'organisation_id' => $organisation->id, + 'type' => $this->alignment_type, + 'individual_email' => $entry[$this->individual_email_column], + ]; $new['individual_id'] = $new['individual_id']['id']; $new['organisation_id'] = $new['organisation_id']['id']; $updatedData[] = $new; @@ -224,14 +226,14 @@ class FastUserEnrolmentCommand extends Command { return $this->Individuals->find()->where([ 'email' => $email, - ])->first()->toArray(); + ])->first(); } private function getOrganisationsByName($name) { return $this->Organisations->find()->where([ 'name' => $name, - ])->first()->toArray(); + ])->first(); } private function getDataFromFile($path) From c561fba7ae8b1e4727472245ae3cd5b0abc15b13 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Thu, 19 Jan 2023 15:41:17 +0100 Subject: [PATCH 2/4] fix: [command:fastUserEmrolment] Typo in condition showing the wrong warning for the faulty entity --- src/Command/FastUserEnrolmentCommand.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Command/FastUserEnrolmentCommand.php b/src/Command/FastUserEnrolmentCommand.php index 2fee372..293469c 100644 --- a/src/Command/FastUserEnrolmentCommand.php +++ b/src/Command/FastUserEnrolmentCommand.php @@ -201,11 +201,11 @@ class FastUserEnrolmentCommand extends Command foreach ($data as $entry) { $individual = $this->getIndividualByEmail($entry[$this->individual_email_column]); $organisation = $this->getOrganisationsByName($entry[$this->organisation_name_column]); - if (empty($individual)) { + if (empty($organisation)) { $this->io->error("Error while parsing source data. Could not find organisation with name: " . $entry[$this->organisation_name_column]); die(1); } - if (empty($organisation)) { + if (empty($individual)) { $this->io->error("Error while parsing source data. Could not find individuals with email: " . $entry[$this->individual_email_column]); die(1); } @@ -215,8 +215,6 @@ class FastUserEnrolmentCommand extends Command 'type' => $this->alignment_type, 'individual_email' => $entry[$this->individual_email_column], ]; - $new['individual_id'] = $new['individual_id']['id']; - $new['organisation_id'] = $new['organisation_id']['id']; $updatedData[] = $new; } return $updatedData; From e375e24a6df35a85101d79588ee5e5da7f2410aa Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Mon, 20 Feb 2023 10:17:20 +0100 Subject: [PATCH 3/4] chg: [component:CRUD] Added validation of order fields --- src/Controller/Component/CRUDComponent.php | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index fa98a42..5edb80d 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -73,7 +73,11 @@ class CRUDComponent extends Component $query->select($options['fields']); } if (!empty($options['order'])) { - $query->order($options['order']); + $orderFields = array_keys($options['order']); + if ($this->_validOrderFields($orderFields)) { + $query->order($options['order']); + $this->Controller->paginate['order'] = $options['order']; + } } if ($this->Controller->ParamHandler->isRest()) { if ($this->metaFieldsSupported()) { @@ -1581,4 +1585,34 @@ class CRUDComponent extends Component } return $typeMap; } + + protected function _validOrderFields($fields): bool + { + if (!is_array($fields)) { + $fields = [$fields]; + } + foreach ($fields as $field) { + $exploded = explode('.', $field); + if (count($exploded) > 1) { + $model = $exploded[0]; + $subField = $exploded[1]; + if ($model == $this->Table->getAlias()) { + if (empty($this->Table->getSchema()->typeMap()[$subField])) { + return false; + } + } else { + $association = $this->Table->associations()->get($model); + $associatedTable = $association->getTarget(); + if (empty($associatedTable->getSchema()->typeMap()[$subField])) { + return false; + } + } + } else { + if (empty($this->Table->getSchema()->typeMap()[$field])) { + return false; + } + } + } + return true; + } } From ce42bd77263c4e0bbb37a0823de76f3cc0f4f9df Mon Sep 17 00:00:00 2001 From: iglocska Date: Tue, 21 Feb 2023 13:50:30 +0100 Subject: [PATCH 4/4] chg: [version] bump --- src/VERSION.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VERSION.json b/src/VERSION.json index 572ef01..9122d97 100644 --- a/src/VERSION.json +++ b/src/VERSION.json @@ -1,4 +1,4 @@ { - "version": "1.11", + "version": "1.12", "application": "Cerebrate" }