Skip to content

Commit

Permalink
Merge pull request #142 from pantheon-systems/bugs-5880
Browse files Browse the repository at this point in the history
[BUGS-5880] Adjust for multisite checks
  • Loading branch information
jazzsequence authored May 16, 2023
2 parents 9bd8881 + d85639d commit e10a8a8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ jobs:
validate:
name: "Run validation test suite"
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ["7.2", "7.3", "7.4"]

env:
# GITHUB_CONTEXT: ${{ toJson(github) }}
PANTHEON_WPVULNDB_API_TOKEN: ${{ secrets.PANTHEON_WPVULNDB_API_TOKEN }}
Expand Down Expand Up @@ -44,7 +42,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: 7.4
ini-values: post_max_size=256M, max_execution_time=120

- name: Get Composer Cache Directory
Expand Down
6 changes: 3 additions & 3 deletions features/general.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Feature: General tests of WP Launch Check
# This check is here to remind us to update versions when new releases are available.
Then STDOUT should contain:
"""
6.1.1
6.2
"""

When I run `wp launchcheck general`
Expand All @@ -60,7 +60,7 @@ Feature: General tests of WP Launch Check

Scenario: WordPress has a new minor version but no new major version
Given a WP install
And I run `wp core download --version=6.2 --force`
And I run `wp core download --version=6.1 --force`
And I run `wp theme activate twentytwentytwo`

When I run `wp launchcheck general`
Expand All @@ -72,7 +72,7 @@ Feature: General tests of WP Launch Check
Scenario: WordPress has a new major version but no new minor version
Given a WP install
And I run `wp core download --version=5.6.10 --force`
And I run `wp theme activate twentytwentytwo`
And I run `wp theme activate twentytwenty`

When I run `wp launchcheck general`
Then STDOUT should contain:
Expand Down
1 change: 1 addition & 0 deletions features/objectcache.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Feature: Suggest object cache to be enabled

Scenario: WP Redis is present as the enabled object-cache
Given a WP install
# TODO Remove the version flag.
And I run `wp plugin install wp-redis --activate`
And I run `wp redis enable`

Expand Down
19 changes: 19 additions & 0 deletions php/commands/launchcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function all($args, $assoc_args) {

// wp-config is going to be loaded again, and we need to avoid notices
@WP_CLI::get_runner()->load_wordpress();
WP_CLI::add_hook( 'before_run_command', [ $this, 'maybe_switch_to_blog' ] );

// WordPress is now loaded, so other checks can run
$searcher = new \Pantheon\Filesearcher( WP_CONTENT_DIR );
Expand All @@ -47,6 +48,24 @@ public function all($args, $assoc_args) {
\Pantheon\Messenger::emit($format);
}

/**
* Switch to BLOG_ID_CURRENT_SITE if we're on a multisite.
*
* This forces the launchcheck command to use the main site's info for all
* the checks.
*/
public function maybe_switch_to_blog() {
// Check for multisite. If we're on multisite, switch to the main site.
if ( is_multisite() ) {
if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
switch_to_blog( BLOG_ID_CURRENT_SITE );
} else {
switch_to_blog( 1 );
}
\WP_CLI::log( sprintf( esc_html__( 'Multisite detected. Running checks on %s site.' ), get_bloginfo( 'name' ) ) );
}
}

/**
* Checks for a properly-configured wp-config
*
Expand Down
4 changes: 4 additions & 0 deletions php/pantheon/checks/insecure.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function run($file) {
if ( $matches ) {
$note = '';
foreach($matches as $match) {
// Don't flag if the file in question is inside wp-redis.
if ( false !== strpos( $file->getPath(), 'wp-redis' ) ) {
continue;
}
$linenum = substr_count(substr($file_contents, 0, $match[1]), "\n") + 1;
$this->alerts[] = array( 'class'=>'warning', 'data'=> array( $file->getRelativePathname(), $linenum, substr($match[0],0,50)));
}
Expand Down

0 comments on commit e10a8a8

Please sign in to comment.