* @param array $params input parameters
*/
static function create($params) {
+ // Ensure mysql phone function exists
+ CRM_Core_DAO::checkSqlFunctionsExist();
+
if (is_numeric(CRM_Utils_Array::value('is_primary', $params)) ||
// if id is set & is_primary isn't we can assume no change
empty($params['id'])
* @static
*/
static function add(&$params) {
+ // Ensure mysql phone function exists
+ CRM_Core_DAO::checkSqlFunctionsExist();
+
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'Phone', CRM_Utils_Array::value('id', $params), $params);
if (!$optionId) {
return;
}
+ // Ensure mysql phone function exists
+ CRM_Core_DAO::checkSqlFunctionsExist();
$tables = array(
'civicrm_phone',
* Call common delete function
*/
static function del($id) {
+ // Ensure mysql phone function exists
+ CRM_Core_DAO::checkSqlFunctionsExist();
return CRM_Contact_BAO_Contact::deleteObjectWithPrimary('Phone', $id);
}
}
*/
static $_factory = NULL;
+ static $_checkedSqlFunctionsExist = FALSE;
+
/**
* Class constructor
*
self::createTriggers($info);
}
+ /**
+ * 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")
+ */
+ 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
*