* @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);
}
if (!$optionId) {
return;
}
- // Ensure mysql phone function exists
- CRM_Core_DAO::checkSqlFunctionsExist();
$tables = [
'civicrm_phone',
* @return bool
*/
public static function del($id) {
- // Ensure mysql phone function exists
- CRM_Core_DAO::checkSqlFunctionsExist();
return CRM_Contact_BAO_Contact::deleteObjectWithPrimary('Phone', $id);
}
*/
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
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.
*
}
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'),
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 [];
+ }
+
}