diff --git a/CRM/Core/BAO/Note.php b/CRM/Core/BAO/Note.php index c33642acd255..a5646795eb8e 100644 --- a/CRM/Core/BAO/Note.php +++ b/CRM/Core/BAO/Note.php @@ -143,7 +143,7 @@ public static function add(&$params, $ids = array()) { return CRM_Core_DAO::$_nullObject; } - if ($params['entity_table'] == 'civicrm_contact' && !empty($params['check_permissions'])) { + if (!empty($params['entity_table']) && $params['entity_table'] == 'civicrm_contact' && !empty($params['check_permissions'])) { if (!CRM_Contact_BAO_Contact_Permission::allow($params['entity_id'], CRM_Core_Permission::EDIT)) { throw new CRM_Exception('Permission denied to modify contact record'); } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 4d7829d778e2..1d7542130521 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2436,13 +2436,15 @@ public function addSelectWhereClause() { $relatedClauses = array(); $relatedEntities = $this->buildOptions('entity_table', 'get'); foreach ((array) $relatedEntities as $table => $ent) { - $ent = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($table)); - $subquery = CRM_Utils_SQL::mergeSubquery($ent); - if ($subquery) { - $relatedClauses[] = "(entity_table = '$table' AND entity_id " . implode(' AND entity_id ', $subquery) . ")"; - } - else { - $relatedClauses[] = "(entity_table = '$table')"; + if (!empty($ent)) { + $ent = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($table)); + $subquery = CRM_Utils_SQL::mergeSubquery($ent); + if ($subquery) { + $relatedClauses[] = "(entity_table = '$table' AND entity_id " . implode(' AND entity_id ', $subquery) . ")"; + } + else { + $relatedClauses[] = "(entity_table = '$table')"; + } } } if ($relatedClauses) {