fix: [decaying] Do not access existing keys anymore

pull/5032/head
mokaddem 2019-08-13 15:54:03 +02:00
parent 8a6dbd033e
commit 0c8b7b5820
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 14 additions and 12 deletions

View File

@ -3182,7 +3182,7 @@ class Attribute extends AppModel
} }
if ($options['includeDecayScore']) { if ($options['includeDecayScore']) {
$this->DecayingModel = ClassRegistry::init('DecayingModel'); $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 if ($options['excludeDecayed']) { // filter out decayed attribute
$decayed_flag = true; $decayed_flag = true;
foreach ($results[$key]['Attribute']['decay_score'] as $decayResult) { foreach ($results[$key]['Attribute']['decay_score'] as $decayResult) {

View File

@ -254,7 +254,7 @@ class DecayingModel extends AppModel
private function __include_formula_file_and_return_instance($filename='Polynomial.php') private function __include_formula_file_and_return_instance($filename='Polynomial.php')
{ {
$filename_no_extension = str_replace('.php', '', $filename); $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; $full_path = APP . 'Model/DecayingModelsFormulas/' . $filename;
$expected_classname = $filename_no_extension; $expected_classname = $filename_no_extension;
if (is_file($full_path)) { if (is_file($full_path)) {

View File

@ -43,16 +43,18 @@ abstract class DecayingModelBase
$temp_mapping[$namespace_predicate] = $i; $temp_mapping[$namespace_predicate] = $i;
} }
} }
foreach ($attribute['AttributeTag'] as $tag) { if (isset($attribute['AttributeTag'])) {
$namespace_predicate = explode('=', $tag['Tag']['name'])[0]; foreach ($attribute['AttributeTag'] as $tag) {
if (isset($temp_mapping[$namespace_predicate])) { // need to override event tag $namespace_predicate = explode('=', $tag['Tag']['name'])[0];
$overridden_tags[] = array( if (isset($temp_mapping[$namespace_predicate])) { // need to override event tag
'EventTag' => $tags[$temp_mapping[$namespace_predicate]], $overridden_tags[] = array(
'AttributeTag' => $tag 'EventTag' => $tags[$temp_mapping[$namespace_predicate]],
); 'AttributeTag' => $tag
$tags[$temp_mapping[$namespace_predicate]] = $tag; );
} else { $tags[$temp_mapping[$namespace_predicate]] = $tag;
$tags[] = $tag; } else {
$tags[] = $tag;
}
} }
} }
return array('tags' => $tags, 'overridden' => $overridden_tags); return array('tags' => $tags, 'overridden' => $overridden_tags);