Skip to content

Commit

Permalink
Make SearchKit a required extension
Browse files Browse the repository at this point in the history
This enables SearchKit during upgrade and on (most) new installs.

SearchKit was already being enabled on the standard "setup" API,
but some installers don't yet use it. (https://lab.civicrm.org/dev/core/-/issues/1615)

As a hedge I've also added a system status check which gives a warning and prompts the admin
to immediately install required extensions.
  • Loading branch information
colemanw committed Nov 15, 2022
1 parent e59cce0 commit f925535
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CRM/Admin/Page/Extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public function formatLocalExtensionRows() {
$keys = array_keys($manager->getStatuses());
sort($keys);
$hiddenExtensions = $mapper->getKeysByTag('mgmt:hidden');
$requiredExtensions = $mapper->getKeysByTag('mgmt:required');
foreach ($keys as $key) {
if (in_array($key, $hiddenExtensions)) {
continue;
Expand Down Expand Up @@ -202,7 +203,7 @@ public function formatLocalExtensionRows() {
}
// TODO if extbrowser is enabled and extbrowser has newer version than extcontainer,
// then $action += CRM_Core_Action::UPDATE
if ($action) {
if ($action && !in_array($key, $requiredExtensions)) {
$row['action'] = CRM_Core_Action::formLink(self::links(),
$action,
['id' => $row['id'], 'key' => $obj->key],
Expand Down
7 changes: 7 additions & 0 deletions CRM/Extension/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ public function disable($keys) {

sort($keys);
$disableRequirements = $this->findDisableRequirements($keys);

$requiredExtensions = $this->mapper->getKeysByTag('mgmt:required');

// This munges order, but makes it comparable.
sort($disableRequirements);
if ($keys !== $disableRequirements) {
Expand All @@ -388,6 +391,10 @@ public function disable($keys) {

foreach ($keys as $key) {
if (isset($origStatuses[$key])) {
if (in_array($key, $requiredExtensions)) {
throw new CRM_Extension_Exception("Cannot disable required extension: $key");
}

switch ($origStatuses[$key]) {
case self::STATUS_INSTALLED:
$this->addProcess([$key], 'disabling');
Expand Down
4 changes: 4 additions & 0 deletions CRM/Extension/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public static function createExtendedInfo(CRM_Extension_Info $obj) {
$extensionRow['path'] = '';
}
$extensionRow['status'] = $manager->getStatus($obj->key);
$requiredExtensions = $mapper->getKeysByTag('mgmt:required');

switch ($extensionRow['status']) {
case CRM_Extension_Manager::STATUS_UNINSTALLED:
Expand Down Expand Up @@ -371,6 +372,9 @@ public static function createExtendedInfo(CRM_Extension_Info $obj) {
if ($manager->isIncompatible($obj->key)) {
$extensionRow['statusLabel'] = ts('Obsolete') . ($extensionRow['statusLabel'] ? (' - ' . $extensionRow['statusLabel']) : '');
}
elseif (in_array($obj->key, $requiredExtensions)) {
$extensionRow['statusLabel'] = ts('Required');
}
return $extensionRow;
}

Expand Down
1 change: 1 addition & 0 deletions CRM/Upgrade/Incremental/php/FiveFiftySeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CRM_Upgrade_Incremental_php_FiveFiftySeven extends CRM_Upgrade_Incremental
*/
public function upgrade_5_57_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addExtensionTask('Enable SearchKit extension', ['org.civicrm.search_kit']);
}

}
19 changes: 19 additions & 0 deletions CRM/Utils/Check/Component/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ public function checkExtensions() {
$enabled = array_keys(array_filter($stauses, function($status) {
return $status === CRM_Extension_Manager::STATUS_INSTALLED;
}));
$requiredExtensions = $mapper->getKeysByTag('mgmt:required');
sort($keys);
$updates = $errors = $okextensions = [];

Expand Down Expand Up @@ -660,6 +661,24 @@ public function checkExtensions() {
}
}
break;

default:
if (in_array($key, $requiredExtensions, TRUE)) {
$requiredMessage = new CRM_Utils_Check_Message(
__FUNCTION__ . 'Required:' . $key,
ts('The extension %1 is required and must be enabled.', [1 => $row['label']]),
ts('Required Extension'),
\Psr\Log\LogLevel::ERROR,
'fa-exclamation-triangle'
);
$requiredMessage->addAction(
ts('Enable %1', [1 => $row['label']]),
'',
'api3',
['Extension', 'install', ['key' => $key]]
);
$messages[] = $requiredMessage;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion bin/regen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ php GenerateData.php

## Prune local data
$MYSQLCMD -e "DROP TABLE IF EXISTS civicrm_install_canary; DELETE FROM civicrm_cache; DELETE FROM civicrm_setting;"
$MYSQLCMD -e "DELETE FROM civicrm_extension WHERE full_name NOT IN ('sequentialcreditnotes', 'eventcart', 'greenwich', 'search', 'org.civicrm.flexmailer', 'financialacls', 'contributioncancelactions', 'recaptcha', 'ckeditor4', 'legacycustomsearches', 'civiimport');"
$MYSQLCMD -e "DELETE FROM civicrm_extension WHERE full_name NOT IN ('sequentialcreditnotes', 'eventcart', 'greenwich', 'org.civicrm.search_kit', 'org.civicrm.flexmailer', 'financialacls', 'contributioncancelactions', 'recaptcha', 'ckeditor4', 'legacycustomsearches', 'civiimport');"
TABLENAMES=$( echo "show tables like 'civicrm_%'" | $MYSQLCMD | grep ^civicrm_ | xargs )

cd $CIVISOURCEDIR/sql
Expand Down
5 changes: 4 additions & 1 deletion ext/search_kit/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
<releaseDate>2021-01-06</releaseDate>
<version>5.57.alpha1</version>
<develStage>stable</develStage>
<tags>
<tag>mgmt:required</tag>
</tags>
<compatibility>
<ver>5.57</ver>
</compatibility>
<comments>This extension is still in beta. Click on the chat link above to discuss development, report problems or ask questions.</comments>
<comments>Click on the chat link above to discuss development, report problems or ask questions.</comments>
<classloader>
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
Expand Down

0 comments on commit f925535

Please sign in to comment.