-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathclass-update-database.php
More file actions
79 lines (68 loc) · 2.02 KB
/
Copy pathclass-update-database.php
File metadata and controls
79 lines (68 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Class file for updating the database.
*
* @package Accessibility_Checker
* @since 1.9.0
*/
namespace EDAC\Admin;
/**
* Class that handles admin notices
*
* @since 1.9.0
*/
class Update_Database {
/**
* Class constructor.
*/
public function __construct() {
}
/**
* Initialize WordPress hooks
*/
public function init_hooks() {
add_action( 'admin_init', [ $this, 'edac_update_database' ], 10 );
}
/**
* Create/Update database
*
* @return void
*/
public function edac_update_database() {
global $wpdb;
$table_name = $wpdb->prefix . 'accessibility_checker';
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
// 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.
if ( get_option( 'edac_db_version' ) !== EDAC_DB_VERSION || $wpdb->get_var( $query ) !== $table_name ) {
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id bigint(20) NOT NULL AUTO_INCREMENT,
postid bigint(20) NOT NULL,
siteid text NOT NULL,
type text NOT NULL,
landmark varchar(20) NULL,
landmark_selector text NULL,
selector text NULL,
ancestry text NULL,
xpath text NULL,
rule text NOT NULL,
ruletype text NOT NULL,
object mediumtext NOT NULL,
recordcheck mediumint(9) NOT NULL,
created timestamp NOT NULL default CURRENT_TIMESTAMP,
user bigint(20) NOT NULL,
ignre mediumint(9) NOT NULL,
ignre_global mediumint(9) NOT NULL,
ignre_user bigint(20) NULL,
ignre_date timestamp NULL,
ignre_comment mediumtext NULL,
UNIQUE KEY id (id),
KEY postid_index (postid)
) $charset_collate;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
}
// Update database version option.
update_option( 'edac_db_version', sanitize_text_field( EDAC_DB_VERSION ) );
}
}