diff --git a/plugins/system/debug/debug.php b/plugins/system/debug/debug.php index 15bd3af39172a..20bff5b16cad9 100644 --- a/plugins/system/debug/debug.php +++ b/plugins/system/debug/debug.php @@ -126,50 +126,6 @@ class PlgSystemDebug extends CMSPlugin */ protected $isAjax = false; - /** - * Constructor. - * - * @param DispatcherInterface &$subject The object to observe. - * @param array $config An optional associative array of configuration settings. - * - * @since 1.5 - */ - public function __construct(&$subject, $config) - { - parent::__construct($subject, $config); - - $this->debugLang = $this->app->get('debug_lang'); - - // Skip the plugin if debug is off - if (!$this->debugLang && !$this->app->get('debug')) - { - return; - } - - $this->app->getConfig()->set('gzip', false); - ob_start(); - ob_implicit_flush(false); - - /** @var \Joomla\Database\Monitor\DebugMonitor */ - $this->queryMonitor = $this->db->getMonitor(); - - if (!$this->params->get('queries', 1)) - { - // Remove the database driver monitor - $this->db->setMonitor(null); - } - - $storagePath = JPATH_CACHE . '/plg_system_debug_' . $this->app->getName(); - - $this->debugBar = new DebugBar; - $this->debugBar->setStorage(new FileStorage($storagePath)); - - $this->isAjax = $this->app->input->get('option') === 'com_ajax' - && $this->app->input->get('plugin') === 'debug' && $this->app->input->get('group') === 'system'; - - $this->setupLogging(); - } - /** * Add the CSS for debug. * We can't do this in the constructor because stuff breaks. @@ -180,6 +136,8 @@ public function __construct(&$subject, $config) */ public function onAfterDispatch() { + $this->setupPlugin(); + // Only if debugging or language debug is enabled. if ((JDEBUG || $this->debugLang) && $this->isAuthorisedDisplayDebug() && strtolower($this->app->getDocument()->getType()) === 'html') { @@ -208,6 +166,8 @@ public function onAfterDispatch() */ public function onAfterRespond() { + $this->setupPlugin(); + // Do not render if debugging or language debug is not enabled. if (!JDEBUG && !$this->debugLang || $this->isAjax || strtolower($this->app->getDocument()->getType()) !== 'html') { @@ -324,6 +284,8 @@ public function onAfterRespond() */ public function onAjaxDebug() { + $this->setupPlugin(); + // Do not render if debugging or language debug is not enabled. if (!JDEBUG && !$this->debugLang) { @@ -347,6 +309,53 @@ public function onAjaxDebug() } } + /** + * Does the setup for the plugin. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + private function setupPlugin() + { + // Check if setup was done already + if ($this->queryMonitor) + { + return; + } + + $this->debugLang = $this->app->get('debug_lang'); + + // Skip the plugin if debug is off + if (!$this->debugLang && !$this->app->get('debug')) + { + return; + } + + $this->app->getConfig()->set('gzip', false); + ob_start(); + ob_implicit_flush(false); + + /** @var \Joomla\Database\Monitor\DebugMonitor */ + $this->queryMonitor = $this->db->getMonitor(); + + if (!$this->params->get('queries', 1)) + { + // Remove the database driver monitor + $this->db->setMonitor(null); + } + + $storagePath = JPATH_CACHE . '/plg_system_debug_' . $this->app->getName(); + + $this->debugBar = new DebugBar; + $this->debugBar->setStorage(new FileStorage($storagePath)); + + $this->isAjax = $this->app->input->get('option') === 'com_ajax' + && $this->app->input->get('plugin') === 'debug' && $this->app->input->get('group') === 'system'; + + $this->setupLogging(); + } + /** * Setup logging functionality. * @@ -454,6 +463,8 @@ private function isAuthorisedDisplayDebug(): bool */ public function onAfterDisconnect(ConnectionEvent $event) { + $this->setupPlugin(); + if (!JDEBUG) { return;