From 543fccdc588200c6cbe7f38b0869e208c3c0af2f Mon Sep 17 00:00:00 2001 From: iglocska Date: Thu, 4 Oct 2018 22:48:50 +0200 Subject: [PATCH] fix: [api] Sharing group organisations not iterated if they don't exist --- app/Model/SharingGroup.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/Model/SharingGroup.php b/app/Model/SharingGroup.php index 898b6df43..1aafb1e45 100644 --- a/app/Model/SharingGroup.php +++ b/app/Model/SharingGroup.php @@ -187,15 +187,17 @@ class SharingGroup extends AppModel )); } $sg['Organisation'] = $this->__sgoCache[$sg['SharingGroup']['org_id']]; - foreach ($sg['SharingGroupOrg'] as &$sgo) { - if (!isset($this->__sgoCache[$sgo['org_id']])) { - $this->__sgoCache[$sgo['org_id']] = $this->Organisation->find('first', array( - 'recursive' => -1, - 'fields' => $fieldsOrg, - 'conditions' => array('id' => $sgo['org_id']) - )); + if (!empty($sg['SharingGroupOrg'])) { + foreach ($sg['SharingGroupOrg'] as &$sgo) { + if (!isset($this->__sgoCache[$sgo['org_id']])) { + $this->__sgoCache[$sgo['org_id']] = $this->Organisation->find('first', array( + 'recursive' => -1, + 'fields' => $fieldsOrg, + 'conditions' => array('id' => $sgo['org_id']) + )); + } + $sgo['Organisation'] = $this->__sgoCache[$sgo['org_id']]; } - $sgo['Organisation'] = $this->__sgoCache[$sgo['org_id']]; } } return $sgs;