prefix . 'aculect_ai_companion_activity'; } /** * Return the logical activity store when its table is unavailable. * * @return list */ public static function missing_table_keys(): array { global $wpdb; $table = self::table_name(); return $table === (string) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ) ) ? array() : array( 'activity' ); } /** * Remove activity log storage and schema option. */ public static function uninstall(): void { global $wpdb; $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', self::table_name() ) ); delete_option( self::OPTION_DB_VERSION ); } /** * Create or upgrade the activity table through dbDelta(). */ private static function create_table(): void { global $wpdb; $charset = $wpdb->get_charset_collate(); $table = self::table_name(); $sql = "CREATE TABLE {$table} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, provider varchar(40) DEFAULT NULL, client_id varchar(100) DEFAULT NULL, client_name varchar(255) DEFAULT NULL, user_id bigint(20) unsigned DEFAULT NULL, action varchar(100) NOT NULL, target_type varchar(60) DEFAULT NULL, target_id bigint(20) unsigned DEFAULT NULL, status varchar(20) NOT NULL DEFAULT 'success', error_code varchar(100) DEFAULT NULL, message text DEFAULT NULL, context longtext DEFAULT NULL, PRIMARY KEY (id), KEY created_at (created_at), KEY provider (provider), KEY client_id (client_id), KEY user_id (user_id), KEY action (action), KEY target (target_type, target_id), KEY status (status), KEY error_code (error_code) ) {$charset};\n"; if ( ! function_exists( 'dbDelta' ) ) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; } dbDelta( $sql ); } }