← All changes
|
includes/page-form-builder/save-load/bfb-form-storage.php
+47
-4
11.4.1
→
11.9
View file →
| @@ -249,9 +249,9 @@ | ||
| 249 | 249 | * @type string $picture_url Optional preview image URL. |
| 250 | 250 | * |
| 251 | 251 | * @return int|false Booking form ID or false on failure. |
| 252 | 252 | */ |
| 253 | - public static function save_form( $data ) { | |
| 253 | + public static function save_form( $data ) { | |
| 254 | 254 | global $wpdb; |
| 255 | 255 | |
| 256 | 256 | $now = current_time( 'mysql' ); |
| 257 | 257 | $current_id = wpbc_get_current_user_id(); |
| @@ -429,7 +429,50 @@ | ||
| 429 | 429 | |
| 430 | 430 | if ( false === $inserted ) { |
| 431 | 431 | return false; |
| 432 | 432 | } |
| 433 | - return intval( $wpdb->insert_id ); | |
| 434 | - } | |
| 435 | -} | |
| 433 | + return intval( $wpdb->insert_id ); | |
| 434 | + } | |
| 435 | + | |
| 436 | + /** | |
| 437 | + * Delete one newly created form only when its complete logical identity matches. | |
| 438 | + * | |
| 439 | + * This narrow compensation API is used by multi-domain setup operations after | |
| 440 | + * a later Service-assignment write fails. Existing forms are never deleted; | |
| 441 | + * callers must provide the exact inserted row ID, slug, status, and owner. | |
| 442 | + * | |
| 443 | + * @param int $booking_form_id Booking Form row ID created in this operation. | |
| 444 | + * @param string $form_slug Exact canonical form slug. | |
| 445 | + * @param string $status Exact canonical status. | |
| 446 | + * @param int $owner_user_id Exact canonical owner ID. | |
| 447 | + * | |
| 448 | + * @return bool True when exactly one matching row was deleted. | |
| 449 | + */ | |
| 450 | + public static function delete_form_if_matches( $booking_form_id, $form_slug, $status, $owner_user_id ) { | |
| 451 | + global $wpdb; | |
| 452 | + | |
| 453 | + $booking_form_id = absint( $booking_form_id ); | |
| 454 | + $form_slug = sanitize_title( (string) $form_slug ); | |
| 455 | + $status = sanitize_key( (string) $status ); | |
| 456 | + $owner_user_id = absint( $owner_user_id ); | |
| 457 | + if ( ! $booking_form_id || '' === $form_slug || '' === $status ) { | |
| 458 | + return false; | |
| 459 | + } | |
| 460 | + | |
| 461 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 462 | + $deleted = $wpdb->query( | |
| 463 | + $wpdb->prepare( | |
| 464 | + "DELETE FROM {$wpdb->prefix}booking_form_structures | |
| 465 | + WHERE booking_form_id = %d | |
| 466 | + AND form_slug = %s | |
| 467 | + AND status = %s | |
| 468 | + AND owner_user_id = %d", | |
| 469 | + $booking_form_id, | |
| 470 | + $form_slug, | |
| 471 | + $status, | |
| 472 | + $owner_user_id | |
| 473 | + ) | |
| 474 | + ); | |
| 475 | + | |
| 476 | + return 1 === (int) $deleted; | |
| 477 | + } | |
| 478 | +} | |