Skip to content

Commit a235b7f

Browse files
committed
Merge branch 'master' of github.com:wpengine/phpcompat into PHP-160
2 parents 7be55c4 + 7d05014 commit a235b7f

File tree

7 files changed

+101
-34
lines changed

7 files changed

+101
-34
lines changed

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.5
6+
- 5.6
7+
- 7.0
8+
9+
env:
10+
- WP_VERSION=latest WP_MULTISITE=0
11+
- WP_VERSION=4.5 WP_MULTISITE=0
12+
13+
matrix:
14+
include:
15+
- php: 5.6
16+
env: WP_VERSION=latest WP_MULTISITE=1
17+
18+
before_script:
19+
- composer install
20+
- bash tests/bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
21+
22+
script: phpunit

Gruntfile.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module.exports = function(grunt) {
33
grunt.initConfig({
44
wp_readme_to_markdown: {
55
options: {
6-
screenshot_url: 'assets/{screenshot}.png'
6+
screenshot_url: 'assets/{screenshot}.png',
7+
post_convert: addBuildStatus,
78
},
89
your_target: {
910
files: {
@@ -19,3 +20,10 @@ module.exports = function(grunt) {
1920
'wp_readme_to_markdown'
2021
]);
2122
};
23+
24+
// Add build status image to GitHub readme.
25+
function addBuildStatus(readme) {
26+
var buildImage = '<a href="https://travis-ci.org/wpengine/phpcompat"><img src="https://travis-ci.org/wpengine/phpcompat.svg?branch=master"></a>';
27+
28+
return readme.replace(/# PHP Compatibility Checker #/, '# PHP Compatibility Checker ' + buildImage);
29+
}

readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PHP Compatibility Checker #
1+
# PHP Compatibility Checker <a href="https://travis-ci.org/wpengine/phpcompat"><img src="https://travis-ci.org/wpengine/phpcompat.svg?branch=master"></a>
22
**Contributors:** [wpengine](https://profiles.wordpress.org/wpengine), [octalmage](https://profiles.wordpress.org/octalmage), [stevenkword](https://profiles.wordpress.org/stevenkword), [taylor4484](https://profiles.wordpress.org/taylor4484)
33
**Tags:** php 7, php 5.5, php, version, compatibility, checker, wp engine, wpe, wpengine
44
**Requires at least:** 3.0.1
@@ -85,7 +85,11 @@ Example: `wp phpcompat 5.5 --scan=active`
8585

8686
5. Why was my plugin/theme skipped?
8787

88-
Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issues is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site.
88+
Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issue is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site, or you can use the WP-CLI command.
89+
90+
You can use the filter `wpephpcompat_scan_timeout` to customize the scan timeout. See [this](https://gist.github.com/octalmage/07f26e0d1f25cea9a8ca92ebc67a3a14) for an example.
91+
92+
Setting the timeout to 0 disables the cron/timeout.
8993

9094
6. I found a bug, or have a suggestion, can I contribute back?
9195

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ Example: `wp phpcompat 5.5 --scan=active`
8585

8686
5. Why was my plugin/theme skipped?
8787

88-
Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issues is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site.
88+
Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issue is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site, or you can use the WP-CLI command.
89+
90+
You can use the filter `wpephpcompat_scan_timeout` to customize the scan timeout. See [this](https://gist.github.com/octalmage/07f26e0d1f25cea9a8ca92ebc67a3a14) for an example.
91+
92+
Setting the timeout to 0 disables the cron/timeout.
8993

9094
6. I found a bug, or have a suggestion, can I contribute back?
9195

src/js/run.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function checkStatus() {
9090
jQuery( '#runButton' ).val( 'Re-run' );
9191
}
9292

93-
if ( '1' == obj.status ) {
93+
if ( '1' === obj.status ) {
9494
jQuery( '#runButton' ).addClass( 'button-primary-disabled' );
9595
jQuery( '.spinner' ).show();
9696
} else {
@@ -163,21 +163,29 @@ function displayReport( response ) {
163163
resetDisplay();
164164
var $ = jQuery;
165165
var compatible = 1;
166+
167+
// Keep track of the number of failed plugins/themes.
168+
var failedCount = 0;
166169
var errorsRegex = /(\d*) ERRORS?/g;
167170
var warningRegex = /(\d*) WARNINGS?/g;
168171
var updateVersionRegex = /e: (.*?);/g;
169172
var currentVersionRegex = /n: (.*?);/g;
170173

174+
// Grab and compile our template.
175+
var source = $( '#result-template' ).html();
176+
var template = Handlebars.compile( source );
177+
171178
$( '#testResults' ).text( response );
172179
$( '#footer' ).show();
173180

174181
// Separate plugins/themes.
175182
var plugins = response.replace( /^\s+|\s+$/g, '' ).split( 'Name: ' );
183+
184+
// Remove the first item, it's empty.
185+
plugins.shift();
186+
176187
// Loop through them.
177188
for ( var x in plugins ) {
178-
if ( '' === plugins[x].trim() ) {
179-
continue;
180-
}
181189
var updateVersion;
182190
var updateAvailable = 0;
183191
var passed = 1;
@@ -197,6 +205,7 @@ function displayReport( response ) {
197205
if ( parseInt( errors ) > 0 ) {
198206
compatible = 0;
199207
passed = 0;
208+
failedCount++;
200209
}
201210
// Trim whitespace and newlines from report.
202211
log = log.replace( /^\s+|\s+$/g, '' );
@@ -205,8 +214,6 @@ function displayReport( response ) {
205214
skipped = 1;
206215
}
207216
// Use handlebars to build our template.
208-
var source = $( '#result-template' ).html();
209-
var template = Handlebars.compile( source );
210217
var context = {
211218
plugin_name: name,
212219
warnings: warnings,
@@ -220,11 +227,14 @@ function displayReport( response ) {
220227
var html = template( context );
221228
$('#standardMode').append( html );
222229
}
230+
223231
// Display global compatibility status.
224232
if ( compatible ) {
225233
$( '#standardMode' ).prepend( '<h3>Your WordPress install is PHP ' + test_version + ' compatible.</h3>' );
226234
} else {
235+
// Display scan stats.
236+
$( '#standardMode' ).prepend( '<p>' + failedCount + ' out of ' + plugins.length + ' plugins/themes are not compatible.</p>' );
237+
227238
$( '#standardMode' ).prepend( '<h3>Your WordPress install is not PHP ' + test_version + ' compatible.</h3>' );
228239
}
229240
}
230-

src/wpephpcompat.php

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,45 @@ function __construct( $dir ) {
8888
public function start_test() {
8989

9090
$this->debug_log( 'startScan: ' . isset( $_POST['startScan'] ) );
91-
// Try to lock.
92-
$lock_result = add_option( 'wpephpcompat.lock', time(), '', 'no' );
9391

94-
$this->debug_log( 'lock: ' . $lock_result );
95-
96-
if ( ! $lock_result ) {
97-
$lock_result = get_option( 'wpephpcompat.lock' );
98-
99-
// Bail if we were unable to create a lock, or if the existing lock is still valid.
100-
if ( ! $lock_result || ( $lock_result > ( time() - MINUTE_IN_SECONDS ) ) ) {
101-
$this->debug_log( 'Process already running (locked), returning.' );
102-
103-
$timestamp = wp_next_scheduled( 'wpephpcompat_start_test_cron' );
104-
105-
if ( $timestamp == false ) {
106-
wp_schedule_single_event( time() + ( MINUTE_IN_SECONDS ), 'wpephpcompat_start_test_cron' );
92+
/**
93+
* Filters the scan timeout.
94+
*
95+
* Lets you change the timeout of the scan. The value is how long the scan
96+
* runs before dying and picking back up on a cron. You can set $timeout to
97+
* 0 to disable the timeout and the cron.
98+
*
99+
* @since 1.0.4
100+
*
101+
* @param int $timeout The timeout in seconds.
102+
*/
103+
$timeout = apply_filters( 'wpephpcompat_scan_timeout', MINUTE_IN_SECONDS );
104+
$this->debug_log( 'timeout: ' . $timeout );
105+
106+
// No reason to lock if there's no timeout.
107+
if ( 0 !== $timeout ) {
108+
// Try to lock.
109+
$lock_result = add_option( 'wpephpcompat.lock', time(), '', 'no' );
110+
111+
$this->debug_log( 'lock: ' . $lock_result );
112+
113+
if ( ! $lock_result ) {
114+
$lock_result = get_option( 'wpephpcompat.lock' );
115+
116+
// Bail if we were unable to create a lock, or if the existing lock is still valid.
117+
if ( ! $lock_result || ( $lock_result > ( time() - $timeout ) ) ) {
118+
$this->debug_log( 'Process already running (locked), returning.' );
119+
120+
$timestamp = wp_next_scheduled( 'wpephpcompat_start_test_cron' );
121+
122+
if ( $timestamp == false ) {
123+
wp_schedule_single_event( time() + $timeout, 'wpephpcompat_start_test_cron' );
124+
}
125+
return;
107126
}
108-
return;
109127
}
128+
update_option( 'wpephpcompat.lock', time(), false );
110129
}
111-
update_option( 'wpephpcompat.lock', time(), false );
112130

113131
// Check to see if scan has already started.
114132
$scan_status = get_option( 'wpephpcompat.status' );
@@ -148,15 +166,16 @@ public function start_test() {
148166

149167
return;
150168
}
151-
152-
wp_schedule_single_event( time() + ( MINUTE_IN_SECONDS ), 'wpephpcompat_start_test_cron' );
169+
if ( 0 !== $timeout ) {
170+
wp_schedule_single_event( time() + $timeout, 'wpephpcompat_start_test_cron' );
171+
}
153172

154173
if ( ! $this->is_command_line() ) {
155174
// Close the connection to the browser.
156175
$this->close_connection("started");
157176

158-
// Kill cron after a minute.
159-
set_time_limit( 55 );
177+
// Kill cron after a configurable timeout.
178+
set_time_limit( ( $timeout > 5 ? $timeout - 5 : $timeout ) );
160179
}
161180

162181
$scan_results = get_option( 'wpephpcompat.scan_results' );
@@ -377,8 +396,6 @@ public function clean_after_scan() {
377396
// Delete options created during the scan.
378397
delete_option( 'wpephpcompat.lock' );
379398
delete_option( 'wpephpcompat.status' );
380-
//delete_option( 'wpephpcompat.scan_results' );
381-
//delete_option( 'wpephpcompat.test_version' );
382399
delete_option( 'wpephpcompat.only_active' );
383400
delete_option( 'wpephpcompat.numdirs' );
384401

tests/qunit/test-run.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ QUnit.test( 'Render test pass', function( assert ) {
6363
assert.ok( $('.wpe-results-card').length == 2, 'There are 2 results.' );
6464
assert.ok( $('#standardMode').text().includes( 'Your WordPress install is PHP 5.5 compatible.' ), 'Test did pass.' );
6565
assert.ok( '#038103' === helpers.rgb2hex( $( ".wpe-results-card" ).eq( 0 ).css( 'border-left-color' ) ), 'First plugin marked as passed.' );
66+
assert.ok( ! $( '#standardMode' ).text().includes( '0 out of 2' ), 'No scan stats are shown.' );
6667
});
6768

6869
QUnit.test( 'Render test fail', function( assert ) {
@@ -83,6 +84,7 @@ QUnit.test( 'Render test fail', function( assert ) {
8384
assert.ok( $('#footer').is(':visible'), 'Footer is visible' );
8485
assert.ok( $('.wpe-results-card').length == 7, 'There are 7 results.' );
8586
assert.ok( $('#standardMode').text().includes( 'Your WordPress install is not PHP 5.5 compatible.' ), 'Test did not pass.' );
87+
assert.ok( $( '#standardMode' ).text().includes( '1 out of 7' ), 'Scan stats are correct' );
8688
});
8789

8890
QUnit.test( 'Render test skip', function( assert ) {

0 commit comments

Comments
 (0)