From 0d96bb666ae908307fdf98d7fa98caca8586cadc Mon Sep 17 00:00:00 2001 From: Alberto Paderno <apaderno@isepro.org> Date: Mon, 22 Jul 2024 20:41:34 +0200 Subject: [PATCH] Issue #2979423: Drush commands fail with "Error: Call to undefined function module_exists()" --- apc.drush.inc | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/apc.drush.inc b/apc.drush.inc index 19e0dcd..78410ad 100644 --- a/apc.drush.inc +++ b/apc.drush.inc @@ -11,18 +11,26 @@ function apc_drush_exit() { global $base_url; - if (!module_exists('apc')) { - drush_log( - dt('You need to enable the Alternative PHP Cache module for remote cache clearing to work. Run drush pm-enable apc.'), - 'error' - ); - return; - } - if (class_exists('DrupalApcCache')) { $requests = DrupalApcCache::pendingRequests(); - if (!empty($requests)) { + if (!empty($requests) && is_array($requests)) { + if (!function_exists('module_exists')) { + // Drupal bootstrap did not reach the DRUPAL_BOOTSTRAP_VARIABLES phase, + // or module_exists() would be defined. This means it is not possible to + // check if the Alternative PHP Cache module is available. + // Exit silently. + return; + } + + if (!module_exists('apc')) { + drush_log( + dt('You need to enable the Alternative PHP Cache module to clear the cache on the server.'), + 'error' + ); + return; + } + $star = serialize('*'); foreach (array_keys($requests) as $key) { @@ -54,7 +62,7 @@ function apc_drush_exit() { if ($base_url == 'http://' . basename(conf_path())) { drush_log( - dt('$base_url might not be set correctly. Try using the -l/--uri option for Drush.'), + dt('$base_url might not be set correctly.'), 'warning' ); } -- GitLab