From 0c8b7b5820cf00ccd2c4f64d26961e6652083b7e Mon Sep 17 00:00:00 2001 From: mokaddem Date: Tue, 13 Aug 2019 15:54:03 +0200 Subject: [PATCH] fix: [decaying] Do not access existing keys anymore --- app/Model/Attribute.php | 2 +- app/Model/DecayingModel.php | 2 +- app/Model/DecayingModelsFormulas/Base.php | 22 ++++++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index 3ed5c76d0..11ef36dd0 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -3182,7 +3182,7 @@ class Attribute extends AppModel } if ($options['includeDecayScore']) { $this->DecayingModel = ClassRegistry::init('DecayingModel'); - $this->DecayingModel->attachScoresToAttribute($user, $results[$key], $options['decayingModel']); + $this->DecayingModel->attachScoresToAttribute($user, $results[$key]['Attribute'], $options['decayingModel']); if ($options['excludeDecayed']) { // filter out decayed attribute $decayed_flag = true; foreach ($results[$key]['Attribute']['decay_score'] as $decayResult) { diff --git a/app/Model/DecayingModel.php b/app/Model/DecayingModel.php index f9de22049..dd431b81e 100644 --- a/app/Model/DecayingModel.php +++ b/app/Model/DecayingModel.php @@ -254,7 +254,7 @@ class DecayingModel extends AppModel private function __include_formula_file_and_return_instance($filename='Polynomial.php') { $filename_no_extension = str_replace('.php', '', $filename); - $filename = preg_replace('/[^a-zA-Z0-9_]+/', '-', $filename_no_extension) . '.php'; // sanitization + $filename = preg_replace('/[^a-zA-Z0-9_]+/', '-', $filename_no_extension) . '.php'; // sanitization & TO BE REVIEWED $full_path = APP . 'Model/DecayingModelsFormulas/' . $filename; $expected_classname = $filename_no_extension; if (is_file($full_path)) { diff --git a/app/Model/DecayingModelsFormulas/Base.php b/app/Model/DecayingModelsFormulas/Base.php index e265a804c..562943aa2 100644 --- a/app/Model/DecayingModelsFormulas/Base.php +++ b/app/Model/DecayingModelsFormulas/Base.php @@ -43,16 +43,18 @@ abstract class DecayingModelBase $temp_mapping[$namespace_predicate] = $i; } } - foreach ($attribute['AttributeTag'] as $tag) { - $namespace_predicate = explode('=', $tag['Tag']['name'])[0]; - if (isset($temp_mapping[$namespace_predicate])) { // need to override event tag - $overridden_tags[] = array( - 'EventTag' => $tags[$temp_mapping[$namespace_predicate]], - 'AttributeTag' => $tag - ); - $tags[$temp_mapping[$namespace_predicate]] = $tag; - } else { - $tags[] = $tag; + if (isset($attribute['AttributeTag'])) { + foreach ($attribute['AttributeTag'] as $tag) { + $namespace_predicate = explode('=', $tag['Tag']['name'])[0]; + if (isset($temp_mapping[$namespace_predicate])) { // need to override event tag + $overridden_tags[] = array( + 'EventTag' => $tags[$temp_mapping[$namespace_predicate]], + 'AttributeTag' => $tag + ); + $tags[$temp_mapping[$namespace_predicate]] = $tag; + } else { + $tags[] = $tag; + } } } return array('tags' => $tags, 'overridden' => $overridden_tags);