/**
* Initialise.
*
- * @param bool $fresh
+ * @param bool $fresh Deprecated parameter, use flush() to flush.
*/
- public static function init($fresh = FALSE) {
- static $init = FALSE;
- if ($init && !$fresh) {
+ public static function init(bool $fresh = FALSE): void {
+ if (!empty(Civi::$statics[__CLASS__]['initialised']) && !$fresh) {
return;
}
+ if ($fresh) {
+ CRM_Core_Error::deprecatedWarning('Use CRM_Core_DAO_AllCoreTables::flush()');
+ }
+ Civi::$statics[__CLASS__]['initialised'] = TRUE;
Civi::$statics[__CLASS__] = [];
$file = preg_replace('/\.php$/', '.data.php', __FILE__);
);
}
- $init = TRUE;
+ Civi::$statics[__CLASS__]['initialised'] = TRUE;
+ }
+
+ /**
+ * Flush class cache.
+ */
+ public static function flush(): void {
+ Civi::$statics[__CLASS__]['initialised'] = FALSE;
}
/**
// 2. Now, let's hook into it...
$this->hookClass->setHook('civicrm_entityTypes', [$this, '_hook_civicrm_entityTypes']);
unset(Civi::$statics['CRM_Core_DAO_Email']);
- CRM_Core_DAO_AllCoreTables::init(1);
+ CRM_Core_DAO_AllCoreTables::flush();
// 3. And see if the data has changed...
$fields = CRM_Core_DAO_Email::fields();
protected function tearDown(): void {
CRM_Utils_Hook::singleton()->reset();
- CRM_Core_DAO_AllCoreTables::init(1);
+ CRM_Core_DAO_AllCoreTables::flush();
parent::tearDown();
}
*
* @throws \CRM_Core_Exception
*/
- public function testHookDupeQueryMatch() {
+ public function testHookDupeQueryMatch(): void {
$this->hookClass->setHook('civicrm_dupeQuery', [$this, 'hook_civicrm_dupeQuery']);
- \CRM_Core_DAO_AllCoreTables::init(TRUE);
+ \CRM_Core_DAO_AllCoreTables::flush();
\CRM_Core_DAO_AllCoreTables::registerEntityType('TestEntity', 'CRM_Dedupe_DAO_TestEntity', 'civicrm_dedupe_test_table');
$this->apiKernel = \Civi::service('civi_api_kernel');
$this->assertCount(0, $foundDupes);
CRM_Core_DAO::executeQuery('DROP TABLE civicrm_dedupe_test_table');
- \CRM_Core_DAO_AllCoreTables::init(TRUE);
+ \CRM_Core_DAO_AllCoreTables::flush();
}
/**
protected function setUp(): void {
parent::setUp();
- \CRM_Core_DAO_AllCoreTables::init(TRUE);
+ \CRM_Core_DAO_AllCoreTables::flush();
\CRM_Core_DAO_AllCoreTables::registerEntityType('FakeFile', 'CRM_Fake_DAO_FakeFile', 'fake_file');
$fileProvider = new StaticProvider(
protected function tearDown(): void {
parent::tearDown();
- \CRM_Core_DAO_AllCoreTables::init(TRUE);
+ \CRM_Core_DAO_AllCoreTables::flush();
}
/**
* @dataProvider restrictionCases
*/
public function testEach($apiRequest, $rules, $expectSuccess) {
- \CRM_Core_DAO_AllCoreTables::init(TRUE);
+ \CRM_Core_DAO_AllCoreTables::flush();
$recs = $this->getFixtures();
/**
* Install the custom api.
*/
- public function installApi() {
+ public function installApi(): void {
require_once __DIR__ . '/custom_api/MailingProviderData.php';
$this->hookClass->setHook('civicrm_entityTypes', [$this, 'hookEntityTypes']);
- CRM_Core_DAO_AllCoreTables::init(TRUE);
+ CRM_Core_DAO_AllCoreTables::flush();
CRM_Core_DAO::executeQuery(
"CREATE TABLE IF NOT EXISTS `civicrm_mailing_provider_data` (
`contact_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',