From 32140b75b56e3caff376aa454170995f310b1be6 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Thu, 12 Sep 2019 11:23:45 +0200 Subject: [PATCH] chg: [decaying:model] Fourth batch of fix from the PR review - WiP (not tested) --- app/Model/DecayingModel.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Model/DecayingModel.php b/app/Model/DecayingModel.php index bb83ab6a0..b67ab7400 100644 --- a/app/Model/DecayingModel.php +++ b/app/Model/DecayingModel.php @@ -234,6 +234,9 @@ class DecayingModel extends AppModel public function fetchModels($user, $ids, $full=true, $conditions=array(), $attach_editable=0) { + if (is_numeric($ids)) { + $ids = array($ids); + } $models = array(); foreach ($ids as $id) { $model = $this->fetchModel($user, $id, $full, $conditions, $attach_editable); @@ -536,12 +539,10 @@ class DecayingModel extends AppModel if (!empty($associated_model_ids)) { $models = $this->fetchModels($user, $associated_model_ids, false, array('enabled' => true)); } - } elseif (is_array($model_id)) { - $models = $this->fetchModels($user, $model_id, false, array()); } else { - $models[] = $this->fetchModel($user, $model_id, false, array()); + $models = $this->fetchModels($user, $model_id, false, array()); } - foreach ($models as $i => $model) { + foreach ($models as $model) { if (!empty($model_overrides)) { $model = $this->overrideModelParameters($model, $model_overrides); } @@ -574,6 +575,9 @@ class DecayingModel extends AppModel } if (is_numeric($model) && $user !== false) { $model = $this->fetchModel($user, $model); + if (empty($model)) { + throw new NotFoundException(__('No Decaying Model with the provided ID exists')); + } } $this->Computation = $this->getModelClass($model); return $this->Computation->computeCurrentScore($user, $model, $attribute);