$hookParams = ['id' => $optionValueId];
CRM_Utils_Hook::pre('delete', 'OptionValue', $optionValueId, $hookParams);
if (self::updateRecords($optionValueId, CRM_Core_Action::DELETE)) {
+ Civi::cache('metadata')->flush();
CRM_Core_PseudoConstant::flush();
$optionValue->delete();
CRM_Utils_Hook::post('delete', 'OptionValue', $optionValueId, $optionValue);
* The values as specified by the params
*/
public static function &values(
- $name, $flip = FALSE, $grouping = FALSE,
+ string $name, $flip = FALSE, $grouping = FALSE,
$localize = FALSE, $condition = NULL,
$labelColumnName = 'label', $onlyActive = TRUE, $fresh = FALSE, $keyColumnName = 'value',
$orderBy = 'weight'
) {
- $cache = CRM_Utils_Cache::singleton();
+
if (self::isDomainOptionGroup($name)) {
$cacheKey = self::createCacheKey($name, CRM_Core_I18n::getLocale(), $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive, $keyColumnName, $orderBy, CRM_Core_Config::domainID());
}
else {
$cacheKey = self::createCacheKey($name, CRM_Core_I18n::getLocale(), $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive, $keyColumnName, $orderBy);
}
-
+ $cache = Civi::cache('metadata');
if (!$fresh) {
- // Fetch from static var
- if (array_key_exists($cacheKey, self::$_cache)) {
- return self::$_cache[$cacheKey];
- }
- // Fetch from main cache
- self::$_cache[$cacheKey] = $cache->get($cacheKey);
- if (self::$_cache[$cacheKey] !== NULL) {
- return self::$_cache[$cacheKey];
+ if ($cache->has($cacheKey)) {
+ $result = $cache->get($cacheKey);
+ return $result;
}
}
+ else {
+ CRM_Core_Error::deprecatedWarning('do not call to flush cache');
+ }
$query = "
SELECT v.{$labelColumnName} as {$labelColumnName} ,v.{$keyColumnName} as value, v.grouping as `grouping`
AND g.is_active = 1 ";
if ($onlyActive) {
- $query .= " AND v.is_active = 1 ";
+ $query .= ' AND v.is_active = 1 ';
// Only show options for enabled components
$componentClause = ' v.component_id IS NULL ';
$enabledComponents = CRM_Core_Config::singleton()->enableComponents;
$query .= " AND ($componentClause) ";
}
if (self::isDomainOptionGroup($name)) {
- $query .= " AND v.domain_id = " . CRM_Core_Config::domainID();
+ $query .= ' AND v.domain_id = ' . CRM_Core_Config::domainID();
}
if ($condition) {
// call option value hook
CRM_Utils_Hook::optionValues($var, $name);
- self::$_cache[$cacheKey] = $var;
$cache->set($cacheKey, $var);
return $var;
*
* @throws CRM_Core_Exception
*/
- public function onPreInstall(CRM_Extension_Info $info) {
+ public function onPreInstall(CRM_Extension_Info $info): void {
$customReports = $this->getCustomReportsByName();
if (array_key_exists($info->key, $customReports)) {
throw new CRM_Core_Exception(ts('This report is already registered.'));
'is_active' => 1,
];
- $optionValue = CRM_Core_BAO_OptionValue::add($params);
+ CRM_Core_BAO_OptionValue::add($params);
}
/**
* @return array
*/
public function getCustomReportsByName() {
- return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE);
+ return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE);
}
/**
* @return array
*/
public function getCustomReportsById() {
- return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE);
+ return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE);
}
}
/**
* @return array
*/
- protected function getCustomSearchesByName() {
- return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE);
+ protected function getCustomSearchesByName(): array {
+ return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE);
}
/**
* @return array
*/
- protected function getCustomSearchesById() {
- return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE);
+ protected function getCustomSearchesById(): array {
+ return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE);
}
}
/**
* Check that pseudoconstant reflects new value added.
*/
- public function testCRM11876CreateOptionPseudoConstantUpdated() {
+ public function testCRM11876CreateOptionPseudoConstantUpdated(): void {
$optionGroupID = $this->callAPISuccess('option_group', 'getvalue', [
'name' => 'payment_instrument',
'return' => 'id',
'label' => $newOption,
]);
- $fields = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
- $this->assertTrue(in_array($newOption, $fields['values']));
+ $fields = $this->callAPISuccess('Contribution', 'getoptions', ['field' => 'payment_instrument_id']);
+ $this->assertContains($newOption, $fields['values']);
- $this->callAPISuccess('option_value', 'delete', ['id' => $apiResult['id']]);
+ $this->callAPISuccess('OptionValue', 'delete', ['id' => $apiResult['id']]);
- $fields = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
- $this->assertFalse(in_array($newOption, $fields['values']));
+ $fields = $this->callAPISuccess('Contribution', 'getoptions', ['field' => 'payment_instrument_id']);
+ $this->assertNotContains($newOption, $fields['values']);
}
/**