Skip to content
Snippets Groups Projects
Commit c7af1af2 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Merge branch 'feature/transients' into 'master'

Feature/transients

See merge request !42
parents 97c47f4e 21891549
No related branches found
Tags 3.6.0
1 merge request!42Feature/transients
Pipeline #213685 passed with warnings with stages
in 47 seconds
variables: variables:
WPDESK_CI_VERSION: 1.10.19-library DISABLE_ACCEPTANCE: "1"
MYSQL_ROOT_PASSWORD: mysql DISABLE_FUNCTIONAL: "1"
MYSQL_DATABASE: wptest IS_LIBRARY: 1
MYSQL_USER: mysql DISABLE_PHP_5_5: 1
MYSQL_PASSWORD: mysql DISABLE_CODECEPTION: 1
MYSQL_INNODB_LOG_BUFFER_SIZE: 32M
PHP_ERROR_REPORTING: E_ALL
COMPOSER_ALLOW_SUPERUSER: 1
GIT_STRATEGY: fetch
ACCEPTANCE_ERROR_PATH: ${CI_PROJECT_DIR}/acceptance
stages: include: 'https://gitlab.com/wpdesk/gitlab-ci/raw/master/gitlab-ci-1.2.yml'
- tools
- tests
.template: &job-test-template
stage: tests
coverage: '/^\s*Lines:\s*\d+.\d+\%/'
.template: &job-test-integration-template
<<: *job-test-template
services:
- mysql:5.6
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- php --version
- cat /tmp/wordpress-develop/src/wp-includes/version.php
- cat /tmp/woocommerce/woocommerce.php
- composer update --no-progress
- if [[ -f tests/integration/prepare.sh ]]; then sh tests/integration/prepare.sh; fi
- vendor/bin/phpunit --configuration phpunit-integration.xml --coverage-text --colors=never
only:
- tags
.template: &job-test-integration-template-fast
<<: *job-test-integration-template
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- php --version
- cat /tmp/wordpress-develop/src/wp-includes/version.php
- cat /tmp/woocommerce/woocommerce.php
- composer update --no-progress
- if [[ -f tests/integration/prepare.sh ]]; then sh tests/integration/prepare.sh; fi
- vendor/bin/phpunit --configuration phpunit-integration.xml --no-coverage
except:
- tags
only:
.template: &job-test-unit-template
<<: *job-test-template
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- php --version
- cat /tmp/wordpress-develop/src/wp-includes/version.php
- cat /tmp/woocommerce/woocommerce.php
- composer update --no-progress
- vendor/bin/phpunit --configuration phpunit-unit.xml --coverage-text --colors=never
only:
- tags
.template: &job-test-unit-template-fast
<<: *job-test-unit-template
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- php --version
- cat /tmp/wordpress-develop/src/wp-includes/version.php
- cat /tmp/woocommerce/woocommerce.php
- composer update --no-progress
- vendor/bin/phpunit --configuration phpunit-unit.xml --no-coverage
except:
- tags
only:
before_script:
- cd ${CI_PROJECT_DIR}
phpmetric metrics:
stage: tools
image: wpdesknet/phpunit-woocommerce:0-0
allow_failure: true
when: manual
artifacts:
when: always
expire_in: 1 month
name: "metrics"
paths:
- ${CI_PROJECT_DIR}/phpmetric
script:
- echo ${WPDESK_CI_VERSION}
- composer require phpmetrics/phpmetrics
- composer update --no-progress
- php ./vendor/bin/phpmetrics --report-html=phpmetric .
churn metrics:
stage: tools
image: wpdesknet/phpunit-woocommerce:0-0
allow_failure: true
when: manual
script:
- echo ${WPDESK_CI_VERSION}
- composer require bmitch/churn-php
- composer update --no-progress
- vendor/bin/churn run src
unit test lastest:
<<: *job-test-unit-template-fast
image: wpdesknet/phpunit-woocommerce:0-0
integration test lastest:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:0-0
unit test lastest coverage:
<<: *job-test-unit-template
image: wpdesknet/phpunit-woocommerce:0-0
integration test lastest coverage:
<<: *job-test-integration-template
image: wpdesknet/phpunit-woocommerce:0-0
integration test php7-1 wc-1:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:1-1
integration test php7 wc-2:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:2-2
integration test php-7 wc-3:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:2-3
integration test php5-6:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:3-0
integration test php5-5:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:4-0
integration test current woocommerce:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:0-0
allow_failure: true
before_script:
- cd /tmp
- rm -rf woocommerce
- git clone https://github.com/woocommerce/woocommerce.git
- cd ${CI_PROJECT_DIR}
## [3.5.2] - 2023-02-10 ## [3.6.0] - 2023-06-22
### Changed ### Changed
- Plugin info transient changed to auto loaded option (expiration 0)
## [3.5.2] - 2023-02-10
### Changed
- Removed arrows from user-facing messages. - Removed arrows from user-facing messages.
## [3.5.1] - 2022-08-30 ## [3.5.1] - 2022-08-30
......
...@@ -10,43 +10,70 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -10,43 +10,70 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
* have to be compatible with PHP 5.3.x * have to be compatible with PHP 5.3.x
*/ */
class WPDesk_Basic_Requirement_Checker implements WPDesk_Requirement_Checker { class WPDesk_Basic_Requirement_Checker implements WPDesk_Requirement_Checker {
const EXTENSION_NAME_OPENSSL = 'openssl'; const EXTENSION_NAME_OPENSSL = 'openssl';
const HOOK_ADMIN_NOTICES_ACTION = 'admin_notices'; const HOOK_ADMIN_NOTICES_ACTION = 'admin_notices';
const HOOK_PLUGIN_DEACTIVATED_ACTION = 'deactivated_plugin'; const HOOK_PLUGIN_DEACTIVATED_ACTION = 'deactivated_plugin';
const HOOK_PLUGIN_ACTIVATED_ACTION = 'activated_plugin'; const HOOK_PLUGIN_ACTIVATED_ACTION = 'activated_plugin';
const PLUGIN_INFO_KEY_NICE_NAME = 'nice_name'; const PLUGIN_INFO_KEY_NICE_NAME = 'nice_name';
const PLUGIN_INFO_KEY_NAME = 'name'; const PLUGIN_INFO_KEY_NAME = 'name';
const PLUGIN_INFO_VERSION = 'version'; const PLUGIN_INFO_VERSION = 'version';
const PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION = '0.0'; const PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION = '0.0';
const PLUGIN_INFO_APPEND_PLUGIN_DATA = 'required_version'; const PLUGIN_INFO_APPEND_PLUGIN_DATA = 'required_version';
const PLUGIN_INFO_TRANSIENT_NAME = 'require_plugins_data';
const PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME = 16; const PLUGIN_INFO_TRANSIENT_NAME = 'wpdesk_plugins_data';
const EXPIRATION_TRANSIENT_NAME = 'wpdesk_plugins_data_exp';
const CACHE_TIME = 300;
/** @var string */ /** @var string */
protected $plugin_name; protected $plugin_name;
/** @var string */ /** @var string */
private $plugin_file; private $plugin_file;
/** @var string */ /** @var string */
private $min_php_version; private $min_php_version;
/** @var string */ /** @var string */
private $min_wp_version; private $min_wp_version;
/** @var string|null */ /** @var string|null */
private $min_wc_version = null; private $min_wc_version = null;
/** @var int|null */ /** @var int|null */
private $min_openssl_version = null; private $min_openssl_version = null;
/** @var array */ /** @var array */
protected $plugin_require; protected $plugin_require;
/** @var bool */ /** @var bool */
protected $should_check_plugin_versions = false; protected $should_check_plugin_versions = false;
/** @var array */ /** @var array */
private $module_require; private $module_require;
/** @var array */ /** @var array */
private $setting_require; private $setting_require;
/** @var array */ /** @var array */
protected $notices; protected $notices;
/** @var @string */ /** @var @string */
private $text_domain; private $text_domain;
/**
* @var mixed|true
*/
private $use_transients;
/** /**
* @param string $plugin_file * @param string $plugin_file
...@@ -54,11 +81,13 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -54,11 +81,13 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
* @param string $text_domain * @param string $text_domain
* @param string $php_version * @param string $php_version
* @param string $wp_version * @param string $wp_version
* @param bool $use_transients
*/ */
public function __construct( $plugin_file, $plugin_name, $text_domain, $php_version, $wp_version ) { public function __construct( $plugin_file, $plugin_name, $text_domain, $php_version, $wp_version, $use_transients = true ) {
$this->plugin_file = $plugin_file; $this->plugin_file = $plugin_file;
$this->plugin_name = $plugin_name; $this->plugin_name = $plugin_name;
$this->text_domain = $text_domain; $this->text_domain = $text_domain;
$this->use_transients = $use_transients;
$this->set_min_php_require( $php_version ); $this->set_min_php_require( $php_version );
$this->set_min_wp_require( $wp_version ); $this->set_min_wp_require( $wp_version );
...@@ -321,32 +350,47 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -321,32 +350,47 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
/** /**
* Check the plugins directory and retrieve all plugin files with plugin data. * Check the plugins directory and retrieve all plugin files with plugin data.
* *
* @param bool $use_transients
*
* @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', ...], ] * @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', ...], ]
*/ */
private static function retrieve_plugins_data_in_transient() { private static function retrieve_plugins_data_in_transient( $use_transients = true ) {
static $never_executed = true; $current_time = time();
if ( $never_executed ) { if ( $use_transients) {
$never_executed = false; $plugins = get_transient( self::PLUGIN_INFO_TRANSIENT_NAME );
/** Required when WC starts later and these data should be in cache */ $expiration_time = get_transient( self::EXPIRATION_TRANSIENT_NAME );
add_filter( 'extra_plugin_headers', function ( $headers = array() ) { } else {
$headers[] = 'WC tested up to'; $plugins = get_option( self::PLUGIN_INFO_TRANSIENT_NAME );
$headers[] = 'WC requires at least'; $expiration_time = get_option( self::EXPIRATION_TRANSIENT_NAME );
$headers[] = 'Woo';
return array_unique( $headers );
} );
} }
$is_expired = ! $expiration_time || $current_time > $expiration_time;
if ( $plugins === false || $is_expired ) {
static $never_executed = true;
if ( $never_executed ) {
$never_executed = false;
/** Required when WC starts later and these data should be in cache */
add_filter( 'extra_plugin_headers', function( $headers = array() ) {
$headers[] = 'WC tested up to';
$headers[] = 'WC requires at least';
$headers[] = 'Woo';
return array_unique( $headers );
} );
}
$plugins = get_transient( self::PLUGIN_INFO_TRANSIENT_NAME );
if ( $plugins === false ) {
if ( ! function_exists( 'get_plugins' ) ) { if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php'; require_once ABSPATH . '/wp-admin/includes/plugin.php';
} }
$plugins = function_exists( 'get_plugins' ) ? get_plugins() : array(); $plugins = function_exists( 'get_plugins' ) ? get_plugins() : array();
set_transient( self::PLUGIN_INFO_TRANSIENT_NAME, $plugins, if ( $use_transients ) {
self::PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME ); set_transient( self::PLUGIN_INFO_TRANSIENT_NAME, $plugins, 0 );
set_transient( self::EXPIRATION_TRANSIENT_NAME, $current_time + self::CACHE_TIME, 0 );
} else {
update_option( self::PLUGIN_INFO_TRANSIENT_NAME, $plugins );
update_option( self::EXPIRATION_TRANSIENT_NAME, $current_time + self::CACHE_TIME );
}
} }
return $plugins; return $plugins;
...@@ -358,9 +402,8 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -358,9 +402,8 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
* @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', 'required_version' => '1.0.2']... ] * @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', 'required_version' => '1.0.2']... ]
*/ */
private function retrieve_required_plugins_data() { private function retrieve_required_plugins_data() {
$require_plugins = array(); $require_plugins = array();
$plugins = self::retrieve_plugins_data_in_transient(); $plugins = self::retrieve_plugins_data_in_transient( $this->use_transients );
if ( is_array( $plugins ) ) { if ( is_array( $plugins ) ) {
if ( count( $plugins ) > 0 ) { if ( count( $plugins ) > 0 ) {
if ( ! empty( $this->plugin_require ) ) { if ( ! empty( $this->plugin_require ) ) {
...@@ -420,7 +463,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -420,7 +463,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
if ( function_exists( 'wp_nonce_url' ) && function_exists( 'wp_create_nonce' ) ) { if ( function_exists( 'wp_nonce_url' ) && function_exists( 'wp_create_nonce' ) ) {
$install_url = wp_nonce_url( $install_url, 'install-plugin_' . $slug ); $install_url = wp_nonce_url( $install_url, 'install-plugin_' . $slug );
} }
add_filter( 'plugins_api', function ( $api, $action, $args ) use ( $plugin_info, $slug ) { add_filter( 'plugins_api', function( $api, $action, $args ) use ( $plugin_info, $slug ) {
if ( 'plugin_information' !== $action || if ( 'plugin_information' !== $action ||
false !== $api || false !== $api ||
! isset( $args->slug ) || ! isset( $args->slug ) ||
...@@ -450,7 +493,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -450,7 +493,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
$nice_name = $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ]; $nice_name = $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ];
if ( ! self::is_wp_plugin_active( $name ) ) { if ( ! self::is_wp_plugin_active( $name ) ) {
if ( ! self::is_wp_plugin_installed( $name ) ) { if ( ! self::is_wp_plugin_installed( $name, $this->use_transients ) ) {
$install_url = $this->prepare_plugin_repository_install_url( $plugin_info ); $install_url = $this->prepare_plugin_repository_install_url( $plugin_info );
return $this->prepare_notice_message( sprintf( wp_kses( __( 'The &#8220;%s&#8221; plugin requires free %s plugin. <a href="%s">Install %s</a>', return $this->prepare_notice_message( sprintf( wp_kses( __( 'The &#8220;%s&#8221; plugin requires free %s plugin. <a href="%s">Install %s</a>',
...@@ -491,11 +534,12 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -491,11 +534,12 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
* Checks if plugin is installed. Needs to be enabled in deferred way. * Checks if plugin is installed. Needs to be enabled in deferred way.
* *
* @param string $plugin_file * @param string $plugin_file
* @param bool $use_transients
* *
* @return bool * @return bool
*/ */
public static function is_wp_plugin_installed( $plugin_file ) { public static function is_wp_plugin_installed( $plugin_file, $use_transients = false ) {
$plugins_data = self::retrieve_plugins_data_in_transient(); $plugins_data = self::retrieve_plugins_data_in_transient( $use_transients );
return array_key_exists( $plugin_file, (array) $plugins_data ); return array_key_exists( $plugin_file, (array) $plugins_data );
} }
...@@ -564,7 +608,10 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -564,7 +608,10 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
* @deprecated use render_notices or disable_plugin * @deprecated use render_notices or disable_plugin
*/ */
public function disable_plugin_render_notice() { public function disable_plugin_render_notice() {
add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_render_notices_action' ) ); add_action( self::HOOK_ADMIN_NOTICES_ACTION, array(
$this,
'handle_render_notices_action'
) );
} }
/** /**
...@@ -573,7 +620,10 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -573,7 +620,10 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
* @return void * @return void
*/ */
public function render_notices() { public function render_notices() {
add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_render_notices_action' ) ); add_action( self::HOOK_ADMIN_NOTICES_ACTION, array(
$this,
'handle_render_notices_action'
) );
} }
/** /**
...@@ -582,7 +632,10 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -582,7 +632,10 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
* @return void * @return void
*/ */
public function disable_plugin() { public function disable_plugin() {
add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_deactivate_action' ) ); add_action( self::HOOK_ADMIN_NOTICES_ACTION, array(
$this,
'handle_deactivate_action'
) );
} }
/** /**
...@@ -594,7 +647,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -594,7 +647,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
if ( isset( $this->plugin_file ) ) { if ( isset( $this->plugin_file ) ) {
deactivate_plugins( plugin_basename( $this->plugin_file ) ); deactivate_plugins( plugin_basename( $this->plugin_file ) );
delete_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); $this->clear_plugin_info_data();
} }
} }
...@@ -604,8 +657,14 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -604,8 +657,14 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
* @return void * @return void
*/ */
public function transient_delete_on_plugin_version_changed() { public function transient_delete_on_plugin_version_changed() {
add_action( self::HOOK_PLUGIN_DEACTIVATED_ACTION, array( $this, 'handle_transient_delete_action' ) ); add_action( self::HOOK_PLUGIN_DEACTIVATED_ACTION, array(
add_action( self::HOOK_PLUGIN_ACTIVATED_ACTION, array( $this, 'handle_transient_delete_action' ) ); $this,
'clear_plugin_info_data'
) );
add_action( self::HOOK_PLUGIN_ACTIVATED_ACTION, array(
$this,
'clear_plugin_info_data'
) );
} }
/** /**
...@@ -613,8 +672,11 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -613,8 +672,11 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
* *
* @return void * @return void
*/ */
public function handle_transient_delete_action() { public function clear_plugin_info_data() {
delete_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); delete_transient( self::PLUGIN_INFO_TRANSIENT_NAME );
delete_transient( self::EXPIRATION_TRANSIENT_NAME );
delete_option( self::PLUGIN_INFO_TRANSIENT_NAME );
delete_option( self::EXPIRATION_TRANSIENT_NAME );
} }
/** /**
...@@ -629,5 +691,6 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { ...@@ -629,5 +691,6 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
echo $notice; echo $notice;
} }
} }
} }
} }
...@@ -44,7 +44,8 @@ ...@@ -44,7 +44,8 @@
$plugin_name, $plugin_name,
$text_domain, $text_domain,
$requirements['php'], $requirements['php'],
$requirements['wp'] $requirements['wp'],
(bool) wp_using_ext_object_cache()
); );
if ( isset( $requirements['plugins'] ) ) { if ( isset( $requirements['plugins'] ) ) {
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
WP_Mock::wpFunction( 'get_locale' ) WP_Mock::wpFunction( 'get_locale' )
->andReturn( $existing_locale ); ->andReturn( $existing_locale );
WP_Mock::wpFunction( 'wp_using_ext_object_cache')->andReturn( true );
$factory = new WPDesk_Basic_Requirement_Checker_Factory(); $factory = new WPDesk_Basic_Requirement_Checker_Factory();
$checker = $factory->create_from_requirement_array( 'whatever', 'whatever', $requirements ); $checker = $factory->create_from_requirement_array( 'whatever', 'whatever', $requirements );
...@@ -41,7 +43,7 @@ ...@@ -41,7 +43,7 @@
WP_Mock::passthruFunction( 'wp_nonce_url' ); WP_Mock::passthruFunction( 'wp_nonce_url' );
WP_Mock::passthruFunction( 'wp_create_nonce' ); WP_Mock::passthruFunction( 'wp_create_nonce' );
WP_Mock::passthruFunction( 'admin_url' ); WP_Mock::passthruFunction( 'admin_url' );
$this->assertFalse( $checker->are_requirements_met(), '2 plugins required and there should be none activated' ); $this->assertFalse( $checker->are_requirements_met(), '2 plugins required and there should be none activated' );
$this->expectOutputRegex( '/Flexible Checkout Fields/' ); $this->expectOutputRegex( '/Flexible Checkout Fields/' );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment