• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

equalizedigital / accessibility-checker / 24683125413

20 Apr 2026 06:22PM UTC coverage: 57.497% (-3.0%) from 60.51%
24683125413

push

github

web-flow
Merge pull request #1315 from equalizedigital/william/pro-286-update-the-free-plugin-to-be-able-to-handle-licence

Add support for registering sites with myDot and exchanging a jwt token that can be used to share site stats

440 of 1210 new or added lines in 9 files covered. (36.36%)

2 existing lines in 2 files now uncovered.

5426 of 9437 relevant lines covered (57.5%)

4.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.57
/admin/class-update-database.php
1
<?php
2
/**
3
 * Class file for updating the database.
4
 *
5
 * @package Accessibility_Checker
6
 * @since 1.9.0
7
 */
8

9
namespace EDAC\Admin;
10

11
if ( ! defined( 'ABSPATH' ) ) {
2✔
12
        exit;
×
13
}
14

15
/**
16
 * Class that handles admin notices
17
 *
18
 * @since 1.9.0
19
 */
20
class Update_Database {
21

22
        /**
23
         * Class constructor.
24
         */
25
        public function __construct() {
26
        }
48✔
27

28
        /**
29
         * Initialize WordPress hooks
30
         */
31
        public function init_hooks() {
32
                add_action( 'admin_init', [ $this, 'edac_update_database' ], 10 );
2✔
33
        }
34

35
        /**
36
         * Create/Update database
37
         *
38
         * @return void
39
         */
40
        public function edac_update_database() {
41

42
                global $wpdb;
46✔
43
                $table_name   = $wpdb->prefix . 'accessibility_checker';
46✔
44
                $table_exists = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
46✔
45
                        $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) )
46✔
46
                ) === $table_name;
46✔
47
                $db_version   = get_option( 'edac_db_version' );
46✔
48

49
                // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Prepare above, Safe variable used for table name, caching not required for one time operation.
50
                if ( EDAC_DB_VERSION !== $db_version || ! $table_exists ) {
46✔
51

52
                        $charset_collate = $wpdb->get_charset_collate();
4✔
53
                        $sql             = "CREATE TABLE $table_name (
4✔
54
                                id bigint(20) NOT NULL AUTO_INCREMENT,
55
                                postid bigint(20) NOT NULL,
56
                                siteid text NOT NULL,
57
                                type text NOT NULL,
58
                                landmark varchar(20) NULL,
59
                                landmark_selector text NULL,
60
                                selector text NULL,
61
                                ancestry text NULL,
62
                                xpath text NULL,
63
                                rule text NOT NULL,
64
                                ruletype text NOT NULL,
65
                                object mediumtext NOT NULL,
66
                                recordcheck mediumint(9) NOT NULL,
67
                                created timestamp NOT NULL default CURRENT_TIMESTAMP,
68
                                user bigint(20) NOT NULL,
69
                                ignre mediumint(9) NOT NULL,
70
                                ignre_global mediumint(9) NOT NULL,
71
                                ignre_user bigint(20) NULL,
72
                                ignre_date timestamp NULL,
73
                                ignre_reason varchar(50) NULL,
74
                                ignre_comment mediumtext NULL,
75
                                PRIMARY KEY (id),
76
                                KEY postid_index (postid)
77
                        ) $charset_collate;";
4✔
78

79
                        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
4✔
80
                        dbDelta( $sql );
4✔
81

82
                        // Run migration for selector-based unique identifiers if upgrading from older versions.
83
                        if ( version_compare( $db_version, '1.0.5', '<' ) ) {
4✔
84
                                $this->migrate_to_selector_based_unique_id();
4✔
85
                        }
86

87
                        // Migrate free plugin license key to shared option key used by both free and pro.
88
                        if ( version_compare( $db_version, '1.0.7', '<' ) ) {
4✔
89
                                $this->migrate_license_key_to_shared_option();
4✔
90
                        }
91
                }
92

93
                // Update database version option.
94
                update_option( 'edac_db_version', sanitize_text_field( EDAC_DB_VERSION ) );
46✔
95
        }
96

97
        /**
98
         * Migrate early testing key to the shared option used by both free and pro.
99
         *
100
         * Copies `edac_license_key` to `edacp_license_key` if the free key exists and the
101
         * shared key is not already set, then deletes the old option.
102
         *
103
         * @since 1.0.7
104
         * @return void
105
         */
106
        private function migrate_license_key_to_shared_option() {
107
                $migratable_key = get_option( 'edac_license_key', '' );
4✔
108

109
                if ( empty( $migratable_key ) ) {
4✔
110
                        return;
4✔
111
                }
112

113
                // Only copy if the shared key is not already occupied.
NEW
114
                if ( empty( get_option( 'edacp_license_key', '' ) ) ) {
×
NEW
115
                        update_option( 'edacp_license_key', $migratable_key );
×
116
                }
117

NEW
118
                delete_option( 'edac_license_key' );
×
119
        }
120

121
        /**
122
         * Migrate existing records to use selector-based unique identifiers.
123
         *
124
         * This migration handles records that were created before the selector field
125
         * was used as the unique identifier. Records with NULL selectors will have
126
         * a fallback identifier generated based on their ID to ensure uniqueness.
127
         *
128
         * @since 1.0.5
129
         * @return void
130
         */
131
        private function migrate_to_selector_based_unique_id() {
132
                global $wpdb;
4✔
133
                $table_name = $wpdb->prefix . 'accessibility_checker';
4✔
134

135
                // Find records with NULL or empty selectors and update them with a fallback value.
136
                // Using the record ID ensures each record has a unique selector for backward compatibility.
137
                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- One-time migration query.
138
                $wpdb->query(
4✔
139
                        $wpdb->prepare(
4✔
140
                                "UPDATE %i SET selector = CONCAT('legacy-id-', id) WHERE selector IS NULL OR selector = ''",
4✔
141
                                $table_name
4✔
142
                        )
4✔
143
                );
4✔
144
        }
145
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc