Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 345dc83

Browse files
committed
Update to 3.0.0 of Query Monitor
1 parent 22a5702 commit 345dc83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2893
-2673
lines changed

www/wp-content/plugins/query-monitor/assets/query-monitor.css

Lines changed: 585 additions & 392 deletions
Large diffs are not rendered by default.

www/wp-content/plugins/query-monitor/assets/query-monitor.js

Lines changed: 371 additions & 299 deletions
Large diffs are not rendered by default.

www/wp-content/plugins/query-monitor/classes/Activation.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
<?php
2-
/*
3-
Copyright 2009-2017 John Blackbourn
4-
5-
This program is free software; you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation; either version 2 of the License, or
8-
(at your option) any later version.
9-
10-
This program is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
14-
15-
*/
2+
/**
3+
* Plugin activation handler.
4+
*
5+
* @package query-monitor
6+
*/
167

178
class QM_Activation extends QM_Plugin {
189

1910
protected function __construct( $file ) {
2011

12+
# PHP version handling
13+
if ( ! self::php_version_met() ) {
14+
add_action( 'all_admin_notices', array( $this, 'php_notice' ) );
15+
return;
16+
}
17+
2118
# Filters
2219
add_filter( 'pre_update_option_active_plugins', array( $this, 'filter_active_plugins' ) );
2320
add_filter( 'pre_update_site_option_active_sitewide_plugins', array( $this, 'filter_active_sitewide_plugins' ) );
@@ -98,6 +95,24 @@ public function filter_active_sitewide_plugins( $plugins ) {
9895

9996
}
10097

98+
public function php_notice() {
99+
?>
100+
<div id="qm_php_notice" class="error">
101+
<p>
102+
<span class="dashicons dashicons-warning" style="color:#dd3232" aria-hidden="true"></span>
103+
<?php
104+
echo esc_html( sprintf(
105+
/* Translators: 1: Minimum required PHP version, 2: Current PHP version. */
106+
__( 'The Query Monitor plugin requires PHP version %1$s or higher. This site is running version %2$s.', 'query-monitor' ),
107+
self::$minimum_php_version,
108+
PHP_VERSION
109+
) );
110+
?>
111+
</p>
112+
</div>
113+
<?php
114+
}
115+
101116
public static function init( $file = null ) {
102117

103118
static $instance = null;

www/wp-content/plugins/query-monitor/classes/Backtrace.php

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
<?php
2-
/*
3-
Copyright 2009-2017 John Blackbourn
4-
5-
This program is free software; you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation; either version 2 of the License, or
8-
(at your option) any later version.
9-
10-
This program is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
14-
15-
*/
2+
/**
3+
* Function call backtrace container.
4+
*
5+
* @package query-monitor
6+
*/
167

178
if ( ! class_exists( 'QM_Backtrace' ) ) {
189
class QM_Backtrace {
1910

2011
protected static $ignore_class = array(
2112
'wpdb' => true,
2213
'QueryMonitor' => true,
23-
'ExtQuery' => true,
2414
'W3_Db' => true,
2515
'Debug_Bar_PHP' => true,
2616
'WP_Hook' => true,
@@ -65,10 +55,9 @@ class QM_Backtrace {
6555
protected $calling_file = '';
6656

6757
public function __construct( array $args = array() ) {
68-
# @TODO save the args as a property and process the trace JIT
6958
$args = array_merge( array(
7059
'ignore_current_filter' => true,
71-
'ignore_items' => 0,
60+
'ignore_frames' => 0,
7261
), $args );
7362
$this->trace = debug_backtrace( false );
7463
$this->ignore( 1 ); # Self-awareness
@@ -81,13 +70,33 @@ public function __construct( array $args = array() ) {
8170
$this->ignore( 1 );
8271
}
8372

84-
if ( $args['ignore_items'] ) {
85-
$this->ignore( $args['ignore_items'] );
73+
if ( $args['ignore_frames'] ) {
74+
$this->ignore( $args['ignore_frames'] );
8675
}
8776
if ( $args['ignore_current_filter'] ) {
8877
$this->ignore_current_filter();
8978
}
9079

80+
foreach ( $this->trace as $k => $frame ) {
81+
if ( ! isset( $frame['args'] ) ) {
82+
continue;
83+
}
84+
85+
if ( isset( self::$show_args[ $frame['function'] ] ) ) {
86+
$show = self::$show_args[ $frame['function'] ];
87+
88+
if ( 'dir' === $show ) {
89+
$show = 1;
90+
}
91+
92+
$frame['args'] = array_slice( $frame['args'], 0, $show );
93+
94+
} else {
95+
unset( $frame['args'] );
96+
}
97+
98+
$this->trace[ $k ] = $frame;
99+
}
91100
}
92101

93102
public function get_stack() {
@@ -111,29 +120,35 @@ public function get_component() {
111120

112121
$components = array();
113122

114-
foreach ( $this->trace as $item ) {
123+
foreach ( $this->trace as $frame ) {
115124
try {
116125

117-
if ( isset( $item['class'] ) ) {
118-
if ( ! is_object( $item['class'] ) and ! class_exists( $item['class'], false ) ) {
126+
if ( isset( $frame['class'] ) ) {
127+
if ( ! class_exists( $frame['class'], false ) ) {
119128
continue;
120129
}
121-
if ( ! method_exists( $item['class'], $item['function'] ) ) {
130+
if ( ! method_exists( $frame['class'], $frame['function'] ) ) {
122131
continue;
123132
}
124-
$ref = new ReflectionMethod( $item['class'], $item['function'] );
133+
$ref = new ReflectionMethod( $frame['class'], $frame['function'] );
125134
$file = $ref->getFileName();
126-
} elseif ( function_exists( $item['function'] ) ) {
127-
$ref = new ReflectionFunction( $item['function'] );
135+
} elseif ( isset( $frame['function'] ) && function_exists( $frame['function'] ) ) {
136+
$ref = new ReflectionFunction( $frame['function'] );
128137
$file = $ref->getFileName();
129-
} elseif ( isset( $item['file'] ) ) {
130-
$file = $item['file'];
138+
} elseif ( isset( $frame['file'] ) ) {
139+
$file = $frame['file'];
131140
} else {
132141
continue;
133142
}
134143

135144
$comp = QM_Util::get_file_component( $file );
136145
$components[ $comp->type ] = $comp;
146+
147+
if ( 'plugin' === $comp->type ) {
148+
// If the component is a plugin then it can't be anything else,
149+
// so short-circuit and return early.
150+
return $comp;
151+
}
137152
} catch ( ReflectionException $e ) {
138153
# nothing
139154
}
@@ -236,7 +251,7 @@ public function filter_trace( array $trace ) {
236251

237252
if ( 'dir' === $show ) {
238253
if ( isset( $trace['args'][0] ) ) {
239-
$arg = QM_Util::standard_dir( $trace['args'][0], '~/' );
254+
$arg = QM_Util::standard_dir( $trace['args'][0], '' );
240255
$return['id'] = $trace['function'] . '()';
241256
$return['display'] = $trace['function'] . "('{$arg}')";
242257
}

www/wp-content/plugins/query-monitor/classes/Collector.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
<?php
2-
/*
3-
Copyright 2009-2017 John Blackbourn
4-
5-
This program is free software; you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation; either version 2 of the License, or
8-
(at your option) any later version.
9-
10-
This program is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
14-
15-
*/
2+
/**
3+
* Abstract data collector.
4+
*
5+
* @package query-monitor
6+
*/
167

178
if ( ! class_exists( 'QM_Collector' ) ) {
189
abstract class QM_Collector {
1910

11+
protected $timer;
2012
protected $data = array(
2113
'types' => array(),
2214
'component_times' => array(),
@@ -57,13 +49,11 @@ protected function log_component( $component, $ltime, $type ) {
5749
if ( ! isset( $this->data['component_times'][ $component->name ] ) ) {
5850
$this->data['component_times'][ $component->name ] = array(
5951
'component' => $component->name,
60-
'calls' => 0,
6152
'ltime' => 0,
6253
'types' => array(),
6354
);
6455
}
6556

66-
$this->data['component_times'][ $component->name ]['calls']++;
6757
$this->data['component_times'][ $component->name ]['ltime'] += $ltime;
6858

6959
if ( isset( $this->data['component_times'][ $component->name ]['types'][ $type ] ) ) {
@@ -124,7 +114,17 @@ public function filter_remove_qm( array $item ) {
124114

125115
public function process() {}
126116

117+
public function post_process() {}
118+
127119
public function tear_down() {}
128120

121+
public function get_timer() {
122+
return $this->timer;
123+
}
124+
125+
public function set_timer( QM_Timer $timer ) {
126+
$this->timer = $timer;
127+
}
128+
129129
}
130130
}

www/wp-content/plugins/query-monitor/classes/Collectors.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
<?php
2-
/*
3-
Copyright 2009-2017 John Blackbourn
4-
5-
This program is free software; you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation; either version 2 of the License, or
8-
(at your option) any later version.
9-
10-
This program is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
14-
15-
*/
2+
/**
3+
* Container for data collectors.
4+
*
5+
* @package query-monitor
6+
*/
167

178
if ( ! class_exists( 'QM_Collectors' ) ) {
189
class QM_Collectors implements IteratorAggregate {
@@ -52,10 +43,22 @@ public function process() {
5243
if ( $this->processed ) {
5344
return;
5445
}
46+
5547
foreach ( $this as $collector ) {
5648
$collector->tear_down();
49+
50+
$timer = new QM_Timer;
51+
$timer->start();
52+
5753
$collector->process();
54+
55+
$collector->set_timer( $timer->stop() );
5856
}
57+
58+
foreach ( $this as $collector ) {
59+
$collector->post_process();
60+
}
61+
5962
$this->processed = true;
6063
}
6164

www/wp-content/plugins/query-monitor/classes/Dispatcher.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
<?php
2-
/*
3-
Copyright 2009-2017 John Blackbourn
4-
5-
This program is free software; you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation; either version 2 of the License, or
8-
(at your option) any later version.
9-
10-
This program is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
14-
15-
*/
2+
/**
3+
* Abstract dispatcher.
4+
*
5+
* @package query-monitor
6+
*/
167

178
if ( ! class_exists( 'QM_Dispatcher' ) ) {
189
abstract class QM_Dispatcher {
@@ -49,21 +40,12 @@ final public function should_dispatch() {
4940
}
5041

5142
public function get_outputters( $outputter_id ) {
52-
53-
$out = array();
54-
5543
$collectors = QM_Collectors::init();
5644
$collectors->process();
5745

5846
$this->outputters = apply_filters( "qm/outputter/{$outputter_id}", array(), $collectors );
5947

60-
/* @var QM_Output[] */
61-
foreach ( $this->outputters as $id => $outputter ) {
62-
$out[ $id ] = $outputter;
63-
}
64-
65-
return $out;
66-
48+
return $this->outputters;
6749
}
6850

6951
public function init() {

www/wp-content/plugins/query-monitor/classes/Dispatchers.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
<?php
2-
/*
3-
Copyright 2009-2017 John Blackbourn
4-
5-
This program is free software; you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation; either version 2 of the License, or
8-
(at your option) any later version.
9-
10-
This program is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
14-
15-
*/
2+
/**
3+
* Container for dispatchers.
4+
*
5+
* @package query-monitor
6+
*/
167

178
class QM_Dispatchers implements IteratorAggregate {
189

0 commit comments

Comments
 (0)