Skip to content

Ref. AntiCrawler. Module flow refactored.#788

Open
alexandergull wants to merge 17 commits intodevfrom
anti-crawler-ref.ag
Open

Ref. AntiCrawler. Module flow refactored.#788
alexandergull wants to merge 17 commits intodevfrom
anti-crawler-ref.ag

Conversation

@alexandergull
Copy link
Copy Markdown
Member

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

❌ Patch coverage is 52.73632% with 95 lines in your changes missing coverage. Please review.
✅ Project coverage is 15.13%. Comparing base (0132ded) to head (e585c66).
⚠️ Report is 17 commits behind head on dev.

Files with missing lines Patch % Lines
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php 53.33% 91 Missing ⚠️
cleantalk.php 0.00% 2 Missing ⚠️
lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php 50.00% 2 Missing ⚠️

❌ Your patch check has failed because the patch coverage (52.73%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev     #788      +/-   ##
============================================
+ Coverage     14.46%   15.13%   +0.67%     
- Complexity     5543     5584      +41     
============================================
  Files           263      264       +1     
  Lines         27231    27313      +82     
============================================
+ Hits           3939     4134     +195     
+ Misses        23292    23179     -113     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the AntiCrawler firewall module flow and renames/extracts UA blacklist table maintenance helpers, aligning SFW update code to the new AntiCrawler API.

Changes:

  • Renamed/extracted UA blacklist import & truncate helpers (updateUADataTable(), clearUADataTable()) and updated callers.
  • Refactored AntiCrawler::check() into clearer pre-check + log-check subroutines and added module constants/debug helper.
  • Renamed AntiCrawler log cleanup method to clearLogTable() and updated cron caller.

Reviewed changes

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

File Description
lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php Switches UA list processing to AntiCrawler::updateUADataTable().
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Major AntiCrawler flow refactor; adds UA table helpers, cookie/param constants, debug helper, and method renames.
cleantalk.php Updates SFW update stage to use clearUADataTable() and cron cleanup to use clearLogTable().
Comments suppressed due to low confidence (2)

lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php:66

  • processUA() checks !empty($result['error']) before verifying that $result is an array. On success AntiCrawler::updateUADataTable() returns an int, so this will trigger a PHP warning (array offset on int). Check is_array($result) (or isset($result['error'])) before reading the 'error' key, or normalize updateUADataTable() to always return an array structure.
        $result = AntiCrawler::updateUADataTable($file_path);

        if ( ! empty($result['error']) ) {
            return array('error' => 'UPDATING UA LIST: ' . $result['error']);
        }

        if ( ! is_int($result) ) {
            return array('error' => 'UPDATING UA LIST: : WRONG_RESPONSE AntiCrawler::update');

cleantalk.php:1592

  • AntiCrawler::clearUADataTable() returns void/null on success, but this code immediately reads $result__clear_db['error'], which will raise a PHP warning when the call succeeds (array offset on null). Either make clearUADataTable() return a consistent array result (e.g. [] on success), or guard with is_array($result__clear_db) before accessing ['error'].
    $result__clear_db = AntiCrawler::clearUADataTable(
        \Cleantalk\ApbctWP\DB::getInstance(),
        APBCT_TBL_AC_UA_BL
    );

    if ( ! empty($result__clear_db['error']) ) {
        return $result__clear_db['error'];
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Outdated
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Outdated
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 22, 2026 08:44
svfcode and others added 2 commits April 22, 2026 11:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the AntiCrawler firewall module flow and renames UA blacklist table maintenance methods, updating call sites accordingly.

Changes:

  • Refactors AntiCrawler::check() into clearer pre-check and log-check phases, adding helper methods and debug logging.
  • Renames UA blacklist import/cleanup helpers (update()updateUADataTable(), clearDataTable()clearUADataTable()), and renames log cleanup (clearTable()clearLogTable()).
  • Updates SFW/UA update pipeline call sites to use the new AntiCrawler method names.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php Switches UA list processing to the renamed AntiCrawler UA import method.
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Major refactor of AntiCrawler module flow; introduces new helper methods, constants, renamed APIs, and debug facility.
cleantalk.php Updates UA table cleanup and AntiCrawler log cleanup to use renamed AntiCrawler methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Outdated
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 22, 2026 08:59
svfcode and others added 2 commits April 22, 2026 12:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the AntiCrawler firewall module flow and renames/moves UA blacklist maintenance helpers to clearer, more specific method names.

Changes:

  • Refactored AntiCrawler runtime check flow into smaller helper methods (pre-checks, UA check, log lookup, cookie handling) and added optional debug logging.
  • Renamed UA blacklist maintenance helpers (updateupdateUADataTable, clearDataTableclearUADataTable) and updated call sites.
  • Renamed AntiCrawler log cleanup method (clearTableclearLogTable) and updated cron usage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php Updates UA processing to call the renamed AntiCrawler UA import method.
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Major refactor of module flow; adds UA import/clear helpers and debug logging; renames redirect/Cloudflare helpers and log cleanup method.
cleantalk.php Updates callers to new AntiCrawler UA-table and log-table helper method names.
Comments suppressed due to low confidence (1)

cleantalk.php:1592

  • AntiCrawler::clearUADataTable() returns array-on-error and void-on-success, but this caller treats the return value as an array and reads ['error']. Consider updating the call site to handle the void/array contract explicitly (or, preferably, adjust clearUADataTable() to always return a consistent type).
    $result__clear_db = AntiCrawler::clearUADataTable(
        \Cleantalk\ApbctWP\DB::getInstance(),
        APBCT_TBL_AC_UA_BL
    );

    if ( ! empty($result__clear_db['error']) ) {
        return $result__clear_db['error'];
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Outdated
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 22, 2026 09:12
svfcode and others added 2 commits April 22, 2026 12:14
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the AntiCrawler firewall module flow and clarifies responsibilities by splitting “check” logic into smaller methods, while also renaming UA table maintenance helpers to be more explicit.

Changes:

  • Refactored AntiCrawler::check() into pre-check and log-search stages with helper methods and constants for cookie/param names.
  • Renamed UA import/cleanup helpers (update()updateUADataTable(), clearDataTable()clearUADataTable()) and updated call sites.
  • Renamed AntiCrawler log cleanup method (clearTable()clearLogTable()).

Reviewed changes

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

File Description
lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php Updates UA-processing to call the renamed UA import method and adjusts the related error string.
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Major AntiCrawler refactor: new helpers, constants, renamed methods, and UA table import/clear functions.
cleantalk.php Updates SFW temp-table stage and cron cleanup to call renamed AntiCrawler helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Outdated
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Copilot AI review requested due to automatic review settings April 27, 2026 10:02
Copy link
Copy Markdown

Copilot AI left a comment

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 refactors the AntiCrawler firewall module flow and updates related update/maintenance hooks, adding PHPUnit coverage for key AntiCrawler behaviors.

Changes:

  • Refactored AntiCrawler::check() into smaller pre-check/log-check helper methods and added UA table maintenance helpers (updateUADataTable, clearUADataTable).
  • Updated UA update pipeline to validate UA file paths and call the renamed UA update method.
  • Added a new PHPUnit test suite covering AntiCrawler early-exit conditions and AC log writes.

Reviewed changes

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

File Description
tests/ApbctWP/Firewall/TestAntiCrawler.php Adds unit tests for AntiCrawler check() behavior and updateAcLog() SQL writes.
lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php Adds path existence checks for UA processing and switches to AntiCrawler::updateUADataTable().
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Major refactor of module control flow; adds UA table import/clear helpers; renames/clarifies several internal methods.
cleantalk.php Updates call sites to renamed AntiCrawler UA clear + log clear methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php Outdated
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Outdated
svfcode and others added 2 commits April 27, 2026 13:09
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 27, 2026 10:18
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

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 refactors the AntiCrawler firewall module flow and updates the SFW/UA update pipeline to use newly named UA table helper methods, along with adding PHPUnit coverage for key AntiCrawler behaviors.

Changes:

  • Refactored AntiCrawler execution flow into clearer pre-check and log-check phases, adding helper methods/constants and renaming some internal behaviors.
  • Replaced legacy UA import/clear entry points with updateUADataTable() / clearUADataTable() and updated update helpers/callers accordingly.
  • Added PHPUnit tests validating AntiCrawler outcomes (invalid key, redirect pass, known-IP deny, log writes).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/ApbctWP/Firewall/TestAntiCrawler.php Adds new unit tests for AntiCrawler check paths and AC log writing.
lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php Switches UA processing to AntiCrawler::updateUADataTable() and adds file existence guard.
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Major AntiCrawler refactor; introduces new UA import/clear static methods and reorganizes logic.
cleantalk.php Updates UA table clear call and renames AntiCrawler log cleanup method invocation.
Comments suppressed due to low confidence (1)

cleantalk.php:1592

  • AntiCrawler::clearUADataTable() returns void on success and an array only on failure. Here $result__clear_db will commonly be null, so accessing $result__clear_db['error'] will raise a fatal error on PHP 8+ (offset access on null). Also the error branch returns a raw string, but other callers (e.g. direct update flow) expect an array with an 'error' key. Please make the return contract consistent (e.g. have clearUADataTable() always return an array like []/['error'=>...], and keep this function returning ['error'=>...] instead of a string), and guard with is_array() before reading ['error'].
    );

    if ( ! empty($result__clear_db['error']) ) {
        return $result__clear_db['error'];
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php
Comment thread tests/ApbctWP/Firewall/TestAntiCrawler.php
Comment thread tests/ApbctWP/Firewall/TestAntiCrawler.php
Copilot AI review requested due to automatic review settings April 27, 2026 10:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the AntiCrawler firewall module flow (pre-checks, log checks, exclusions) and updates the SFW UA-list update pipeline accordingly, with added PHPUnit coverage for key AntiCrawler behaviors.

Changes:

  • Refactored AntiCrawler::check() flow into smaller helpers (pre-checks, log search, cookie/bot-detector handling) and introduced UA-table helper methods.
  • Updated SFW UA-list processing to call AntiCrawler::updateUADataTable() and renamed related table-clear / log-clear helpers.
  • Added a new PHPUnit test suite for AntiCrawler behaviors and DB interactions.

Reviewed changes

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

File Description
tests/ApbctWP/Firewall/TestAntiCrawler.php Adds PHPUnit tests for AntiCrawler outcomes (invalid key, redirects, known IP deny, AC log writes, die page build).
lib/Cleantalk/ApbctWP/Firewall/SFWUpdateHelper.php Switches UA-list processing to updateUADataTable() and adds a file existence guard.
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Major refactor of module control flow; adds UA import/clear helpers and renames log cleanup method.
cleantalk.php Updates call sites to renamed UA-table clear and AntiCrawler log cleanup methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +472 to 475
* @param string $ip Visitor IP address.
* @param string $status Check result status (e.g. 'PASS_ANTICRAWLER', 'DENY_ANTICRAWLER').
*/
public function updateLog($ip, $status)

$result = AntiCrawler::updateUADataTable($file_path);

if ( ! empty($result['error']) ) {
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.

4 participants