From a15bfb7f89ecbc371d1afe1a19d9f686265509e1 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Mon, 24 Jun 2024 15:55:54 +0100 Subject: [PATCH] Add some tweaks to handle a namespace update in pro and preserve back compat --- admin/class-scans-stats.php | 22 +++++++++++++++++++--- admin/class-settings.php | 9 +++++++-- includes/options-page.php | 3 ++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/admin/class-scans-stats.php b/admin/class-scans-stats.php index e7be48ef..04c4227f 100644 --- a/admin/class-scans-stats.php +++ b/admin/class-scans-stats.php @@ -7,6 +7,8 @@ namespace EDAC\Admin; +use EqualizeDigital\AccessibilityCheckerPro\Admin\Scans; + /** * Class that handles calculating scans stats */ @@ -176,7 +178,7 @@ function ( $item ) { if ( $rule_query->count() ) { ++$data['rules_failed']; - } + } } $data['rules_passed'] = $this->rule_count - $data['rules_failed']; @@ -231,7 +233,7 @@ function ( $item ) { $data['posts_without_issues'] = 0; $data['avg_issues_per_post'] = 0; - if ( $data['posts_scanned'] > 0 + if ( $data['posts_scanned'] > 0 && ! empty( Settings::get_scannable_post_types() ) && ! empty( Settings::get_scannable_post_statuses() ) ) { @@ -270,7 +272,20 @@ function ( $item ) { $data['fullscan_state'] = ''; $data['fullscan_completed_at'] = 0; - if ( class_exists( '\EDACP\Scans' ) ) { + // For back compat reasons the old class_exists is kept and moved to an else block. + // After a few releases the else should be removed. + if ( class_exists( '\EqualizeDigital\AccessibilityCheckerPro\Admin\Scans' ) ) { + $scans = new Scans(); + $scan_state = $scans->scan_state(); + + $data['fullscan_state'] = $scan_state; + if ( Scans::SCAN_STATE_PHP_SCAN_RUNNING === $scan_state + || Scans::SCAN_STATE_JS_SCAN_RUNNING === $scan_state + ) { + $data['fullscan_running'] = true; + } + $data['fullscan_completed_at'] = $scans->scan_date( 'php' ); + } elseif ( class_exists( '\EDACP\Scans' ) ) { $scans = new \EDACP\Scans(); $scan_state = $scans->scan_state(); @@ -281,6 +296,7 @@ function ( $item ) { $data['fullscan_running'] = true; } $data['fullscan_completed_at'] = $scans->scan_date( 'php' ); + } $data['cache_id'] = $transient_name; diff --git a/admin/class-settings.php b/admin/class-settings.php index e0028ae3..20a4af9e 100644 --- a/admin/class-settings.php +++ b/admin/class-settings.php @@ -29,7 +29,10 @@ public static function get_scannable_post_statuses() { */ public static function get_scannable_post_types() { - if ( ! class_exists( '\EDACP\Settings' ) ) { + // Check if the new settings class exists. This is added to allow for backwards compatibility + // with the old settings class. The old settings class check should be removed after a few releases. + $new_settings_class_exists = class_exists( 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings' ); + if ( ! class_exists( '\EDACP\Settings' ) || ! $new_settings_class_exists ) { $post_types = Helpers::get_option_as_array( 'edac_post_types' ); @@ -53,7 +56,9 @@ public static function get_scannable_post_types() { return $post_types; } - return \EDACP\Settings::get_scannable_post_types(); + return $new_settings_class_exists + ? \EqualizeDigital\AccessibilityCheckerPro\Admin\Settings::get_scannable_post_types() + : \EDACP\Settings::get_scannable_post_types(); } diff --git a/includes/options-page.php b/includes/options-page.php index 71db210f..601a3e1c 100644 --- a/includes/options-page.php +++ b/includes/options-page.php @@ -490,7 +490,8 @@ function edac_sanitize_post_types( $selected_post_types ) { $scan_stats = new \EDAC\Admin\Scans_Stats(); $scan_stats->clear_cache(); - if ( class_exists( '\EDACP\Scans' ) ) { + // EDACP\Scans is the old namespace, kept for back compat but should be removed after a few releases. + if ( class_exists( '\EDACP\Scans' ) || class_exists( '\EqualizeDigital\AccessibilityCheckerPro\Admin\Scans' ) ) { delete_option( 'edacp_fullscan_completed_at' ); } }