Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMS-845] Don't recommend Native PHP Sessions if it's already installed #133

Merged
merged 19 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion features/general.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ Feature: General tests of WP Launch Check
Scenario: WordPress is up to date
Given a WP install

When I run `wp core version`
# This check is here to remind us to update versions when new releases are available.
Then STDOUT should contain:
"""
6.0
"""

When I run `wp launchcheck general`
Then STDOUT should contain:
"""
Expand All @@ -64,7 +71,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.8.4 --force`
And I run `wp core download --version=5.8.5 --force`
And I run `wp theme activate twentytwentytwo`

When I run `wp launchcheck general`
Expand Down
31 changes: 31 additions & 0 deletions features/sessions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Test for the existence of the PHP Native Sessions plugin

Scenario: A WordPress install without the native sessions plugin
Given a WP install

When I run `wp launchcheck sessions`
Then STDOUT should contain:
"""
Recommendation: You should install the Native PHP Sessions plugin - https://wordpress.org/plugins/wp-native-php-sessions/
"""

Scenario: A WordPress install with the native sessions plugin installed but not active
Given a WP install
And I run `wp plugin install wp-native-php-sessions`

When I run `wp launchcheck sessions`
Then STDOUT should contain:
"""
Recommendation: You should install the Native PHP Sessions plugin - https://wordpress.org/plugins/wp-native-php-sessions/
"""

Scenario: A WordPress install with the native sessions plugin installed and active
Given a WP install
And I run `wp plugin install wp-native-php-sessions`
And I run `wp plugin activate wp-native-php-sessions`

When I run `wp launchcheck sessions`
Then STDOUT should contain:
"""
Recommendation: No action required
"""
28 changes: 16 additions & 12 deletions php/pantheon/checks/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function checkCaching() {
'class' => 'warning',
'message' => 'W3 Total Cache plugin found. This plugin is not needed on Pantheon and should be removed.',
);
} else {
} else {
$this->alerts[] = array(
'code' => 0,
'class' => 'ok',
Expand All @@ -50,7 +50,7 @@ public function checkCaching() {
'class' => 'warning',
'message' => 'WP Super Cache plugin found. This plugin is not needed on Pantheon and should be removed.',
);
} else {
} else {
$this->alerts[] = array(
'code' => 0,
'class' => 'ok',
Expand All @@ -64,13 +64,13 @@ public function checkURLS() {
$siteurl = \get_option('siteurl');
$home = \get_option('home');
if ( $siteurl !== $home ) {
$this->alerts[] = array(
$this->alerts[] = array(
'code' => 2,
'class' => 'error',
'message' => "Site url and home settings do not match. ( 'siteurl'=$siteurl and 'home'=>$home )",
);
} else {
$this->alerts[] = array(
$this->alerts[] = array(
'code' => 0,
'class' => 'ok',
'message' => "Site and home url settings match. ( $siteurl )",
Expand All @@ -82,19 +82,19 @@ public function checkPluginCount() {
$active = get_option('active_plugins');
$plugins = count($active);
if ( 100 <= $plugins ) {
$this->alerts[] = array(
$this->alerts[] = array(
'code' => 1,
'class' => 'warning',
'message' => sprintf('%d active plugins found. You are running more than 100 plugins. The more plugins you run the worse your performance will be. You should uninstall any plugin that is not necessary.', $plugins),
);
} else {
} else {
$this->alerts[] = array(
'code' => 0,
'class' => 'ok',
'message' => sprintf('%d active plugins found.',$plugins),
);
}
}
}

public function checkDebug() {

Expand All @@ -113,7 +113,7 @@ public function checkDebug() {
);
}
} else {
$this->alerts[] = array(
$this->alerts[] = array(
'code' => 0,
'class' => 'ok',
'message' => 'WP_DEBUG not found or is set to false.',
Expand All @@ -132,7 +132,7 @@ public function checkDebug() {
'message' => 'Looks like you are running the debug bar plugin. You should disable this plugin in the live environment'
);
}
}
}

}

Expand Down Expand Up @@ -178,7 +178,7 @@ public function message(Messenger $messenger) {
$avg = $total/count($this->alerts);
$this->result = View::make('checklist', array('rows'=> $rows) );
$this->score = $avg;
$this->action = "You should use object caching";
$this->action = $this->action ?? "You should use object caching";
}
$messenger->addMessage(get_object_vars($this));
}
Expand All @@ -198,17 +198,21 @@ public function checkCoreUpdates() {
}

if ( $has_minor ) {
$action = "Updating to WordPress' newest minor version is strongly recommended.";
$this->alerts[] = array(
'code' => 2,
'class' => 'error',
'message' => "Updating to WordPress' newest minor version is strongly recommended.",
'message' => $action,
);
$this->action = $action;
} else if ( $has_major ) {
$action = 'A new major version of WordPress is available for update.';
$this->alerts[] = array(
'code' => 1,
'class' => 'warning',
'message' => 'A new major version of WordPress is available for update.'
'message' => $action,
);
$this->action = $action;
} else {
$this->alerts[] = array(
'code' => 0,
Expand Down
9 changes: 6 additions & 3 deletions php/pantheon/checks/sessions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ class Sessions extends Checkimplementation {
public $name = 'sessions';

public function init() {
$this->action = 'You should install the Native PHP Sessions plugin - https://wordpress.org/plugins/wp-native-php-sessions/';
$this->description = 'Sessions only work with sessions plugin is enabled';
$this->description = 'Sessions only work when sessions plugin is enabled';
$this->score = 0;
$this->result = '';
$this->label = 'PHP Sessions';
$this->has_plugin = class_exists("Pantheon_Sessions");
// If the plugin was not found, define the recommended action.
// Otherwise, we don't want to recommend anything, we're all good here.
$this->action = ! $this->has_plugin ? 'You should install the Native PHP Sessions plugin - https://wordpress.org/plugins/wp-native-php-sessions/' : 'No action required';

return $this;
}

Expand All @@ -32,7 +35,7 @@ public function run($file) {
foreach ($matches as $match) {
$this->alerts[] = array( 'class' => 'error','data'=>array($file->getRelativePathname(),$match[1] + 1, substr($match[0],0,50)));
}
}
}
return $this;
}

Expand Down
7 changes: 5 additions & 2 deletions php/pantheon/messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ public static function emit($format='raw') {
$color = "%R";
}

$recommendation = isset( $message['action'] ) ? sprintf( "Recommendation: %s", $message['action'] ) : '';

// @todo might be a better way to do this
echo \cli\Colors::colorize( sprintf(str_repeat('-',80).PHP_EOL."%s: (%s) \n%s\nResult:%s %s\nRecommendation: %s\n\n".PHP_EOL,
echo \cli\Colors::colorize( sprintf(str_repeat('-',80).PHP_EOL."%s: (%s) \n%s\nResult:%s %s\n%s\n\n".PHP_EOL,
strtoupper($message['label']),
$message['description'],
str_repeat('-',80),
$color,
$message['result'].'%n', // ugly
$message['action'])
// Check for a recommended action before printing something.
$recommendation )
);
}
break;
Expand Down