From ea1176e336be38cfe846bee7ef0149ba9d0d67b4 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 23 Jul 2011 19:50:19 +0000 Subject: [PATCH] Changed Maintenance::shouldExecute() to allow for multiple requires() in the stack. This avoids failing over requires due to Het wrappers. --- maintenance/Maintenance.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 196e0dd849..6eb8c50239 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -133,18 +133,25 @@ abstract class Maintenance { /** * Should we execute the maintenance script, or just allow it to be included * as a standalone class? It checks that the call stack only includes this - * function and a require (meaning was called from the file scope) + * function and "requires" (meaning was called from the file scope) * * @return Boolean */ public static function shouldExecute() { $bt = debug_backtrace(); - if( count( $bt ) !== 2 ) { - return false; + if ( count( $bt ) < 2 ) { + return false; // sanity + } + if ( $bt[0]['class'] !== 'Maintenance' || $bt[0]['function'] !== 'shouldExecute' ) { + return false; // last call should be to this function + } + $includeFuncs = array( 'require_once', 'require', 'include' ); + for( $i=1; $i < count( $bt ); $i++ ) { + if ( !in_array( $bt[$i]['function'], $includeFuncs ) ) { + return false; // previous calls should all be "requires" + } } - return in_array( $bt[1]['function'], array( 'require_once', 'require', 'include' ) ) && - $bt[0]['class'] == 'Maintenance' && - $bt[0]['function'] == 'shouldExecute'; + return true; } /** -- 2.20.1