prefix . ( self::$legacy ? 'asb_' : 'abece_booking_' ) . $logical; } /** * Return every logical-to-physical mapping, in immutable registry order. * * @param \wpdb $wpdb Site database connection. * @return array */ public static function all( \wpdb $wpdb ): array { $names = array(); foreach ( self::LOGICAL as $logical ) { $names[ $logical ] = self::name( $wpdb, $logical ); } return $names; } /** * Explicit historical names for preflight and the versioned transition only. * * @param \wpdb $wpdb Site database connection. * @return array */ public static function legacy( \wpdb $wpdb ): array { return self::historical( static fn() => self::all( $wpdb ) ); } /** * Scope immutable migrations 1–12 without making runtime reads ambiguous. * * @param callable $operation Historical migration operation. * @return mixed */ public static function historical( callable $operation ): mixed { $previous = self::$legacy; self::$legacy = true; try { return $operation(); } finally { self::$legacy = $previous; } } /** * Reject long prefixes before creating or renaming any table. * * @param \wpdb $wpdb Site database connection. * @return void */ public static function validate_prefix( \wpdb $wpdb ): void { if ( ! preg_match( '/^[A-Za-z0-9_]+$/D', $wpdb->prefix ) || strlen( $wpdb->prefix ) > 29 ) { throw new RuntimeException( __( 'ABeCe Booking requires a WordPress database prefix of at most 29 letters, digits or underscores. No tables were renamed.', 'abece-booking' ) ); } } /** * Database/site-specific lock names with a bounded MySQL identifier length. * * @param \wpdb $wpdb Site database connection. * @param string $scope Fixed application lock scope. * @param string $identity Optional typed customer or operation identity. * @return string */ public static function lock( \wpdb $wpdb, string $scope, string $identity = '' ): string { if ( ! in_array( $scope, array( 'schema', 'resources', 'prices', 'season', 'member_link', 'privacy', 'customer', 'geocoding', 'page' ), true ) ) { throw new InvalidArgumentException( 'Unknown ABeCe Booking lock scope.' ); } return 'abece_booking_' . $scope . '_' . substr( hash( 'sha256', DB_NAME . ':' . $wpdb->prefix . ':' . $identity ), 0, 32 ); } }