From c2a866e87bcd36553e0d9cf0ba2f05adcb71e68a Mon Sep 17 00:00:00 2001 From: sumit panwar Date: Wed, 27 Jan 2021 17:56:37 +0530 Subject: [PATCH] Fixed::Prevent deleting profile which is used by at least one employee --- classes/Profile.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/classes/Profile.php b/classes/Profile.php index cd4fe6ae8..7cd04cc4e 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -94,12 +94,17 @@ class ProfileCore extends ObjectModel public function delete() { - if (parent::delete()) { - return ( - Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'access` WHERE `id_profile` = '.(int)$this->id) - && Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_access` WHERE `id_profile` = '.(int)$this->id) - ); + // check if any employee exists of this deleting profile before delete + $profileEmployees = Employee::getEmployeesByProfile($this->id); + if (empty($profileEmployees)) { + if (parent::delete()) { + return ( + Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'access` WHERE `id_profile` = '.(int)$this->id) + && Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_access` WHERE `id_profile` = '.(int)$this->id) + ); + } } + return false; }