Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#27 Move check for phone function to a check #20757

Merged
merged 1 commit into from
Jul 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions CRM/Core/BAO/Phone.php
Original file line number Diff line number Diff line change
@@ -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 @@ public static function setOptionToNull($optionId) {
if (!$optionId) {
return;
}
// Ensure mysql phone function exists
CRM_Core_DAO::checkSqlFunctionsExist();

$tables = [
'civicrm_phone',
@@ -243,8 +239,6 @@ public static function setOptionToNull($optionId) {
* @return bool
*/
public static function del($id) {
// Ensure mysql phone function exists
CRM_Core_DAO::checkSqlFunctionsExist();
return CRM_Contact_BAO_Contact::deleteObjectWithPrimary('Phone', $id);
}

19 changes: 0 additions & 19 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
@@ -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 @@ public static function triggerRebuild($tableName = NULL, $force = FALSE) {
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;
colemanw marked this conversation as resolved.
Show resolved Hide resolved
$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.
*
28 changes: 27 additions & 1 deletion CRM/Utils/Check/Component/Schema.php
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ public function checkSmartGroupCustomFieldCriteria() {
}
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 @@ public function checkMoneyValueFormatConfig() {
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 [];
}

}