Skip to content

Upd. FW. Improve statement to check update - #708

Open
svfcode wants to merge 2 commits into
fixfrom
upd-fw-flow
Open

Upd. FW. Improve statement to check update#708
svfcode wants to merge 2 commits into
fixfrom
upd-fw-flow

Conversation

@svfcode

@svfcode svfcode commented Aug 9, 2026

Copy link
Copy Markdown
Member

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a cross-request “update lock” for the Security Firewall table swap window, and uses it to skip firewall DB UNION queries while FW tables are being dropped/renamed to avoid “table doesn’t exist” log spam during updates.

Changes:

  • Added FirewallUpdateLock (transient + filesystem flag + positive “tables ready” marker) and integrated it into FW checks.
  • Updated FW runtime (FW::check() and spbc_firewall_skip_check()) to skip DB access when the lock is active / tables are missing.
  • Updated FW update flow (spbc_security_firewall_update__end_of_update()) to set/clear the new lock, and added unit tests for lock behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/lib/CleantalkSP/SpbctWP/Firewall/FirewallUpdateLockTest.php Adds unit coverage for lock set/clear/skip behavior.
lib/CleantalkSP/SpbctWP/Firewall/FW.php Skips firewall DB queries when tables are locked/missing.
lib/CleantalkSP/SpbctWP/Firewall/FirewallUpdateLock.php Implements the new lock and table-readiness checks.
inc/spbc-firewall.php Ensures firewall skip logic re-reads the lock cross-request.
inc/fw-update.php Sets/clears the lock around the FW table swap stage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/CleantalkSP/SpbctWP/Firewall/FirewallUpdateLock.php Outdated
Comment thread lib/CleantalkSP/SpbctWP/Firewall/FirewallUpdateLock.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (3)

tests/lib/CleantalkSP/SpbctWP/Firewall/FirewallUpdateLockTest.php:93

  • assertFileNotExists() is deprecated/removed in newer PHPUnit versions; use assertFileDoesNotExist() to keep the test suite compatible beyond PHPUnit 8.x.
        $this->assertFalse(FirewallUpdateLock::isLocked());
        $this->assertFileNotExists($path);

tests/lib/CleantalkSP/SpbctWP/Firewall/FirewallUpdateLockTest.php:50

  • assertFileNotExists() is deprecated/removed in newer PHPUnit versions; this repo uses PHPUnit ^8.5 and should prefer assertFileDoesNotExist() for forward compatibility (and to avoid deprecation noise).

This issue also appears on line 92 of the same file.

        $path = FirewallUpdateLock::filePath();
        if ( $path ) {
            $this->assertFileNotExists($path);
        }

lib/CleantalkSP/SpbctWP/Firewall/FirewallUpdateLock.php:58

  • The lock uses set_transient()/get_transient() and a lock file under wp_upload_dir()['basedir'], both of which are blog-specific in WordPress multisite. At the same time, core FW tables (e.g., SPBC_TBL_FIREWALL_DATA_*) are defined with $wpdb->base_prefix (security-malware-firewall.php:117–119), so the swap window affects all sites. This can leave other sites unaware of the lock and still executing FW UNION queries during a swap. Consider using network-scoped storage for the lock on multisite (e.g., set_site_transient() and a network-wide lock-file path), while keeping current behavior on single-site installs.
        $now = time();
        set_transient(self::TRANSIENT_KEY, $now, self::TTL);
        delete_transient(self::TABLES_READY_KEY);
        self::bustTransientCaches();

        $path = self::filePath();
        if ( $path ) {
            $dir = dirname($path);
            if ( ! is_dir($dir) ) {
                // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.directory_mkdir
                @mkdir($dir, 0755, true);
            }
            @file_put_contents($path, (string) $now);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants