Skip to content
Snippets Groups Projects
Unverified Commit 2ac16f93 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #24743 from totten/import_load-a

Ensure that class-index is up-to-date after toggling extensions (A)
parents 1e956573 c0db4b22
Branches
Tags
No related merge requests found
......@@ -34,6 +34,10 @@ class CRM_Extension_Manager_Module extends CRM_Extension_Manager_Base {
$this->callHook($info, 'enable');
}
public function onPostInstall(CRM_Extension_Info $info) {
\Civi\Core\ClassScanner::cache('index')->flush();
}
/**
* @param CRM_Extension_Info $info
*/
......@@ -80,6 +84,7 @@ class CRM_Extension_Manager_Module extends CRM_Extension_Manager_Base {
* @param CRM_Extension_Info $info
*/
public function onPostUninstall(CRM_Extension_Info $info) {
\Civi\Core\ClassScanner::cache('index')->flush();
}
/**
......@@ -89,6 +94,10 @@ class CRM_Extension_Manager_Module extends CRM_Extension_Manager_Base {
$this->callHook($info, 'disable');
}
public function onPostDisable(CRM_Extension_Info $info) {
\Civi\Core\ClassScanner::cache('index')->flush();
}
/**
* @param CRM_Extension_Info $info
*/
......@@ -97,6 +106,10 @@ class CRM_Extension_Manager_Module extends CRM_Extension_Manager_Base {
$this->callHook($info, 'enable');
}
public function onPostEnable(CRM_Extension_Info $info) {
\Civi\Core\ClassScanner::cache('index')->flush();
}
public function onPostReplace(CRM_Extension_Info $oldInfo, CRM_Extension_Info $newInfo) {
// Like everything, ClassScanner is probably affected by pre-existing/long-standing issue dev/core#3686.
// This may mitigate a couple edge-cases. But really #3686 needs a different+deeper fix.
......
......@@ -9,6 +9,7 @@ use Civi\Api4\ContributionSoft;
use Civi\Api4\DedupeRule;
use Civi\Api4\DedupeRuleGroup;
use Civi\Api4\Email;
use Civi\Api4\Import;
use Civi\Api4\Note;
use Civi\Api4\OptionValue;
use Civi\Api4\UserJob;
......@@ -31,6 +32,26 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase {
*/
protected $entity = 'Contribution';
/**
* These extensions are inactive at the start. They may be activated during the test. They should be deactivated at the end.
*
* For the moment, the test is simply hard-coded to cleanup in a specific order. It's tempting to auto-detect and auto-uninstall these.
* However, the shape of their dependencies makes it tricky to auto-uninstall (e.g. some exts have managed-entities that rely on other
* exts -- you need to fully disable+uninstall the downstream managed-entity-ext before disabling or uninstalling the upstream
* entity-provider-ext).
*
* You may need to edit `$toggleExts` whenever the dependency-graph changes.
*
* @var string[]
*/
protected $toggleExts = ['civiimport', 'org.civicrm.search_kit', 'org.civicrm.afform', 'authx'];
protected function setUp(): void {
parent::setUp();
$origExtensions = array_column(CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(), 'fullName');
$this->assertEquals([], array_intersect($origExtensions, $this->toggleExts), 'These extensions may be enabled and disabled during the test. The start-state and end-state should be the same. It appears that we have an unexpected start-state. Perhaps another test left us with a weird start-state?');
}
/**
* Cleanup function.
*
......@@ -43,6 +64,10 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase {
DedupeRule::delete()
->addWhere('rule_table', '!=', 'civicrm_email')
->addWhere('dedupe_rule_group_id.name', '=', 'IndividualUnsupervised')->execute();
foreach ($this->toggleExts as $ext) {
CRM_Extension_System::singleton()->getManager()->disable([$ext]);
CRM_Extension_System::singleton()->getManager()->uninstall([$ext]);
}
parent::tearDown();
}
......@@ -817,4 +842,14 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase {
]);
}
/**
* Test the Import api works from the extension when the extension is enabled after the import.
*/
public function testEnableExtension(): void {
$this->importContributionsDotCSV();
$this->callAPISuccess('Extension', 'enable', ['key' => 'civiimport']);
$result = Import::get($this->userJobID)->execute();
$this->assertEquals('ERROR', $result->first()['_status']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment