← All changes
|
includes/page-form-builder/save-load/bfb-form-storage.php
+49
-6
11.1
→
11.9
View file →
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Storage of Booking form structure. |
| 4 | 4 | * |
| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | * booking_resource_id – nullable; if you bind a specific form to a particular booking resource (calendar). |
| 16 | 16 | * owner_user_id – nullable; owner of the form (MultiUser). |
| 17 | 17 | * |
| 18 | 18 | * Engine & payloads |
| 19 | - * engine – engine key: 'bfb', 'legacy_simple', 'legacy_advanced', etc. Default 'bfb'. | |
| 19 | + * engine – engine key: 'bfb' or 'advanced_mode'. Default 'bfb'. | |
| 20 | 20 | * engine_version – engine version, e.g. '1.0'. |
| 21 | 21 | * structure_json – canonical builder structure (pages -> sections -> columns -> fields). |
| 22 | 22 | * settings_json – extra non-structural options (CSS classes, theme/skin, internal flags, etc.). |
| 23 | 23 | * advanced_form – shortcodes / markup for booking form (optional). |
| @@ -239,9 +239,9 @@ | ||
| 239 | 239 | * @type int $booking_resource_id Optional booking resource ID. |
| 240 | 240 | * @type int $owner_user_id Optional owner ID (MultiUser). Backwards-compat: 'user_id'. |
| 241 | 241 | * @type int $is_default 1 if default, 0 otherwise. |
| 242 | 242 | * |
| 243 | - * @type string $engine Engine key: 'bfb', 'legacy_simple', 'legacy_advanced'. Default 'bfb'. | |
| 243 | + * @type string $engine Engine key: 'bfb' or 'advanced_mode'. Default 'bfb'. | |
| 244 | 244 | * @type string $engine_version Engine version. Default '1.0'. |
| 245 | 245 | * @type string $structure_json Canonical JSON structure (required). |
| 246 | 246 | * @type string $settings_json Optional JSON with extra settings. |
| 247 | 247 | * @type string $advanced_form Optional shortcodes string for booking form. |
| @@ -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 | +} | |