GenCode, Cache::cleanKey() - Fix deploop during clean initialization
authorTim Otten <totten@civicrm.org>
Wed, 10 Jul 2019 02:21:58 +0000 (19:21 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 10 Jul 2019 05:42:07 +0000 (22:42 -0700)
commit77f080cbe1c0062631f43244d7f37edfc133c0b7
tree55a32b4a8da816f39cd5e3697c4eb8e54b6bd1b5
parent0e42e612431bf5bc6a5b27dc229ee954e36f3862
GenCode, Cache::cleanKey() - Fix deploop during clean initialization

Overview
--------

Suppose you have a clean codebase with no DAO files, and you try to run `xml/GenCode.php`.
This currently crashes.

The problem is not symptomatic day-to-day because we commit DAOs, so it's
very rare to run a full/clean initialization.  However, it does get in the
way of stress-testing the correctness of GenCode.

Before
------

Since 76e697a9d750d568d0d12c10dd8173f656e8bb1e, I believe we've had a dependency-loop
in the clean-gencode scenario, which works as follows:

* We don't have any DAOs, so we run `GenCode`.
* Running `GenCode` does a partial bootstrap (i.e. `CRM_Core_Config::singleton($loadFromDB===FALSE)`)
* The partial bootstrap creates some thread-local caches (`Arraycache`)
* Before creating the cache, it normalizes the name by calling `CRM_Core_BAO_Cache::cleanKey()`
* `CRM_Core_BAO_Cache` extends `CRM_Core_DAO_Cache`
* `CRM_Core_BAO_Cache` doesn't exist - that's why we called `GenCode` at the beginning.

After
-----

This migrates the utility function `cleanKey()` to another class which is always available and
does not rely on DAOs.
CRM/ACL/BAO/ACL.php
CRM/Contact/BAO/ContactType.php
CRM/Core/BAO/Cache.php
CRM/Core/BAO/Cache/Psr16.php
CRM/Core/BAO/PrevNextCache.php
CRM/Core/PseudoConstant.php
CRM/Utils/Cache.php
CRM/Utils/Cache/SqlGroup.php
tests/phpunit/CRM/Core/BAO/CacheTest.php