diff --git a/CHANGELOG.md b/CHANGELOG.md index a6eef6e..a6ece97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Implemented synchronization for campo keys of child terms. + ## [2.0.0] - 2024-07-24 ### Added diff --git a/composer.lock b/composer.lock index bf78183..ea17375 100644 --- a/composer.lock +++ b/composer.lock @@ -411,12 +411,12 @@ "source": { "type": "git", "url": "https://github.com/RRZE-Webteam/FAU-Studium-Common.git", - "reference": "636f84616b29c8bad552d2c6952729f162128c37" + "reference": "2314da111571d795a3f3d3dbe194680737a26e07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/RRZE-Webteam/FAU-Studium-Common/zipball/636f84616b29c8bad552d2c6952729f162128c37", - "reference": "636f84616b29c8bad552d2c6952729f162128c37", + "url": "https://api.github.com/repos/RRZE-Webteam/FAU-Studium-Common/zipball/2314da111571d795a3f3d3dbe194680737a26e07", + "reference": "2314da111571d795a3f3d3dbe194680737a26e07", "shasum": "" }, "require": { @@ -489,7 +489,7 @@ "source": "https://github.com/RRZE-Webteam/FAU-Studium-Common/tree/main", "issues": "https://github.com/RRZE-Webteam/FAU-Studium-Common/issues" }, - "time": "2024-09-04T11:37:53+00:00" + "time": "2024-09-04T13:20:56+00:00" }, { "name": "webmozart/assert", diff --git a/src/Infrastructure/Search/FilterableTermsUpdater.php b/src/Infrastructure/Search/FilterableTermsUpdater.php index 410bad3..1a2fbce 100644 --- a/src/Infrastructure/Search/FilterableTermsUpdater.php +++ b/src/Infrastructure/Search/FilterableTermsUpdater.php @@ -141,19 +141,19 @@ private function setObjectTerms( string $taxonomy, MultilingualString|MultilingualList|MultilingualLink|MultilingualLinks|Degree|AdmissionRequirement $property ): void { - - $termIds = $this->maybeCreateTerms($taxonomy, $property); + /** @var array $terms */ + $terms = $this->maybeCreateTerms($taxonomy, $property); wp_set_object_terms( $rawView->id()->asInt(), - $termIds, + array_keys($terms), $taxonomy ); - if (! isset($termIds[0])) { + if (!$terms) { return; } - $this->maybeUpdateCampoKeys($rawView, $taxonomy, (int) $termIds[0]); + $this->maybeUpdateCampoKeys($rawView, $taxonomy, $terms); } private function isValidPostId(int $postId): bool @@ -179,6 +179,8 @@ private function isValidPostId(int $postId): bool * phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong * * Refactoring could decrease performance. + * + * @return array */ private function maybeCreateTerms( string $taxonomy, @@ -225,7 +227,7 @@ private function maybeCreateTerms( if ($termData->termId()) { // Term was persisted already - $result[] = $termData->termId(); + $result[$termData->termId()] = $termData; $this->updateTerm($termData); continue; } @@ -233,7 +235,7 @@ private function maybeCreateTerms( $termId = $this->createTerm($termData); if (is_int($termId)) { - $result[] = $termId; + $result[$termId] = $termData; $taxonomiesCache[$taxonomy][$termId] = [ self::TAXONOMIES_CACHE_NAME_PROPERTY => $termData->name()->inGerman(), self::TAXONOMIES_CACHE_ORIGINAL_ID_PROPERTY => $termData->remoteTermId(), @@ -540,16 +542,25 @@ private static function arraySearchBy(array $array, string $property, mixed $val return null; } - private function maybeUpdateCampoKeys(DegreeProgramViewRaw $rawView, string $taxonomy, int $termId): void + private function maybeUpdateCampoKeys(DegreeProgramViewRaw $rawView, string $taxonomy, array $terms): void { $campoKeys = $rawView->campoKeys()->asArray(); $campoKeyType = CampoKeysRepository::TAXONOMY_TO_CAMPO_KEY_MAP[$taxonomy] ?? ''; - $campoKey = $campoKeys[$campoKeyType] ?? null; + $taxonomyCampoKeys = $campoKeys[$campoKeyType] ?? null; - if (is_null($campoKey)) { + if (!is_array($taxonomyCampoKeys)) { return; } - update_term_meta($termId, CampoKeysRepository::CAMPO_KEY_TERM_META_KEY, $campoKey); + /** @var TermData $term */ + foreach ($terms as $term) { + $termCampoKey = $taxonomyCampoKeys[$term->remoteTermId()] ?? null; + + if (is_null($termCampoKey)) { + continue; + } + + update_term_meta($term->termId(), CampoKeysRepository::CAMPO_KEY_TERM_META_KEY, $termCampoKey); + } } }