diff --git a/CRM/Core/BAO/Phone.php b/CRM/Core/BAO/Phone.php index c5a110e2eeba9665eb02dda6f71e226ff0c08915..260b2e69736ab34e2cd7d7ad88621c17f09efb51 100644 --- a/CRM/Core/BAO/Phone.php +++ b/CRM/Core/BAO/Phone.php @@ -33,8 +33,6 @@ class CRM_Core_BAO_Phone extends CRM_Core_DAO_Phone { * @throws \CRM_Core_Exception */ public static function create($params) { - // Ensure mysql phone function exists - CRM_Core_DAO::checkSqlFunctionsExist(); CRM_Core_BAO_Block::handlePrimary($params, get_class()); return self::writeRecord($params); } @@ -214,8 +212,6 @@ ORDER BY ph.is_primary DESC, phone_id ASC "; if (!$optionId) { return; } - // Ensure mysql phone function exists - CRM_Core_DAO::checkSqlFunctionsExist(); $tables = [ 'civicrm_phone', @@ -243,8 +239,6 @@ ORDER BY ph.is_primary DESC, phone_id ASC "; * @return bool */ public static function del($id) { - // Ensure mysql phone function exists - CRM_Core_DAO::checkSqlFunctionsExist(); return CRM_Contact_BAO_Contact::deleteObjectWithPrimary('Phone', $id); } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 253c58d580d5d91ac5bba74aa22f223e90b1ffb5..1bcd8743576b69c0f8da5eaa198b64d7bd1e5659 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -107,8 +107,6 @@ class CRM_Core_DAO extends DB_DataObject { */ public static $_factory = NULL; - public static $_checkedSqlFunctionsExist = FALSE; - /** * https://issues.civicrm.org/jira/browse/CRM-17748 * internal variable for DAO to hold per-query settings @@ -2460,23 +2458,6 @@ SELECT contact_id Civi::service('sql_triggers')->rebuild($tableName, $force); } - /** - * Because sql functions are sometimes lost, esp during db migration, we check here to avoid numerous support requests - * @see http://issues.civicrm.org/jira/browse/CRM-13822 - * TODO: Alternative solutions might be - * * Stop using functions and find another way to strip numeric characters from phones - * * Give better error messages (currently a missing fn fatals with "unknown error") - */ - public static function checkSqlFunctionsExist() { - if (!self::$_checkedSqlFunctionsExist) { - self::$_checkedSqlFunctionsExist = TRUE; - $dao = CRM_Core_DAO::executeQuery("SHOW function status WHERE db = database() AND name = 'civicrm_strip_non_numeric'"); - if (!$dao->fetch()) { - self::triggerRebuild(); - } - } - } - /** * Wrapper function to drop triggers. * diff --git a/CRM/Utils/Check/Component/Schema.php b/CRM/Utils/Check/Component/Schema.php index 4e9e9c7ed7e0e1d37954adbdaff069e96da9395b..0fc536184fd4da39fdf655f38e04c76adc6c05af 100644 --- a/CRM/Utils/Check/Component/Schema.php +++ b/CRM/Utils/Check/Component/Schema.php @@ -125,7 +125,7 @@ class CRM_Utils_Check_Component_Schema extends CRM_Utils_Check_Component { } foreach ($group['form_values'] as $formValues) { if (isset($formValues[0]) && (strpos($formValues[0], 'custom_') === 0)) { - list(, $customFieldID) = explode('_', $formValues[0]); + [, $customFieldID] = explode('_', $formValues[0]); if (!in_array((int) $customFieldID, $customFieldIds, TRUE)) { $problematicSG[CRM_Contact_BAO_SavedSearch::getName($group['id'], 'id')] = [ 'title' => CRM_Contact_BAO_SavedSearch::getName($group['id'], 'title'), @@ -203,4 +203,30 @@ class CRM_Utils_Check_Component_Schema extends CRM_Utils_Check_Component { return $messages; } + /** + * Check the function to populate phone_numeric exists. + * + * @return array|\CRM_Utils_Check_Message[] + */ + public function checkPhoneFunctionExists():array { + $dao = CRM_Core_DAO::executeQuery("SHOW function status WHERE db = database() AND name = 'civicrm_strip_non_numeric'"); + if (!$dao->fetch()) { + $msg = new CRM_Utils_Check_Message( + __FUNCTION__, + ts("Your database is missing a function to populate the 'Phone number' field with a numbers-only version of the phone."), + ts('Missing Phone numeric function'), + \Psr\Log\LogLevel::WARNING, + 'fa-server' + ); + $msg->addAction( + ts('Rebuild triggers (also re-builds the phone number function)'), + ts('Create missing function now? This may take few minutes.'), + 'api3', + ['System', 'flush', ['triggers' => TRUE]] + ); + return [$msg]; + } + return []; + } + }