wpdb; $database = (string) $wpdb->get_var( 'SELECT DATABASE()' ); $lock = \ABeCe\Booking\Infrastructure\Database\Tables::lock($wpdb,'season'); if ( '1' !== (string) $wpdb->get_var( $wpdb->prepare( 'SELECT GET_LOCK(%s, 5)', $lock ) ) ) { throw new CatalogException( 'abece_booking_season_busy', __( 'Seasons are being updated. Please try again.', 'abece-booking' ), 503 ); } try { $this->query( 'START TRANSACTION' ); $result = $operation(); $this->query( 'COMMIT' ); return $result; } catch ( Throwable $error ) { $wpdb->query( 'ROLLBACK' ); throw $error; } finally { $wpdb->get_var( $wpdb->prepare( 'SELECT RELEASE_LOCK(%s)', $lock ) ); } } public function clearDefaultExcept( ?int $id ): void { $wpdb = $this->wpdb; $this->query( $wpdb->prepare( 'UPDATE %i SET is_default = 0, updated_at = %s WHERE is_default <> 0 AND id <> %d', $this->table, current_time( 'mysql', true ), $id ?? 0 ) ); } private function query( string $sql ): void { $wpdb = $this->wpdb; if ( false === $wpdb->query( $sql ) ) { throw new CatalogException( 'abece_booking_database_error', __( 'The item could not be saved. Please try again.', 'abece-booking' ), 500 ); } } }