close
Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ public static function create_lock( $lock_name, $release_timeout = null ) {
// Try to lock.
$lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'off') /* LOCK */", $lock_option, time() ) );

if ( ! $lock_result ) {
if ( 0 === $lock_result ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've chatted with @afragen about this. We're unsure how this actually makes a chance. If the query method “returns an integer value indicating the number of rows affected/selected” then a value of zero is just as falsy as false, so the result would be the same?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the actual return value from MariaDB if no matching row is found?

What I found in searching was it returns an empty set but I don't know the exact syntax of it. It's possible that that could be the difference.

Copy link
Copy Markdown
Member

@afragen afragen Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are instances in WPDB::query() where the return value is false and 0 !== false. While this gives the expected result it seems sloppy as the return is an actual boolean.

$lock_result = get_option( $lock_option );

// If a lock couldn't be created, and there isn't a lock, bail.
Expand Down
36 changes: 36 additions & 0 deletions tests/phpunit/tests/admin/wpUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,42 @@ public function test_maintenance_mode_should_create_maintenance_file_with_boolea
self::$instance->maintenance_mode( true );
}

/**
* Tests that `WP_Upgrader::create_lock()` creates the 'lock' option.
*
* @covers WP_Upgrader::create_lock
*/
public function test_create_lock_should_create_lock_option() {
WP_Upgrader::create_lock( 'lock' );

// Check that the lock option was created with a timestamp less than or equal to now.
$this->assertLessThanOrEqual(
time(),
get_option( 'lock.lock' ),
'The lock option was not created as expected.'
);
}

/**
* Tests that `WP_Upgrader::create_lock()` releases expired lock.
*
* @ticket 64080
*
* @covers WP_Upgrader::create_lock
*/
public function test_create_lock_should_release_lock() {
$this->assertTrue( WP_Upgrader::create_lock( 'lock' ) );

$this->assertTrue( update_option( 'lock.lock', time() - 2 ) );

$recreate_lock = WP_Upgrader::create_lock( 'lock', 1 );

$this->assertTrue(
$recreate_lock,
'The lock was not re-created as expected.'
);
}

/**
* Tests that `WP_Upgrader::release_lock()` removes the 'lock' option.
*
Expand Down
Loading