Skip to content

Commit

Permalink
Fixes #6729 Truncate OCI table on update to 3.16.1 (#6730)
Browse files Browse the repository at this point in the history
Co-authored-by: Tabrisrp <[email protected]>
Co-authored-by: WordPressFan <[email protected]>
  • Loading branch information
3 people authored Jun 20, 2024
1 parent a4a724d commit 7a90e86
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dynamic-lists-delayjs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dynamic-lists.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions inc/Engine/Media/AboveTheFold/Admin/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,20 @@ public function clean_url() {

$this->query->delete_by_url( untrailingslashit( $url ) );
}

/**
* Truncate ATF table on update to 3.16.1.1 and higher
*
* @param string $new_version New plugin version.
* @param string $old_version Old plugin version.
*
* @return void
*/
public function truncate_on_update( $new_version, $old_version ) {
if ( version_compare( $old_version, '3.16.1', '>=' ) ) {
return;
}

$this->truncate_atf();
}
}
13 changes: 13 additions & 0 deletions inc/Engine/Media/AboveTheFold/Admin/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function get_subscribed_events(): array {
'pre_delete_term' => 'delete_term_atf',
'rocket_saas_clean_all' => 'truncate_atf_admin',
'rocket_saas_clean_url' => 'clean_url',
'wp_rocket_upgrade' => [ 'truncate_on_update', 10, 2 ],
];
}

Expand Down Expand Up @@ -93,4 +94,16 @@ public function truncate_atf_admin( $clean ) {
public function clean_url() {
$this->controller->clean_url();
}

/**
* Truncate ATF table on update to 3.16.1 and higher
*
* @param string $new_version New plugin version.
* @param string $old_version Old plugin version.
*
* @return void
*/
public function truncate_on_update( $new_version, $old_version ) {
$this->controller->truncate_on_update( $new_version, $old_version );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

return [
'testShouldDoNothingWhenVersionUnder3.16.1' => [
'config' => [
'filter' => true,
'new_version' => '3.16.2',
'old_version' => '3.16.1',
'not_completed' => 0,
],
'expected' => false,
],
'testShouldTruncateWhenVersion3.16.1AndHigher' => [
'config' => [
'filter' => true,
'new_version' => '3.16.1',
'old_version' => '3.15.0',
'not_completed' => 0,
],
'expected' => true,
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Tests\Unit\inc\Engine\Media\AboveTheFold\Admin\Controller;

use Mockery;
use WP_Rocket\Engine\Media\AboveTheFold\Context\Context;
use WP_Rocket\Engine\Media\AboveTheFold\Database\Tables\AboveTheFold as ATFTable;
use WP_Rocket\Engine\Media\AboveTheFold\Database\Queries\AboveTheFold as ATFQuery;
use WP_Rocket\Engine\Media\AboveTheFold\Admin\Controller;
use WP_Rocket\Tests\Unit\TestCase;

/**
* Test class covering WP_Rocket\Engine\Media\AboveTheFold\Admin\Controller::truncate_atf
*
* @group ATF
*/
class TestTruncateOnUpdate extends TestCase {
private $controller;
private $query;
private $table;
private $context;

public function setUp(): void {
parent::setUp();

$this->query = $this->createMock( ATFQuery::class );
$this->table = $this->createMock( ATFTable::class );
$this->context = Mockery::mock( Context::class );
$this->controller = new Controller( $this->table, $this->query, $this->context );
}

/**
* @dataProvider configTestData
*/
public function testShouldDoExpected( $config, $expected ) {
$this->context->shouldReceive( 'is_allowed' )
->atMost()
->once()
->andReturn( $config['filter'] );

if ( ! $expected ) {
$this->query->expects( $this->never() )
->method( 'get_not_completed_count' );
} else {
$this->query->expects( $this->once() )
->method( 'get_not_completed_count' )
->willReturn( $config['not_completed'] );

$this->table->expects( $this->once() )
->method( 'truncate_atf_table' );
}

$this->controller->truncate_on_update( $config['new_version'], $config['old_version'] );
}
}
4 changes: 2 additions & 2 deletions wp-rocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Rocket
* Plugin URI: https://wp-rocket.me
* Description: The best WordPress performance plugin.
* Version: 3.16.1
* Version: 3.16.1.1
* Requires at least: 5.8
* Requires PHP: 7.3
* Code Name: Iego
Expand All @@ -20,7 +20,7 @@
defined( 'ABSPATH' ) || exit;

// Rocket defines.
define( 'WP_ROCKET_VERSION', '3.16.1' );
define( 'WP_ROCKET_VERSION', '3.16.1.1' );
define( 'WP_ROCKET_WP_VERSION', '5.8' );
define( 'WP_ROCKET_WP_VERSION_TESTED', '6.3.1' );
define( 'WP_ROCKET_PHP_VERSION', '7.3' );
Expand Down

0 comments on commit 7a90e86

Please sign in to comment.