From 9c6ee26ed2784ee56bee2bb15e4633d57e03bd22 Mon Sep 17 00:00:00 2001 From: Peter Kraume Date: Tue, 5 Dec 2023 17:08:27 +0100 Subject: [PATCH 1/2] [BUGFIX] Prevent undefined array key warning Fixes: #565 --- Classes/Service/LinkingSuggestionsService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Classes/Service/LinkingSuggestionsService.php b/Classes/Service/LinkingSuggestionsService.php index 126aef15..8a8b0f9e 100644 --- a/Classes/Service/LinkingSuggestionsService.php +++ b/Classes/Service/LinkingSuggestionsService.php @@ -254,6 +254,9 @@ protected function groupWordsByRecord(array $candidateWords): array $candidateWordsByRecords = []; foreach ($candidateWords as $candidateWord) { $recordKey = $candidateWord['uid_foreign'] . '-' . $candidateWord['tablenames']; + if (!array_key_exists('weight', $candidateWord) || !array_key_exists('df', $candidateWord)) { + continue; + } $candidateWordsByRecords[$recordKey][$candidateWord['stem']] = [ 'weight' => (int)$candidateWord['weight'], 'df' => (int)$candidateWord['df'] @@ -345,7 +348,7 @@ protected function linkRecords(array $scores, array $currentLinks): array 'recordType' => $this->getRecordType($table), 'id' => $uid, 'table' => $table, - 'cornerstone' => (int)$data['tx_yoastseo_cornerstone'], + 'cornerstone' => array_key_exists('tx_yoastseo_cornerstone', $data) ? (int)$data['tx_yoastseo_cornerstone'] : 0, 'score' => $score, 'active' => isset($currentLinks[$record]) ]; From c105d6d820186ec63e2ccee909c2572edaeed80b Mon Sep 17 00:00:00 2001 From: Riny van Tiggelen Date: Mon, 11 Dec 2023 13:47:22 +0100 Subject: [PATCH 2/2] [BUGFIX] Prevent undefined array key warning within LinkingSuggestionsService --- CHANGELOG.md | 1 + Classes/Service/LinkingSuggestionsService.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f527e281..ac83ad4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ We will follow [Semantic Versioning](http://semver.org/). ## UNRELEASED ### Fixed +- Prevent undefined array key warning within `LinkingSuggestionsService` - Missing label of the tx_yoastseo_prominent_word table - Removed exclude=true from tx_yoastseo_prominent_word fields, table already has hideTable - Use `websiteTitle` of site configuration within snippet preview, previously this was only taken from site languages instead of the site itself diff --git a/Classes/Service/LinkingSuggestionsService.php b/Classes/Service/LinkingSuggestionsService.php index 8a8b0f9e..ad278175 100644 --- a/Classes/Service/LinkingSuggestionsService.php +++ b/Classes/Service/LinkingSuggestionsService.php @@ -253,10 +253,10 @@ protected function groupWordsByRecord(array $candidateWords): array { $candidateWordsByRecords = []; foreach ($candidateWords as $candidateWord) { - $recordKey = $candidateWord['uid_foreign'] . '-' . $candidateWord['tablenames']; - if (!array_key_exists('weight', $candidateWord) || !array_key_exists('df', $candidateWord)) { + if (!isset($candidateWord['weight'], $candidateWord['df'])) { continue; } + $recordKey = $candidateWord['uid_foreign'] . '-' . $candidateWord['tablenames']; $candidateWordsByRecords[$recordKey][$candidateWord['stem']] = [ 'weight' => (int)$candidateWord['weight'], 'df' => (int)$candidateWord['df'] @@ -348,7 +348,7 @@ protected function linkRecords(array $scores, array $currentLinks): array 'recordType' => $this->getRecordType($table), 'id' => $uid, 'table' => $table, - 'cornerstone' => array_key_exists('tx_yoastseo_cornerstone', $data) ? (int)$data['tx_yoastseo_cornerstone'] : 0, + 'cornerstone' => (int)($data['tx_yoastseo_cornerstone'] ?? 0), 'score' => $score, 'active' => isset($currentLinks[$record]) ];