Skip to content

Commit

Permalink
[REF] Convert Custom Field BAO Class to use standard Civi:: rather th…
Browse files Browse the repository at this point in the history
…an local static vars
  • Loading branch information
seamuslee001 committed Feb 21, 2020
1 parent 5f627bb commit a7fad9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
49 changes: 14 additions & 35 deletions CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,15 @@
*/
class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {

/**
* Array for valid combinations of data_type & descriptions.
*
* @var array
*/
public static $_dataType = NULL;

/**
* Array for valid combinations of data_type & html_type.
*
* @var array
*/
public static $_dataToHtml = NULL;

/**
* Array to hold (formatted) fields for import
*
* @var array
*/
public static $_importFields = NULL;

/**
* Build and retrieve the list of data types and descriptions.
*
* @return array
* Data type => Description
*/
public static function &dataType() {
if (!(self::$_dataType)) {
self::$_dataType = [
if (!isset(Civi::$statics[__CLASS__]['dataType'])) {
Civi::$statics[__CLASS__]['dataType'] = [
'String' => ts('Alphanumeric'),
'Int' => ts('Integer'),
'Float' => ts('Number'),
Expand All @@ -64,7 +43,7 @@ public static function &dataType() {
'ContactReference' => ts('Contact Reference'),
];
}
return self::$_dataType;
return Civi::$statics[__CLASS__]['dataType'];
}

/**
Expand Down Expand Up @@ -99,8 +78,8 @@ public static function dataToType() {
* @return array
*/
public static function dataToHtml() {
if (!self::$_dataToHtml) {
self::$_dataToHtml = [
if (!isset(Civi::$statics[__CLASS__]['dataToHtml'])) {
Civi::$statics[__CLASS__]['dataToHtml'] = [
[
'Text' => 'Text',
'Select' => 'Select',
Expand All @@ -122,7 +101,7 @@ public static function dataToHtml() {
['ContactReference' => 'Autocomplete-Select'],
];
}
return self::$_dataToHtml;
return Civi::$statics[__CLASS__]['dataToHtml'];
}

/**
Expand Down Expand Up @@ -388,11 +367,11 @@ public static function &getFields(
$cacheKey = md5($cacheKey);
}

if (!self::$_importFields ||
CRM_Utils_Array::value($cacheKey, self::$_importFields) === NULL
if (!isset(Civi::$statics[__CLASS__]['importFields']) ||
CRM_Utils_Array::value($cacheKey, Civi::$statics[__CLASS__]['importFields']) === NULL
) {
if (!self::$_importFields) {
self::$_importFields = [];
if (!isset(Civi::$statics[__CLASS__]['importFields'])) {
Civi::$statics[__CLASS__]['importFields'] = [];
}

// check if we can retrieve from database cache
Expand Down Expand Up @@ -422,8 +401,8 @@ public static function &getFields(

if (!empty($customDataType) && empty($extends)) {
// $customDataType specified a filter, but there is no corresponding SQL ($extends)
self::$_importFields[$cacheKey] = [];
return self::$_importFields[$cacheKey];
Civi::$statics[__CLASS__]['importFields'][$cacheKey] = [];
return Civi::$statics[__CLASS__]['importFields'][$cacheKey];
}

if ($onlyParent) {
Expand Down Expand Up @@ -543,10 +522,10 @@ public static function &getFields(

Civi::cache('fields')->set("custom importableFields $cacheKey", $fields);
}
self::$_importFields[$cacheKey] = $fields;
Civi::$statics[__CLASS__]['importFields'][$cacheKey] = $fields;
}

return self::$_importFields[$cacheKey];
return Civi::$statics[__CLASS__]['importFields'][$cacheKey];
}

/**
Expand Down
1 change: 0 additions & 1 deletion CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,6 @@ public static function flushCache() {
= CRM_Contribute_BAO_Contribution::$_importableFields
= CRM_Contribute_BAO_Contribution::$_exportableFields
= CRM_Pledge_BAO_Pledge::$_exportableFields
= CRM_Core_BAO_CustomField::$_importFields
= CRM_Core_BAO_Cache::$_cache = CRM_Core_DAO::$_dbColumnValueCache = NULL;

CRM_Core_OptionGroup::flushAll();
Expand Down

0 comments on commit a7fad9c

Please sign in to comment.