Skip to content

Commit ecc9108

Browse files
authored
Merge pull request #21 from wojsmol/tov2
convert to v2
2 parents 4993755 + 076303c commit ecc9108

File tree

8 files changed

+242
-49
lines changed

8 files changed

+242
-49
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock

.travis.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
sudo: false
2+
dist: trusty
3+
4+
language: php
5+
php: 7.2
6+
7+
notifications:
8+
email:
9+
on_success: never
10+
on_failure: change
11+
12+
branches:
13+
only:
14+
- master
15+
16+
cache:
17+
directories:
18+
- $HOME/.composer/cache
19+
20+
env:
21+
global:
22+
- PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH"
23+
- WP_CLI_BIN_DIR="$TRAVIS_BUILD_DIR/vendor/bin"
24+
25+
before_install:
26+
- |
27+
# Remove Xdebug for a huge performance increase:
28+
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
29+
phpenv config-rm xdebug.ini
30+
else
31+
echo "xdebug.ini does not exist"
32+
fi
33+
- |
34+
# Raise PHP memory limit to 2048MB
35+
echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
36+
- composer validate
37+
38+
install:
39+
- composer install
40+
- composer prepare-tests
41+
42+
script:
43+
- composer phpunit
44+
- composer behat
45+
46+
jobs:
47+
include:
48+
- stage: sniff
49+
script:
50+
- composer lint
51+
- composer phpcs
52+
env: BUILD=sniff
53+
- stage: test
54+
php: 7.2
55+
env: WP_VERSION=latest
56+
- stage: test
57+
php: 7.1
58+
env: WP_VERSION=latest
59+
- stage: test
60+
php: 7.0
61+
env: WP_VERSION=latest
62+
- stage: test
63+
php: 5.6
64+
env: WP_VERSION=latest
65+
- stage: test
66+
php: 5.6
67+
env: WP_VERSION=3.7.11
68+
- stage: test
69+
php: 5.6
70+
env: WP_VERSION=trunk
71+
- stage: test
72+
php: 5.4
73+
env: WP_VERSION=latest

composer.json

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,49 @@
99
],
1010
"homepage": "https://github.com/wp-cli/wp-super-cache-cli",
1111
"license": "MIT",
12-
"authors": [{
13-
"name": "WP-CLI Team",
14-
"homepage": "http://github.com/wp-cli",
15-
"role": "Developer"
16-
}],
12+
"authors": [
13+
{
14+
"name": "WP-CLI Team",
15+
"homepage": "http://github.com/wp-cli",
16+
"role": "Developer"
17+
}
18+
],
1719
"require": {
18-
"php": ">=5.3.0"
20+
"php": ">=5.4",
21+
"wp-cli/wp-cli": "^2"
22+
},
23+
"require-dev": {
24+
"wp-cli/extension-command": "^2",
25+
"wp-cli/wp-cli-tests": "^2.0.7"
26+
},
27+
"config": {
28+
"platform": {
29+
"php": "5.4"
30+
},
31+
"process-timeout": 7200,
32+
"sort-packages": true
1933
},
2034
"autoload": {
21-
"files": [ "wp-super-cache-cli.php" ]
35+
"psr-4": {
36+
"": "src/"
37+
},
38+
"files": [
39+
"wp-super-cache-cli.php"
40+
]
41+
},
42+
"minimum-stability": "dev",
43+
"prefer-stable": true,
44+
"scripts": {
45+
"behat": "run-behat-tests",
46+
"lint": "run-linter-tests",
47+
"phpcs": "run-phpcs-tests",
48+
"phpunit": "run-php-unit-tests",
49+
"prepare-tests": "install-package-tests",
50+
"test": [
51+
"@lint",
52+
"@phpcs",
53+
"@phpunit",
54+
"@behat"
55+
]
2256
}
2357
}

features/manage-cache.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Feature: Generate cache
2+
3+
Scenario: Manage wp-super-cache via CLI
4+
Given a WP install
5+
6+
When I run `wp plugin install wp-super-cache`
7+
Then STDOUT should contain:
8+
"""
9+
Plugin installed successfully.
10+
"""
11+
And the wp-content/plugins/wp-super-cache directory should exist
12+
13+
When I try `wp super-cache enable`
14+
Then STDERR should contain:
15+
"""
16+
Error: WP Super Cache needs to be enabled to use its WP-CLI commands.
17+
"""
18+
19+
When I run `wp plugin activate wp-super-cache`
20+
And I run `wp super-cache enable`
21+
Then STDOUT should contain:
22+
"""
23+
Success: The WP Super Cache is enabled.
24+
"""

phpcs.xml.dist

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WP-CLI">
3+
<description>Custom ruleset for WP-CLI</description>
4+
5+
<!-- For help in understanding this file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
6+
<!-- For help in using PHPCS: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
7+
8+
<!-- What to scan -->
9+
<file>.</file>
10+
<!-- Ignoring Files and Folders:
11+
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders -->
12+
<exclude-pattern>*/.git/*</exclude-pattern>
13+
<exclude-pattern>*/ci/*</exclude-pattern>
14+
<exclude-pattern>*/features/*</exclude-pattern>
15+
<exclude-pattern>*/packages/*</exclude-pattern>
16+
<exclude-pattern>*/tests/*</exclude-pattern>
17+
<exclude-pattern>*/utils/*</exclude-pattern>
18+
<exclude-pattern>*/vendor/*</exclude-pattern>
19+
20+
<!-- How to scan -->
21+
<arg value="sp"/> <!-- Show sniff and progress -->
22+
<arg name="colors"/> <!-- Show results with colors -->
23+
<arg name="extensions" value="php"/> <!-- Limit to PHP files -->
24+
25+
<!-- Rules: Check PHP version compatibility - see
26+
https://github.com/PHPCompatibility/PHPCompatibilityWP -->
27+
<rule ref="PHPCompatibilityWP">
28+
<!-- Polyfill package is used so array_column() is available for PHP 5.4- -->
29+
<exclude name="PHPCompatibility.PHP.NewFunctions.array_columnFound"/>
30+
<!-- Both magic quotes directives set in wp-settings-cli.php to provide consistent starting point. -->
31+
<exclude name="PHPCompatibility.PHP.DeprecatedIniDirectives.magic_quotes_runtimeDeprecatedRemoved"/>
32+
<exclude name="PHPCompatibility.PHP.DeprecatedIniDirectives.magic_quotes_sybaseDeprecatedRemoved"/>
33+
</rule>
34+
35+
<!-- For help in understanding this testVersion:
36+
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
37+
<config name="testVersion" value="5.4-"/>
38+
39+
<!-- Ignore php_uname mode issue, we're conditionally providing a callback -->
40+
<rule ref="PHPCompatibility.PHP.NewFunctionParameters.php_uname_modeFound">
41+
<exclude-pattern>*/php/commands/src/CLI_Command.php</exclude-pattern>
42+
</rule>
43+
44+
<!-- Rules: WordPress Coding Standards - see
45+
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
46+
<rule ref="WordPress-Core">
47+
<exclude name="Squiz.PHP.DisallowMultipleAssignments.Found" />
48+
<exclude name="WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar" />
49+
<exclude name="WordPress.NamingConventions.ValidVariableName.MemberNotSnakeCase" />
50+
<exclude name="WordPress.NamingConventions.ValidVariableName.NotSnakeCase" />
51+
</rule>
52+
53+
<!-- For help in understanding these custom sniff properties:
54+
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
55+
<rule ref="WordPress.Files.FileName">
56+
<properties>
57+
<property name="strict_class_file_names" value="false"/>
58+
</properties>
59+
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
60+
</rule>
61+
</ruleset>

cli.php renamed to src/WP_Super_Cache_Command.php

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Manages the WP Super Cache plugin
55
*/
6-
class WPSuperCache_Command extends WP_CLI_Command {
6+
class WP_Super_Cache_Command extends WP_CLI_Command {
77

88
/**
99
* Clear something from the cache.
@@ -13,25 +13,24 @@ class WPSuperCache_Command extends WP_CLI_Command {
1313
function flush( $args = array(), $assoc_args = array() ) {
1414
require_once( WPCACHEHOME . '/wp-cache-phase1.php' );
1515
global $WPSC_HTTP_HOST;
16-
$home_url = parse_url( home_url() );
16+
$home_url = parse_url( home_url() );
1717
$WPSC_HTTP_HOST = $home_url['host'];
1818

19-
if ( isset($assoc_args['post_id']) ) {
19+
if ( isset( $assoc_args['post_id'] ) ) {
2020
if ( is_numeric( $assoc_args['post_id'] ) ) {
2121
wp_cache_post_change( $assoc_args['post_id'] );
2222
} else {
23-
WP_CLI::error('This is not a valid post id.');
23+
WP_CLI::error( 'This is not a valid post id.' );
2424
}
2525

2626
wp_cache_post_change( $assoc_args['post_id'] );
27-
}
28-
elseif ( isset( $assoc_args['permalink'] ) ) {
27+
} elseif ( isset( $assoc_args['permalink'] ) ) {
2928
$id = url_to_postid( $assoc_args['permalink'] );
3029

3130
if ( is_numeric( $id ) ) {
3231
wp_cache_post_change( $id );
3332
} else {
34-
WP_CLI::error('There is no post with this permalink.');
33+
WP_CLI::error( 'There is no post with this permalink.' );
3534
}
3635
} else {
3736
wp_cache_clean_cache( $file_prefix, true );
@@ -47,23 +46,23 @@ function status( $args = array(), $assoc_args = array() ) {
4746

4847
$cache_stats = get_option( 'supercache_stats' );
4948

50-
if ( !empty( $cache_stats ) ) {
49+
if ( ! empty( $cache_stats ) ) {
5150
if ( $cache_stats['generated'] > time() - 3600 * 24 ) {
52-
WP_CLI::line( 'Cache status: ' . ($super_cache_enabled ? '%gOn%n' : '%rOff%n') );
53-
WP_CLI::line( 'Cache content on ' . date('r', $cache_stats['generated'] ) . ': ' );
51+
WP_CLI::line( 'Cache status: ' . ( $super_cache_enabled ? '%gOn%n' : '%rOff%n' ) );
52+
WP_CLI::line( 'Cache content on ' . date( 'r', $cache_stats['generated'] ) . ': ' );
5453
WP_CLI::line();
5554
WP_CLI::line( ' WordPress cache:' );
56-
WP_CLI::line( ' Cached: ' . $cache_stats[ 'wpcache' ][ 'cached' ] );
57-
WP_CLI::line( ' Expired: ' . $cache_stats[ 'wpcache' ][ 'expired' ] );
55+
WP_CLI::line( ' Cached: ' . $cache_stats['wpcache']['cached'] );
56+
WP_CLI::line( ' Expired: ' . $cache_stats['wpcache']['expired'] );
5857
WP_CLI::line();
5958
WP_CLI::line( ' WP Super Cache:' );
60-
WP_CLI::line( ' Cached: ' . $cache_stats[ 'supercache' ][ 'cached' ] );
61-
WP_CLI::line( ' Expired: ' . $cache_stats[ 'supercache' ][ 'expired' ] );
59+
WP_CLI::line( ' Cached: ' . $cache_stats['supercache']['cached'] );
60+
WP_CLI::line( ' Expired: ' . $cache_stats['supercache']['expired'] );
6261
} else {
63-
WP_CLI::error('The WP Super Cache stats are too old to work with (older than 24 hours).');
62+
WP_CLI::error( 'The WP Super Cache stats are too old to work with (older than 24 hours).' );
6463
}
6564
} else {
66-
WP_CLI::error('No WP Super Cache stats found.');
65+
WP_CLI::error( 'No WP Super Cache stats found.' );
6766
}
6867
}
6968

@@ -75,10 +74,10 @@ function enable( $args = array(), $assoc_args = array() ) {
7574

7675
wp_super_cache_enable();
7776

78-
if($super_cache_enabled) {
77+
if ( $super_cache_enabled ) {
7978
WP_CLI::success( 'The WP Super Cache is enabled.' );
8079
} else {
81-
WP_CLI::error('The WP Super Cache is not enabled, check its settings page for more info.');
80+
WP_CLI::error( 'The WP Super Cache is not enabled, check its settings page for more info.' );
8281
}
8382
}
8483

@@ -90,10 +89,10 @@ function disable( $args = array(), $assoc_args = array() ) {
9089

9190
wp_super_cache_disable();
9291

93-
if(!$super_cache_enabled) {
92+
if ( ! $super_cache_enabled ) {
9493
WP_CLI::success( 'The WP Super Cache is disabled.' );
9594
} else {
96-
WP_CLI::error('The WP Super Cache is still enabled, check its settings page for more info.');
95+
WP_CLI::error( 'The WP Super Cache is still enabled, check its settings page for more info.' );
9796
}
9897
}
9998

@@ -110,7 +109,7 @@ function preload( $args = array(), $assoc_args = array() ) {
110109
$pending_cancel = get_option( 'preload_cache_stop' );
111110

112111
// Bail early if caching or preloading is disabled
113-
if( ! $super_cache_enabled ) {
112+
if ( ! $super_cache_enabled ) {
114113
WP_CLI::error( 'The WP Super Cache is not enabled.' );
115114
}
116115

@@ -158,7 +157,7 @@ function preload( $args = array(), $assoc_args = array() ) {
158157
*/
159158
protected function preload_status( $preload_counter, $pending_cancel ) {
160159
if ( is_array( $preload_counter ) && $preload_counter['c'] > 0 ) {
161-
WP_CLI::line( sprintf( 'Currently caching from post %d to %d.', $preload_counter[ 'c' ] - 100, $preload_counter[ 'c' ] ) );
160+
WP_CLI::line( sprintf( 'Currently caching from post %d to %d.', $preload_counter['c'] - 100, $preload_counter['c'] ) );
162161

163162
if ( $pending_cancel ) {
164163
WP_CLI::warning( 'Pending preload cancel. It may take up to a minute for it to cancel completely.' );
@@ -168,11 +167,3 @@ protected function preload_status( $preload_counter, $pending_cancel ) {
168167
}
169168
}
170169
}
171-
172-
WP_CLI::add_command( 'super-cache', 'WPSuperCache_Command', array(
173-
'before_invoke' => function(){
174-
if ( ! function_exists( 'wp_super_cache_enable' ) ) {
175-
WP_CLI::error( 'WP Super Cache needs to be enabled to use its WP-CLI commands.' );
176-
}
177-
}
178-
) );

wp-cli.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require:
2+
- wp-super-cache-cli.php

wp-super-cache-cli.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
<?php
2-
/*
3-
Plugin Name: WP Super Cache CLI
4-
Version: 1.0
5-
Description: A CLI interface for the WP Super Cache plugin
6-
Author: WP-CLI Team
7-
Author URI: http://github.com/wp-cli
8-
Plugin URI: http://github.com/wp-cli/wp-super-cache-cli
9-
License: MIT
10-
*/
11-
12-
if ( defined( 'WP_CLI' ) && WP_CLI ) {
13-
require_once dirname( __FILE__ ) . '/cli.php';
2+
3+
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
4+
5+
if ( file_exists( $autoload ) ) {
6+
require_once $autoload;
7+
}
8+
9+
if ( ! class_exists( 'WP_CLI' ) ) {
10+
return;
1411
}
1512

13+
WP_CLI::add_command(
14+
'super-cache', 'WP_Super_Cache_Command', array(
15+
'before_invoke' => function() {
16+
if ( ! function_exists( 'wp_super_cache_enable' ) ) {
17+
WP_CLI::error( 'WP Super Cache needs to be enabled to use its WP-CLI commands.' );
18+
}
19+
},
20+
)
21+
);

0 commit comments

Comments
 (0)