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

Closes #5640: Wrong Home URL TranslatePress #6266

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function treeshake( string $html ): string {
public function add_url_to_the_queue( string $url, bool $is_mobile ) {
$used_css_row = $this->used_css_query->get_row( $url, $is_mobile );
if ( empty( $used_css_row ) ) {
$this->used_css_query->create_new_job( $url, '', '', $is_mobile );
$this->used_css_query->create_new_job( $url, '', '', $is_mobile, $this->is_home( $url ) );
return;
}
$this->used_css_query->reset_job( (int) $used_css_row->id );
Expand Down Expand Up @@ -527,7 +527,7 @@ public function check_job_status( int $id ) {
}

// Send the request to get the job status from SaaS.
$job_details = $this->api->get_queue_job_status( $row_details->job_id, $row_details->queue_name, $this->is_home( $row_details->url ) );
$job_details = $this->api->get_queue_job_status( $row_details->job_id, $row_details->queue_name, (bool) $row_details->is_home );

/**
* Filters the rocket min rucss css result size.
Expand Down
4 changes: 3 additions & 1 deletion inc/Engine/Optimization/RUCSS/Database/Queries/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ public function update_job_id( $id, $new_job_id ) {
* @param string $job_id API job_id.
* @param string $queue_name API Queue name.
* @param bool $is_mobile if the request is for mobile page.
* @param bool $is_home if the url is home url.
*
* @return bool
*/
public function create_new_job( string $url, string $job_id = '', string $queue_name = '', bool $is_mobile = false ) {
public function create_new_job( string $url, string $job_id = '', string $queue_name = '', bool $is_mobile = false, bool $is_home = false ) {
if ( ! self::$table_exists && ! $this->table_exists() ) {
return false;
}
Expand All @@ -230,6 +231,7 @@ public function create_new_job( string $url, string $job_id = '', string $queue_
'job_id' => $job_id,
'queue_name' => $queue_name,
'status' => 'to-submit',
'is_home' => $is_home,
'retries' => 0,
'last_accessed' => current_time( 'mysql', true ),
];
Expand Down
8 changes: 8 additions & 0 deletions inc/Engine/Optimization/RUCSS/Database/Row/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ class UsedCSS extends Row {
*/
public $status;

/**
* Is home URL
*
* @var bool
*/
public $is_home;

/**
* Last modified time
*
Expand Down Expand Up @@ -136,5 +143,6 @@ public function __construct( $item ) {
$this->modified = empty( $this->modified ) ? 0 : strtotime( $this->modified );
$this->last_accessed = empty( $this->last_accessed ) ? 0 : strtotime( $this->last_accessed );
$this->submitted_at = empty( $this->submitted_at ) ? 0 : strtotime( $this->submitted_at );
$this->is_home = (bool) $this->is_home;
}
}
11 changes: 11 additions & 0 deletions inc/Engine/Optimization/RUCSS/Database/Schemas/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,16 @@ class UsedCSS extends Schema {
'date_query' => true,
'sortable' => true,
],

// IS_HOME column.
[
'name' => 'is_home',
'type' => 'tinyint',
'length' => '1',
'default' => 0,
'cache_key' => true,
'searchable' => true,
'sortable' => true,
],
];
}
21 changes: 20 additions & 1 deletion inc/Engine/Optimization/RUCSS/Database/Tables/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UsedCSS extends Table {
*
* @var int
*/
protected $version = 20231010;
protected $version = 20231110;

/**
* Key => value array of versions => methods.
Expand All @@ -42,6 +42,7 @@ class UsedCSS extends Table {
20220920 => 'make_status_column_index_instead_queue_name',
20221104 => 'add_error_columns',
20231010 => 'add_submitted_at_column',
20231110 => 'add_is_home',
Miraeld marked this conversation as resolved.
Show resolved Hide resolved
];

/**
Expand Down Expand Up @@ -72,6 +73,7 @@ protected function set_schema() {
job_id varchar(255) NOT NULL default '',
queue_name varchar(255) NOT NULL default '',
status varchar(255) NOT NULL default '',
is_home tinyint(1) NOT NULL default 0,
modified timestamp NOT NULL default '0000-00-00 00:00:00',
last_accessed timestamp NOT NULL default '0000-00-00 00:00:00',
submitted_at timestamp NULL,
Expand Down Expand Up @@ -342,4 +344,21 @@ protected function add_submitted_at_column() {

return $this->is_success( $created );
}

/**
* Adds the is_home column.
*
* @return bool
*/
protected function add_is_home() {
$is_home_exists = $this->column_exists( 'is_home' );

$created = true;

if ( ! $is_home_exists ) {
$created &= $this->get_db()->query( "ALTER TABLE `{$this->table_name}` ADD COLUMN is_home tinyint(1) DEFAULT 0 AFTER status" );
}

return $this->is_success( $created );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'job_id' => 'EU-1',
'queue_name' => 'EU',
'is_mobile' => false,
'is_home' => true,
'now' => '2023-10-11 20:21:00',
'result' => true
],
Expand All @@ -16,6 +17,7 @@
'queue_name' => 'EU',
'is_mobile' => false,
'status' => 'to-submit',
'is_home' => true,
'retries' => 0,
'last_accessed' => '2023-10-11 20:21:00',
],
Expand All @@ -28,6 +30,7 @@
'job_id' => '',
'queue_name' => '',
'is_mobile' => false,
'is_home' => true,
'now' => '2023-10-11 20:21:00',
'result' => true
],
Expand All @@ -38,6 +41,7 @@
'queue_name' => '',
'is_mobile' => false,
'status' => 'to-submit',
'is_home' => true,
'retries' => 0,
'last_accessed' => '2023-10-11 20:21:00',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public function testShouldReturnAsExpected( $config, $expected )

$this->usedcss->expects(self::once())->method('add_item')->with($expected['item'])->willReturn($config['result']);

$this->assertSame($expected['result'], $this->usedcss->create_new_job($config['url'], $config['job_id'], $config['queue_name'], $config['is_mobile']));
$this->assertSame($expected['result'], $this->usedcss->create_new_job($config['url'], $config['job_id'], $config['queue_name'], $config['is_mobile'], $config['is_home']));
}
}
Loading