get_charset_collate(); $bookings = $wpdb->prefix . 'abfw_bookings'; // A booking keeps the dates, the length and the price it was sold at, so a // later change to the rules never moves or reprices what a customer bought. dbDelta( "CREATE TABLE {$bookings} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, product_id bigint(20) unsigned NOT NULL, variation_id bigint(20) unsigned NOT NULL DEFAULT 0, order_id bigint(20) unsigned NOT NULL DEFAULT 0, order_item_id bigint(20) unsigned NOT NULL DEFAULT 0, customer_id bigint(20) unsigned NOT NULL DEFAULT 0, start_date date NOT NULL, end_date date NOT NULL, units smallint(5) unsigned NOT NULL DEFAULT 1, quantity smallint(5) unsigned NOT NULL DEFAULT 1, status varchar(20) NOT NULL DEFAULT 'pending', created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY product_dates (product_id, start_date, end_date), KEY order_id (order_id), KEY status (status) ) {$charset_collate};" ); // Bookings taken before the five steps existed only knew paid and unpaid. // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $wpdb->query( "UPDATE {$bookings} SET status = 'pending' WHERE status = 'confirmed'" ); update_option( 'abfw_schema_version', self::SCHEMA_VERSION ); } /** * Rebuild the tables when the schema changed since the last load. * * @since 1.0.0 */ public static function maybe_update() { if ( get_option( 'abfw_schema_version' ) === self::SCHEMA_VERSION ) { return; } self::create_tables(); } }