Option value cache key missing domain ID can result in wrong value retrieved for domain
I cannot provide steps to recreate the issue on dmaster because it's related to a multi-domain setup.
Our step to recreate was to:
- Log in on domain ID 1, send a test email, the 'from' address was 'email@example.com'
- Log in on domain ID 2, send a test email, the 'from' address was still 'firstname.lastname@example.org' (expecting @domain2.com)
In a multi-domain setup, the wrong option value for domain-sensitive option values can be returned. eg:
\CRM_Core_BAO_Domain::getNameAndEmail returns the name and email of a different domain to the current one.
The problem stems from:
The value names 'from_email_address' and 'grant_type' can be different depending on the domain ID they are looked up from.
However, the cacheKey does not include the domain ID, so the value for one domain could be cached, and returned when the query is for another domain:
$cacheKey = self::createCacheKey($name, $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive, $keyColumnName, $orderBy);
The domain ID is calculated lower down in the function, and is not passed in as a param.
I think this can be resolved by adding the domainID to the cache key - but only for domain-sensitive values (so as not to reduce performance for values that are shared across multiple domains).
I also noticed a mis-match between the current cacheKey (see above), and the one that is generated from flushValues:
$cacheKey = self::createCacheKey($name, $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive, $keyColumnName); - the one in flushValues is missing the 'orderBy'. Is this a different problem?