Uninstall for `org.civicrm.search` extension fails
Overview
The "Search" extension throws error when attempting to uninstall.
Reproduction steps
This reproduces with either quick/direct uninstall or a long/multistep uninstall.
## Quick/direct uninstall
cv en search
cv ext:uninstall search
## Long/multi-step uninstall
cv en search
cv dis search
cv ext:uninstall search
Current behavior
The uninstall fails with error:
Entity declaration references invalid or inactive module name [org.civicrm.search]
As in:
$ cv ext:uninstall search
Uninstalling extension "org.civicrm.search"
Error: API Call Failed: Array
(
[entity] => Extension
[action] => uninstall
[params] => Array
(
[keys] => Array
(
[0] => org.civicrm.search
)
[debug] => 1
[version] => 3
)
[result] => Array
(
[trace] => #0 /home/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/CRM/Core/ManagedEntities.php(127): CRM_Core_ManagedEntities->reconcileEnabledModules()
#1 /home/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/CRM/Core/Invoke.php(400): CRM_Core_ManagedEntities->reconcile()
#2 /home/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/CRM/Extension/Manager.php(478): CRM_Core_Invoke::rebuildMenuAndCaches(true)
#3 /home/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/api/v3/Extension.php(183): CRM_Extension_Manager->uninstall(Array)
#4 /home/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_extension_uninstall(Array)
#5 /home/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/API/Kernel.php(149): Civi\API\Provider\MagicFunctionProvider->invoke(Array)
#6 /home/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/API/Kernel.php(81): Civi\API\Kernel->runRequest(Array)
#7 /home/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/api/api.php(22): Civi\API\Kernel->runSafe('Extension', 'uninstall', Array)
#8 phar:///home/totten/bknix/bin/cv/src/Command/BaseCommand.php(49): civicrm_api('Extension', 'uninstall', Array)
#9 phar:///home/totten/bknix/bin/cv/src/Command/ExtensionUninstallCommand.php(63): Civi\Cv\Command\BaseCommand->callApiSuccess(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput), 'Extension', 'uninstall', Array)
#10 phar:///home/totten/bknix/bin/cv/vendor/symfony/console/Command/Command.php(257): Civi\Cv\Command\ExtensionUninstallCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 phar:///home/totten/bknix/bin/cv/vendor/symfony/console/Application.php(850): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 phar:///home/totten/bknix/bin/cv/vendor/symfony/console/Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(Civi\Cv\Command\ExtensionUninstallCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 phar:///home/totten/bknix/bin/cv/src/Application.php(46): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 phar:///home/totten/bknix/bin/cv/vendor/symfony/console/Application.php(124): Civi\Cv\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 phar:///home/totten/bknix/bin/cv/src/Application.php(15): Symfony\Component\Console\Application->run()
#16 phar:///home/totten/bknix/bin/cv/bin/cv(27): Civi\Cv\Application::main('phar:///home/to...')
#17 /home/totten/bknix/bin/cv(14): require('phar:///home/to...')
#18 {main}
[is_error] => 1
[error_message] => Entity declaration references invalid or inactive module name [org.civicrm.search]
)
)
Expected behavior
No error. Remove old artifacts.
Environment information
-
CiviCRM: Spot-checked multiple branches:
master
,5.35
,5.33
- PHP: 7.2
- CMS: D7
- Database: MySQL 5.7
- Web Server: Apache
Comments
(1) I took a first pass at debugging this, but I got a bit distracted because the symptom had changed for unrelated reasons. However, with #20116 merged, we're back to the original symptom (which presents consistently on master
/ 5.35
/ 5.33
).
(2) I have not done any triage to determine if this problem is unique to org.civicrm.search
or if it affects other extensions.
(3) When reconciling managed entities, the basic idea is to compare a couple lists (1: the list of previously-installed entities vs 2: the list of currently-declared entities). By comparing, you can sort the entities into buckets (e.g. things to be inserted vs preserved vs updated vs removed). The error arises while sorting out these buckets - and indicates some inconsistency in the data.
public function reconcileEnabledModules() {
// Note: any thing currently declared is necessarily from
// an active module -- because we got it from a hook!
// index by moduleName,name
$decls = self::createDeclarationIndex($this->moduleIndex, $this->getDeclarations());
foreach ($decls as $moduleName => $todos) {
if (isset($this->moduleIndex[TRUE][$moduleName])) {
$this->reconcileEnabledModule($this->moduleIndex[TRUE][$moduleName], $todos);
}
elseif (isset($this->moduleIndex[FALSE][$moduleName])) {
// do nothing -- module should get swept up later
}
else {
throw new Exception("Entity declaration references invalid or inactive module name [$moduleName]");
}
}
}
I think this exception represents an assertion that $this->moduleIndex[$installStatus][$moduleName]
should be complete (ie identifying the statuses of all relevant modules). Since org.civicrm.search
is being uninstalled, you'd expect to see it in $this->moduleIndex[FALSE]['org.civicrm.search']
.