abstract-booking-ability.php
1 week ago
approve-booking.php
4 months ago
cancel-booking.php
4 months ago
change-booking-status.php
1 week ago
create-booking.php
4 months ago
delete-booking.php
1 week ago
get-booking-stats.php
1 week ago
get-booking-statuses.php
4 months ago
get-booking.php
1 week ago
get-bookings-for-date.php
4 months ago
get-bookings-per-day.php
1 week ago
get-upcoming-bookings.php
4 months ago
list-bookings.php
4 months ago
reschedule-booking.php
1 week ago
update-booking.php
1 week ago
delete-booking.php
61 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; } |
| 4 | |
| 5 | class LatePointAbilityDeleteBooking extends LatePointAbstractBookingAbility { |
| 6 | |
| 7 | protected function configure(): void { |
| 8 | $this->id = 'latepoint/delete-booking'; |
| 9 | $this->label = __( 'Delete booking', 'latepoint' ); |
| 10 | $this->description = __( 'Permanently deletes a booking record from the database. This cannot be undone. Use cancel-booking to preserve the record instead.', 'latepoint' ); |
| 11 | $this->permission = 'booking__delete'; |
| 12 | $this->read_only = false; |
| 13 | $this->destructive = true; |
| 14 | $this->idempotent = false; |
| 15 | } |
| 16 | |
| 17 | public function get_input_schema(): array { |
| 18 | return [ |
| 19 | 'type' => 'object', |
| 20 | 'properties' => [ |
| 21 | 'id' => [ |
| 22 | 'type' => 'integer', |
| 23 | 'description' => __( 'Booking ID to delete.', 'latepoint' ), |
| 24 | ], |
| 25 | ], |
| 26 | 'required' => [ 'id' ], |
| 27 | ]; |
| 28 | } |
| 29 | |
| 30 | public function get_output_schema(): array { |
| 31 | return [ |
| 32 | 'type' => 'object', |
| 33 | 'properties' => [ |
| 34 | 'deleted' => [ 'type' => 'boolean' ], |
| 35 | 'id' => [ 'type' => 'integer' ], |
| 36 | ], |
| 37 | ]; |
| 38 | } |
| 39 | |
| 40 | public function execute( array $args ) { |
| 41 | $booking = new OsBookingModel( (int) $args['id'] ); |
| 42 | if ( $booking->is_new_record() ) { |
| 43 | return new WP_Error( 'not_found', __( 'Booking not found.', 'latepoint' ), [ 'status' => 404 ] ); |
| 44 | } |
| 45 | $auth = $this->authorize_record( $booking, 'delete' ); |
| 46 | if ( is_wp_error( $auth ) ) { |
| 47 | return $auth; |
| 48 | } |
| 49 | |
| 50 | $id = (int) $booking->id; |
| 51 | if ( ! $booking->delete() ) { |
| 52 | return new WP_Error( 'delete_failed', __( 'Failed to delete booking.', 'latepoint' ), [ 'status' => 500 ] ); |
| 53 | } |
| 54 | |
| 55 | return [ |
| 56 | 'deleted' => true, |
| 57 | 'id' => $id, |
| 58 | ]; |
| 59 | } |
| 60 | } |
| 61 |