diff --git a/searchindex_wipe.info.yml b/searchindex_wipe.info.yml index 964181c..3206ab7 100644 --- a/searchindex_wipe.info.yml +++ b/searchindex_wipe.info.yml @@ -5,4 +5,4 @@ dependencies: package: search type: module core: '8.x' -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 diff --git a/searchindex_wipe.module b/searchindex_wipe.module index 29c3a63..4fdf435 100644 --- a/searchindex_wipe.module +++ b/searchindex_wipe.module @@ -8,6 +8,8 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Database\Database; +use Drupal\Core\Messenger\MessengerInterface; /** * Implements hook_form_FORM_ID_alter(). @@ -32,18 +34,30 @@ function searchindex_wipe_all(&$form, FormStateInterface $form_state) { } /** - * Helper function to truncate search related tables. + * Truncate search related tables and display a message. */ function searchindex_wipe_truncate_table() { - // Taken code from drupal_uninstall_schema. - $schema = drupal_get_module_schema('search'); - foreach ($schema as $table_name => $table) { - // Truncate search related tables. - \Drupal::database()->truncate($table_name)->execute(); + // Get the database service. + $database = Database::getConnection(); + + // Define the tables to truncate. + $tables_to_truncate = [ + 'search_index', + 'search_dataset', + // Add more tables related to the search module here if needed. + ]; + + // Truncate each table. + foreach ($tables_to_truncate as $table_name) { + $database->truncate($table_name)->execute(); } - \Drupal::messenger()->addMessage(t('Search Index Cleared, Please rebuilt the index by running cron.')); + + // Display a message to the user. + $messenger = \Drupal::messenger(); + $messenger->addMessage(t('Search Index Cleared. Please rebuild the index by running cron.'), MessengerInterface::TYPE_STATUS); } + /** * Implements hook_help(). */