| 1 |
<?php |
| 2 |
/** |
| 3 |
* Pro-only database table creation methods. |
| 4 |
* |
| 5 |
* @package WP_Defender\Traits |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Traits; |
| 9 |
|
| 10 |
/** |
| 11 |
* Provides database table creation for Pro-only features (Audit Logging). |
| 12 |
*/ |
| 13 |
trait Pro_Database_Tables { |
| 14 |
|
| 15 |
/** |
| 16 |
* Creates the audit log table used for caching audit events. |
| 17 |
*/ |
| 18 |
protected function create_table_audit_log(): void { |
| 19 |
global $wpdb; |
| 20 |
|
| 21 |
$charset_collate = $wpdb->get_charset_collate(); |
| 22 |
// Audit log table. Though our data mainly store on API side, we will need a table for caching. |
| 23 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->base_prefix}defender_audit_log ( |
| 24 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 25 |
`timestamp` int NOT NULL, |
| 26 |
`event_type` varchar(255) NOT NULL, |
| 27 |
`action_type` varchar(255) NOT NULL, |
| 28 |
`site_url` varchar(255) NOT NULL, |
| 29 |
`user_id` int NOT NULL, |
| 30 |
`context` varchar(255) NOT NULL, |
| 31 |
`ip` varchar(45) NOT NULL, |
| 32 |
`msg` varchar(255) NOT NULL, |
| 33 |
`blog_id` int NOT NULL, |
| 34 |
`synced` int NOT NULL, |
| 35 |
`ttl` int NOT NULL, |
| 36 |
PRIMARY KEY (`id`), |
| 37 |
KEY `event_type` (`event_type`), |
| 38 |
KEY `action_type` (`action_type`), |
| 39 |
KEY `user_id` (`user_id`), |
| 40 |
KEY `context` (`context`), |
| 41 |
KEY `ip` (`ip`) |
| 42 |
) $charset_collate;"; |
| 43 |
$wpdb->query( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 44 |
} |
| 45 |
} |
| 46 |
|