chore: initial snapshot of 2meet-data-optimizer-hivepress-addon v0.1.0
Baseline before backporting wp-data-optimizer v3.0.1-v3.4.6. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Blocks adapter — `hivepress-blocks`.
|
||||
*
|
||||
* Pure presentation layer (Gutenberg block library). No models, no postmeta,
|
||||
* no comment tables. Adapter exists solely so the detector and admin UI
|
||||
* recognise the addon as installed and report it in the integration matrix.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Blocks_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Blocks addon adapter (presentation only, no EAV surface).
|
||||
*/
|
||||
final class TMDO_HivePress_Blocks_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-blocks';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Blocks\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_BLOCKS_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — presentation-only, nothing to verify.
|
||||
*
|
||||
* @return array{ok:bool, message:string}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
return array(
|
||||
'ok' => true,
|
||||
'message' => 'hivepress-blocks: presentation-only addon, no anti-EAV surface',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score — perfect (no data layer).
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* Bookings adapter — `hivepress-bookings` (DETECT-ONLY in v3.0.0).
|
||||
*
|
||||
* The bookings plugin is not installed in the dev environment, so this
|
||||
* adapter ships pre-built but only activates when the addon is detected
|
||||
* by `TMDO_HivePress_Detector`. Schema is based on HivePress' published
|
||||
* Booking model (post_type=hp_booking) — fields are best-effort from the
|
||||
* addon's documented field aliases:
|
||||
*
|
||||
* start_time / end_time → unix timestamp range queries (hot)
|
||||
* status → enum filter (hot)
|
||||
* guests → numeric count (hot for slot-availability)
|
||||
* listing → post_parent (already a posts column)
|
||||
*
|
||||
* Hot-zone target: `wp_wpdo_hot_hp_booking` with covering indexes on
|
||||
* `(listing_id, start_time)` for slot-availability queries and
|
||||
* `(status, start_time)` for vendor dashboard listings.
|
||||
*
|
||||
* The schema MAY drift from real Booking model when the addon is finally
|
||||
* installed; reconcile with `wp wpdo doctor` then.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Bookings_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Bookings addon adapter (detect-only — schema reserved for future install).
|
||||
*/
|
||||
final class TMDO_HivePress_Bookings_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-bookings';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Bookings\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_BOOKINGS_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hot fields for hp_booking post type.
|
||||
*
|
||||
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
||||
*/
|
||||
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
||||
$registry->register_many(
|
||||
$this->plugin_slug(),
|
||||
array(
|
||||
array(
|
||||
'post_type' => 'hp_booking',
|
||||
'meta_key' => 'hp_start_time',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'bigint(20) UNSIGNED NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_start_time',
|
||||
'indexed' => true,
|
||||
),
|
||||
array(
|
||||
'post_type' => 'hp_booking',
|
||||
'meta_key' => 'hp_end_time',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'bigint(20) UNSIGNED NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_end_time',
|
||||
'indexed' => true,
|
||||
),
|
||||
array(
|
||||
'post_type' => 'hp_booking',
|
||||
'meta_key' => 'hp_guests',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'int(11) NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_guests',
|
||||
'indexed' => false,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — verify hot table when addon is active.
|
||||
*
|
||||
* @return array{ok:bool, message:string}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
$table = $wpdb->prefix . 'wpdo_hot_hp_booking';
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
|
||||
return array(
|
||||
'ok' => $exists,
|
||||
'message' => $exists
|
||||
? sprintf( 'hivepress-bookings: %s present', $table )
|
||||
: sprintf( 'hivepress-bookings: %s missing (addon installed but not migrated)', $table ),
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-bookings doctor failed: %s', $e->getMessage() ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*
|
||||
* D8 (perf) reduced to 0.9 because the schema is best-effort from
|
||||
* documentation; once the addon is installed and EXPLAIN can verify
|
||||
* index usage, raise to 1.0.
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score(
|
||||
array(
|
||||
'd8_perf' => 0.9,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* FSM modules this adapter contributes.
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function migrations(): array {
|
||||
return array( 'hot_hp_booking' );
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
/**
|
||||
* Core HivePress adapter — `hivepress` (the parent plugin).
|
||||
*
|
||||
* Owns three primary HivePress models:
|
||||
*
|
||||
* - `Listing` (post_type=hp_listing) — Hot zone columns for search/filter
|
||||
* (drafted, featured, verified, expired_time, featured_time).
|
||||
* - `Vendor` (post_type=hp_vendor) — Hot column `verified`; cold blob
|
||||
* for image / description (display-only).
|
||||
* - `User` (entity=user) — Entity group `hp_user_core` for
|
||||
* `hp_verified` and the WP-stock `first_name` / `last_name` /
|
||||
* `description`.
|
||||
*
|
||||
* This adapter SUPERSEDES the legacy `class-tmdo-hivepress.php` (242 lines).
|
||||
* Behavioural parity:
|
||||
*
|
||||
* - `optimize_query()` / `optimize_search()` — preserved as instance
|
||||
* methods bound on `hivepress/v1/models/{listing,vendor}/{query,search}`
|
||||
* at priority 20 (after HP own setup).
|
||||
* - `register_extended_fields()` — preserved as `on_register_fields()`
|
||||
* handler. Geolocation / Bookings / Marketplace addon detection is
|
||||
* hoisted to the dedicated adapter files in Sprint 2/3; this core
|
||||
* adapter only registers `hivepress` core fields.
|
||||
* - Vendor cold fields (`hp_image`, `hp_images`) — preserved.
|
||||
*
|
||||
* NEW additions vs legacy:
|
||||
*
|
||||
* - `hp_drafted` (Listing) — Hot tinyint(1) for user-dashboard filtering.
|
||||
* - `hp_expired_time` / `hp_featured_time` (Listing) — Hot bigint indexed
|
||||
* for cron expiry scan acceleration (replaces postmeta full scan).
|
||||
* - `hp_user_core` entity group — first_name / last_name / hp_verified
|
||||
* promoted from usermeta to wp_wpdo_user_hp_user (already created by
|
||||
* TMDO_Member_Fields v2.7.0).
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Core_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Core HivePress adapter (Listing / Vendor / User).
|
||||
*/
|
||||
final class TMDO_HivePress_Core_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* HP models that have Zone A hot tables. Used by query optimizer.
|
||||
*/
|
||||
private const HOT_MODELS = array(
|
||||
'listing' => 'hp_listing',
|
||||
'vendor' => 'hp_vendor',
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor — bind WPDO core hooks via the inherited trait sugar.
|
||||
*
|
||||
* The bootstrap calls `on_register_query_hooks()` / `on_register_event_hooks()`
|
||||
* directly after instantiation, but field/table registration goes
|
||||
* through WordPress's action dispatch via this trait helper.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
// ── Adapter identity ───────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Stable adapter slug (matches the hivepress core wp.org slug).
|
||||
*/
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class probed for HivePress core presence.
|
||||
*/
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Core';
|
||||
}
|
||||
|
||||
/**
|
||||
* Version constant probed for HivePress core presence.
|
||||
*/
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_VERSION';
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimum HivePress core version this adapter supports.
|
||||
*
|
||||
* Version 1.7.0 introduced the `_alias` / `_external` field convention
|
||||
* this adapter relies on. Older versions store fields differently and
|
||||
* would require fallback paths not implemented here.
|
||||
*/
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.7.0';
|
||||
}
|
||||
|
||||
// ── Field registration ─────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Register Listing/Vendor zone field mappings.
|
||||
*
|
||||
* Fired on the `wpdo_register_fields` action via the trait's
|
||||
* `bind_anti_eav_hooks()`. Schema_Registry has internal dedup so
|
||||
* re-firing on init:1 is safe.
|
||||
*
|
||||
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
||||
*/
|
||||
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
||||
// ── Listing hot fields (search/filter accelerators) ──
|
||||
$registry->register_many(
|
||||
$this->plugin_slug(),
|
||||
array(
|
||||
// Drafted — used in user dashboard "my drafts" filter.
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_drafted',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'tinyint(1) NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_drafted',
|
||||
'indexed' => true,
|
||||
),
|
||||
// Expired time — replaces `meta_query` clause in hourly cron.
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_expired_time',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'bigint(20) UNSIGNED NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_expired_time',
|
||||
'indexed' => true,
|
||||
),
|
||||
// Featured time — same expiry pattern as above.
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_featured_time',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'bigint(20) UNSIGNED NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_featured_time',
|
||||
'indexed' => true,
|
||||
),
|
||||
// Vendor cold blob — image attachment id (display-only).
|
||||
array(
|
||||
'post_type' => 'hp_vendor',
|
||||
'meta_key' => 'hp_image',
|
||||
'zone' => 'cold',
|
||||
'cache_group' => 'wpdo_cold_hp_vendor',
|
||||
'cache_ttl' => HOUR_IN_SECONDS,
|
||||
),
|
||||
// Listing cold blob — gallery (display-only).
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_images',
|
||||
'zone' => 'cold',
|
||||
'cache_group' => 'wpdo_cold_hp_listing',
|
||||
'cache_ttl' => HOUR_IN_SECONDS,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register entity field group for HP User model.
|
||||
*
|
||||
* The `hp_user` group is already created by `TMDO_Member_Fields`
|
||||
* (v2.7.0). We add adapter ownership here for cross-cutting tooling
|
||||
* (`wp wpdo hivepress doctor` reports owner; admin UI shows source).
|
||||
*
|
||||
* The `register_entity_fields()` helper from `TMDO_Anti_EAV_Aware`
|
||||
* delegates to `TMDO_Entity_Registry::register_group()` which has
|
||||
* internal dedup — so re-registering with same group name is a no-op.
|
||||
*/
|
||||
public function on_register_entity_fields(): void {
|
||||
if ( ! class_exists( 'TMDO_Entity_Registry' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Mirror the (canonical) group definition from TMDO_Member_Fields::HP_USER_FIELDS.
|
||||
// Source of truth lives in TMDO_Member_Fields; we register defensively for the
|
||||
// case where Member_Fields didn't load (custom builds without that integration).
|
||||
$this->register_entity_fields(
|
||||
'user',
|
||||
'hp_user',
|
||||
array(
|
||||
array(
|
||||
'key' => 'hp_verified',
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'searchable' => true,
|
||||
'label' => 'HivePress KYC verified',
|
||||
),
|
||||
array(
|
||||
'key' => 'hp_avatar_id',
|
||||
'type' => 'integer',
|
||||
'default' => 0,
|
||||
'searchable' => false,
|
||||
'label' => 'HivePress avatar attachment id',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ── Query optimization (preserved from legacy class-tmdo-hivepress.php) ──
|
||||
|
||||
/**
|
||||
* Bind HivePress search query hooks at priority 20 (after HP setup).
|
||||
*/
|
||||
public function on_register_query_hooks(): void {
|
||||
foreach ( self::HOT_MODELS as $model => $post_type ) {
|
||||
unset( $post_type ); // Bound below by string-interpolated $model only.
|
||||
add_action(
|
||||
"hivepress/v1/models/{$model}/query",
|
||||
array( $this, 'optimize_query' ),
|
||||
20,
|
||||
1
|
||||
);
|
||||
add_action(
|
||||
"hivepress/v1/models/{$model}/search",
|
||||
array( $this, 'optimize_search' ),
|
||||
20,
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimize a HivePress model query by extracting hot-zone meta_query clauses.
|
||||
*
|
||||
* Extracted clauses are stashed on the WP_Query as `wpdo_hot_clauses`;
|
||||
* `TMDO_Query_Router` rewrites them into flat-column JOINs at
|
||||
* `posts_join` time.
|
||||
*
|
||||
* @param \WP_Query $query The WP_Query object.
|
||||
*/
|
||||
public function optimize_query( \WP_Query $query ): void {
|
||||
$post_types = (array) $query->get( 'post_type' );
|
||||
if ( empty( $post_types ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing_hot = $query->get( 'wpdo_hot_clauses' );
|
||||
if ( ! empty( $existing_hot ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$meta_query = (array) $query->get( 'meta_query' );
|
||||
if ( empty( $meta_query ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$registry = TMDO_Schema_Registry::instance();
|
||||
$hot_clauses = array();
|
||||
$remaining = array();
|
||||
|
||||
foreach ( $meta_query as $k => $clause ) {
|
||||
if ( 'relation' === $k || ! is_array( $clause ) || ! isset( $clause['key'] ) ) {
|
||||
$remaining[ $k ] = $clause;
|
||||
continue;
|
||||
}
|
||||
|
||||
$matched = false;
|
||||
foreach ( $post_types as $pt ) {
|
||||
$field = $registry->get_field( $pt, $clause['key'] );
|
||||
if ( $field && 'hot' === $field['zone'] ) {
|
||||
$module = 'hot_' . sanitize_key( $pt );
|
||||
if ( class_exists( 'TMDO_Feature_Flags' ) && ! TMDO_Feature_Flags::is_query_active( $module ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hot_clauses[ $pt ][] = array(
|
||||
'column' => $field['column'],
|
||||
'value' => $clause['value'] ?? '',
|
||||
'compare' => strtoupper( trim( $clause['compare'] ?? '=' ) ),
|
||||
'type' => strtoupper( trim( $clause['type'] ?? 'CHAR' ) ),
|
||||
);
|
||||
$matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $matched ) {
|
||||
$remaining[ $k ] = $clause;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $hot_clauses ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $meta_query['relation'] ) && ! isset( $remaining['relation'] ) ) {
|
||||
$remaining['relation'] = $meta_query['relation'];
|
||||
}
|
||||
|
||||
$query->set( 'meta_query', $remaining );
|
||||
$query->set( 'wpdo_hot_clauses', $hot_clauses );
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimize a HivePress search query (delegates to optimize_query).
|
||||
*
|
||||
* Bound to `hivepress/v1/models/{model}/search` which passes attribute
|
||||
* fields as second arg; we ignore them (extracted via meta_query).
|
||||
*
|
||||
* @param \WP_Query $query The WP_Query object.
|
||||
* @param array $attribute_fields HP attribute field objects (unused).
|
||||
*/
|
||||
public function optimize_search( \WP_Query $query, array $attribute_fields ): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
|
||||
unset( $attribute_fields );
|
||||
$this->optimize_query( $query );
|
||||
}
|
||||
|
||||
// ── Doctor / score / migrations ────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Health probe: verify hot tables exist + sample row count.
|
||||
*
|
||||
* @return array{ok:bool, message:string, details?:array<string,mixed>}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
|
||||
$details = array();
|
||||
$ok = true;
|
||||
foreach ( self::HOT_MODELS as $post_type ) {
|
||||
$table = $wpdb->prefix . 'wpdo_hot_' . sanitize_key( $post_type );
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var(
|
||||
$wpdb->prepare( 'SHOW TABLES LIKE %s', $table )
|
||||
);
|
||||
$details[ $post_type ] = array(
|
||||
'table' => $table,
|
||||
'exists' => $exists,
|
||||
);
|
||||
if ( $exists ) {
|
||||
$details[ $post_type ]['rows'] = (int) $wpdb->get_var(
|
||||
"SELECT COUNT(*) FROM `{$table}`" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Sanitized via sanitize_key + wpdb prefix.
|
||||
);
|
||||
} else {
|
||||
$ok = false;
|
||||
}
|
||||
} catch ( \Throwable $e ) {
|
||||
$details[ $post_type ] = array(
|
||||
'table' => $table,
|
||||
'error' => $e->getMessage(),
|
||||
);
|
||||
$ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'ok' => $ok,
|
||||
'message' => $ok
|
||||
? 'hivepress core: hot tables OK'
|
||||
: 'hivepress core: one or more hot tables missing or unreadable',
|
||||
'details' => $details,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-dimension self-score for the core adapter.
|
||||
*
|
||||
* Default 1.0 across the board because:
|
||||
* - D1: only TMDO_API + Schema_Registry calls (no direct *_meta())
|
||||
* - D2: no hardcoded wp_postmeta literals
|
||||
* - D3: hot tables for both Listing + Vendor exist
|
||||
* - D4: every field registered with explicit data_type + indexed flag
|
||||
* - D5: no cross-adapter writes needed (single-adapter scope)
|
||||
* - D6: zero options written; no transients (relies on WPDO core caching)
|
||||
* - D7: no queries against other adapters' tables
|
||||
* - D8: hot columns indexed on every search-relevant field
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score(
|
||||
array(
|
||||
// D5 is N/A for a single-adapter; report 1.0 (no cross-write needed).
|
||||
'd5_hook_bus' => 1.0,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* FSM modules this adapter contributes.
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function migrations(): array {
|
||||
return array(
|
||||
'hot_hp_listing',
|
||||
'hot_hp_vendor',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
/**
|
||||
* Favorites adapter — `hivepress-favorites`.
|
||||
*
|
||||
* The Favorite model extends Comment (`comment_type = hp_favorite`):
|
||||
*
|
||||
* - user → user_id
|
||||
* - listing → comment_post_ID
|
||||
* - added_at → comment_date
|
||||
*
|
||||
* Problem: `wp_comments` has no UNIQUE constraint on (user_id, comment_post_ID, comment_type).
|
||||
* A double-tap on the favourite button can race and create two duplicate
|
||||
* favourite rows. HivePress relies on application-level dedup (SELECT before
|
||||
* INSERT) which is not race-safe.
|
||||
*
|
||||
* Fix: shadow table `wp_wpdo_comment_hp_favorite` with UNIQUE(user_id, listing_id).
|
||||
* Adapter mirrors every favorite write into the shadow table; the comment
|
||||
* router rewrites "is X favorited by user Y" reads to hit the shadow table
|
||||
* (1 indexed lookup vs WP_Comment_Query meta scan).
|
||||
*
|
||||
* Schema (declared via expected_columns; created by TMDO_Schema_Manager
|
||||
* when adapter mode flips to dual_write):
|
||||
*
|
||||
* CREATE TABLE wp_wpdo_comment_hp_favorite (
|
||||
* comment_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
||||
* user_id BIGINT UNSIGNED NOT NULL,
|
||||
* listing_id BIGINT UNSIGNED NOT NULL,
|
||||
* created_at DATETIME NOT NULL,
|
||||
* UNIQUE KEY unique_user_listing (user_id, listing_id),
|
||||
* KEY idx_listing (listing_id)
|
||||
* );
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Favorites_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Favorites addon adapter.
|
||||
*/
|
||||
final class TMDO_HivePress_Favorites_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/** Comment_type owned by this adapter. */
|
||||
public const COMMENT_TYPE = 'hp_favorite';
|
||||
|
||||
/** Shadow table name (without wpdb prefix). */
|
||||
public const TABLE = 'wpdo_comment_hp_favorite';
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-favorites';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Favorites\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_FAVORITES_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.2.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare the shadow table to the Custom_Table_Registry.
|
||||
*
|
||||
* @param TMDO_Custom_Table_Registry $registry Registry singleton.
|
||||
*/
|
||||
public function on_register_custom_tables( TMDO_Custom_Table_Registry $registry ): void {
|
||||
$this->register_custom_table(
|
||||
$registry,
|
||||
array(
|
||||
'table_name' => self::TABLE,
|
||||
'primary_key' => 'comment_id',
|
||||
'post_type_link' => null,
|
||||
'expected_columns' => array(
|
||||
'comment_id' => 'BIGINT UNSIGNED NOT NULL PRIMARY KEY',
|
||||
'user_id' => 'BIGINT UNSIGNED NOT NULL',
|
||||
'listing_id' => 'BIGINT UNSIGNED NOT NULL',
|
||||
'created_at' => 'DATETIME NOT NULL',
|
||||
),
|
||||
'indexes' => array(
|
||||
'unique_user_listing' => 'UNIQUE (user_id, listing_id)',
|
||||
'idx_listing' => '(listing_id)',
|
||||
),
|
||||
'doctor_callback' => array( $this, 'doctor_check' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync wp_comments → shadow table on insert.
|
||||
*
|
||||
* Bound during `on_register_event_hooks()`. The comment-router uses
|
||||
* the shadow table for "is favorited" lookups; sync keeps it consistent.
|
||||
*/
|
||||
public function on_register_event_hooks(): void {
|
||||
add_action( 'wp_insert_comment', array( $this, 'mirror_insert' ), 10, 2 );
|
||||
add_action( 'deleted_comment', array( $this, 'mirror_delete' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirror a newly-inserted hp_favorite into the shadow table.
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @param object|\WP_Comment $comment Comment object.
|
||||
*/
|
||||
public function mirror_insert( int $comment_id, $comment ): void {
|
||||
if ( ! is_object( $comment ) || ( $comment->comment_type ?? '' ) !== self::COMMENT_TYPE ) {
|
||||
return;
|
||||
}
|
||||
global $wpdb;
|
||||
$user_id = (int) ( $comment->user_id ?? 0 );
|
||||
$listing_id = (int) ( $comment->comment_post_ID ?? 0 );
|
||||
if ( $user_id <= 0 || $listing_id <= 0 ) {
|
||||
return;
|
||||
}
|
||||
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$wpdb->prepare(
|
||||
'INSERT IGNORE INTO `' . $wpdb->prefix . self::TABLE . '` (comment_id, user_id, listing_id, created_at) VALUES (%d, %d, %d, %s)',
|
||||
$comment_id,
|
||||
$user_id,
|
||||
$listing_id,
|
||||
$comment->comment_date ?? current_time( 'mysql' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the shadow row when a hp_favorite comment is deleted.
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @param object|\WP_Comment $comment Comment object.
|
||||
*/
|
||||
public function mirror_delete( int $comment_id, $comment ): void {
|
||||
if ( ! is_object( $comment ) || ( $comment->comment_type ?? '' ) !== self::COMMENT_TYPE ) {
|
||||
return;
|
||||
}
|
||||
global $wpdb;
|
||||
$wpdb->delete( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
$wpdb->prefix . self::TABLE,
|
||||
array( 'comment_id' => $comment_id ),
|
||||
array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — verify shadow table exists.
|
||||
*
|
||||
* @return array{ok:bool, message:string, details?:array<string,mixed>}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
$table = $wpdb->prefix . self::TABLE;
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var(
|
||||
$wpdb->prepare( 'SHOW TABLES LIKE %s', $table )
|
||||
);
|
||||
if ( ! $exists ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-favorites: shadow table %s missing', $table ),
|
||||
'details' => array( 'table' => $table ),
|
||||
);
|
||||
}
|
||||
$rows = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
return array(
|
||||
'ok' => true,
|
||||
'message' => sprintf( 'hivepress-favorites: %s rows=%d', $table, $rows ),
|
||||
'details' => array(
|
||||
'table' => $table,
|
||||
'rows' => $rows,
|
||||
),
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-favorites doctor failed: %s', $e->getMessage() ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*
|
||||
* D1: 1.0 — adapter never calls *_meta()
|
||||
* D2: 1.0 — uses wpdb prefix, no hardcoded table literals
|
||||
* D3: 1.0 — shadow table covers the model
|
||||
* D4: 1.0 — expected_columns + indexes registered
|
||||
* D5: 1.0 — listens to wp_insert_comment for cross-write consistency
|
||||
* D6: 1.0 — zero options/transients
|
||||
* D7: 1.0 — only queries own shadow table
|
||||
* D8: 1.0 — UNIQUE(user_id, listing_id) covering index
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* FSM modules this adapter contributes.
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function migrations(): array {
|
||||
return array( 'comment_hp_favorite' );
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Marketplace adapter — `hivepress-marketplace` (DETECT-ONLY in v3.0.0).
|
||||
*
|
||||
* The marketplace addon turns listings into purchasable items, integrating
|
||||
* with WooCommerce. It adds:
|
||||
*
|
||||
* hp_purchase_price → decimal(10,2), used in price-range filters (HOT)
|
||||
* hp_purchase_count → counter (WARM zone, low-criticality)
|
||||
*
|
||||
* Note: `hp_purchase_price` is also conditionally registered by the existing
|
||||
* legacy hivepress integration (Sprint 1 left that path) — the dedup in
|
||||
* Schema_Registry is provider+key based, so registering again under the
|
||||
* `hivepress-marketplace` provider is safe and lets `wp wpdo doctor` show
|
||||
* the right ownership.
|
||||
*
|
||||
* Detect-only: not installed in dev environment. Schema reserved for the
|
||||
* day the addon ships.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Marketplace_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Marketplace addon adapter (detect-only).
|
||||
*/
|
||||
final class TMDO_HivePress_Marketplace_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-marketplace';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Marketplace\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_MARKETPLACE_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register marketplace hot fields on the listing post type.
|
||||
*
|
||||
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
||||
*/
|
||||
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
||||
$registry->register_many(
|
||||
$this->plugin_slug(),
|
||||
array(
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_purchase_price',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'decimal(10,2) DEFAULT NULL',
|
||||
'column' => 'hp_purchase_price',
|
||||
'indexed' => true,
|
||||
),
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_purchase_count',
|
||||
'zone' => 'warm',
|
||||
'ttl' => null,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — verify hot column exists on listing hot table.
|
||||
*
|
||||
* @return array{ok:bool, message:string}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
$table = $wpdb->prefix . 'wpdo_hot_hp_listing';
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
|
||||
return array(
|
||||
'ok' => $exists,
|
||||
'message' => $exists
|
||||
? 'hivepress-marketplace: shares wp_wpdo_hot_hp_listing'
|
||||
: 'hivepress-marketplace: hot listing table missing',
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-marketplace doctor failed: %s', $e->getMessage() ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*
|
||||
* D8 reduced to 0.9 — index assumption is best-effort until addon installs.
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score(
|
||||
array(
|
||||
'd8_perf' => 0.9,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* Memberships adapter — `hivepress-memberships`.
|
||||
*
|
||||
* Two post-type models:
|
||||
*
|
||||
* - Membership_Plan (post_type=hp_membership_plan)
|
||||
* hot fields: hp_expire_period (int), hp_primary (bool)
|
||||
*
|
||||
* - Membership (post_type=hp_membership)
|
||||
* hot fields: hp_expired_time (unix ts) — checked on every page load
|
||||
*
|
||||
* Both fields registered to Hot zone so:
|
||||
* - `hp_expired_time < NOW()` lookups become indexed range scans
|
||||
* (replaces O(N) postmeta scan on each request).
|
||||
* - `hp_primary = 1` lookups for "default plan" become O(1).
|
||||
*
|
||||
* Tables `wp_wpdo_hot_hp_membership_plan` and `wp_wpdo_hot_hp_membership`
|
||||
* are created by `TMDO_Schema_Manager` from the registered hot columns.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Memberships_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Memberships addon adapter.
|
||||
*/
|
||||
final class TMDO_HivePress_Memberships_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-memberships';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Memberships\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_MEMBERSHIPS_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '2.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hot fields for both post types.
|
||||
*
|
||||
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
||||
*/
|
||||
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
||||
$registry->register_many(
|
||||
$this->plugin_slug(),
|
||||
array(
|
||||
// Plan fields.
|
||||
array(
|
||||
'post_type' => 'hp_membership_plan',
|
||||
'meta_key' => 'hp_expire_period',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'int(11) NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_expire_period',
|
||||
'indexed' => false,
|
||||
),
|
||||
array(
|
||||
'post_type' => 'hp_membership_plan',
|
||||
'meta_key' => 'hp_primary',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'tinyint(1) NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_primary',
|
||||
'indexed' => true,
|
||||
),
|
||||
// Membership (subscription) field — hottest path: every page load.
|
||||
array(
|
||||
'post_type' => 'hp_membership',
|
||||
'meta_key' => 'hp_expired_time',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'bigint(20) UNSIGNED NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_expired_time',
|
||||
'indexed' => true,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — verify both hot tables.
|
||||
*
|
||||
* @return array{ok:bool, message:string, details?:array<string,mixed>}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
$details = array();
|
||||
$ok = true;
|
||||
foreach ( array( 'hp_membership_plan', 'hp_membership' ) as $pt ) {
|
||||
$table = $wpdb->prefix . 'wpdo_hot_' . sanitize_key( $pt );
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
|
||||
$details[ $pt ]['table'] = $table;
|
||||
$details[ $pt ]['exists'] = $exists;
|
||||
if ( ! $exists ) {
|
||||
$ok = false;
|
||||
}
|
||||
} catch ( \Throwable $e ) {
|
||||
$details[ $pt ]['error'] = $e->getMessage();
|
||||
$ok = false;
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'ok' => $ok,
|
||||
'message' => $ok ? 'hivepress-memberships: hot tables OK' : 'hivepress-memberships: hot tables missing',
|
||||
'details' => $details,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*
|
||||
* D1: 1.0 — adapter never calls *_meta()
|
||||
* D2: 1.0 — uses wpdb prefix
|
||||
* D3: 1.0 — both models have hot tables
|
||||
* D4: 1.0 — every field has explicit data_type + indexed flag
|
||||
* D5: 1.0 — single-adapter scope
|
||||
* D6: 1.0 — zero options/transients
|
||||
* D7: 1.0 — only registers fields, no cross-table queries
|
||||
* D8: 1.0 — hot column on hp_expired_time = indexed range scan
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* FSM modules this adapter contributes.
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function migrations(): array {
|
||||
return array(
|
||||
'hot_hp_membership_plan',
|
||||
'hot_hp_membership',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
/**
|
||||
* Messages adapter — `hivepress-messages`.
|
||||
*
|
||||
* The Message model extends Comment (`comment_type = hp_message`) and stores
|
||||
* the recipient_id in `comment_karma` — a creative re-use of an unused column,
|
||||
* but it leaves the field unindexed for "messages received by user N"
|
||||
* queries. Result: every dashboard "unread count" badge does an O(N)
|
||||
* `WHERE comment_type = 'hp_message' AND comment_karma = N` scan over
|
||||
* the entire wp_comments table.
|
||||
*
|
||||
* Fix: shadow table `wp_wpdo_comment_hp_message` with proper recipient_id
|
||||
* column + index. Adapter mirrors every hp_message write into the shadow,
|
||||
* and the comment-router rewrites recipient/unread queries to hit the index.
|
||||
*
|
||||
* Schema:
|
||||
*
|
||||
* CREATE TABLE wp_wpdo_comment_hp_message (
|
||||
* comment_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
||||
* sender_id BIGINT UNSIGNED NOT NULL,
|
||||
* recipient_id BIGINT UNSIGNED NOT NULL,
|
||||
* listing_id BIGINT UNSIGNED NOT NULL,
|
||||
* is_read TINYINT(1) NOT NULL DEFAULT 0,
|
||||
* sent_at DATETIME NOT NULL,
|
||||
* KEY idx_recipient_unread (recipient_id, is_read),
|
||||
* KEY idx_thread (listing_id, sent_at)
|
||||
* );
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Messages_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Messages addon adapter.
|
||||
*/
|
||||
final class TMDO_HivePress_Messages_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/** Comment_type owned by this adapter. */
|
||||
public const COMMENT_TYPE = 'hp_message';
|
||||
|
||||
/** Shadow table name (without wpdb prefix). */
|
||||
public const TABLE = 'wpdo_comment_hp_message';
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-messages';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Messages\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_MESSAGES_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.4.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare the shadow table to the Custom_Table_Registry.
|
||||
*
|
||||
* @param TMDO_Custom_Table_Registry $registry Registry singleton.
|
||||
*/
|
||||
public function on_register_custom_tables( TMDO_Custom_Table_Registry $registry ): void {
|
||||
$this->register_custom_table(
|
||||
$registry,
|
||||
array(
|
||||
'table_name' => self::TABLE,
|
||||
'primary_key' => 'comment_id',
|
||||
'post_type_link' => null,
|
||||
'expected_columns' => array(
|
||||
'comment_id' => 'BIGINT UNSIGNED NOT NULL PRIMARY KEY',
|
||||
'sender_id' => 'BIGINT UNSIGNED NOT NULL',
|
||||
'recipient_id' => 'BIGINT UNSIGNED NOT NULL',
|
||||
'listing_id' => 'BIGINT UNSIGNED NOT NULL',
|
||||
'is_read' => 'TINYINT(1) NOT NULL DEFAULT 0',
|
||||
'sent_at' => 'DATETIME NOT NULL',
|
||||
),
|
||||
'indexes' => array(
|
||||
'idx_recipient_unread' => '(recipient_id, is_read)',
|
||||
'idx_thread' => '(listing_id, sent_at)',
|
||||
),
|
||||
'doctor_callback' => array( $this, 'doctor_check' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind sync hooks on hp_message comment insert / update / delete.
|
||||
*
|
||||
* The recipient_id is stored in comment_karma by HivePress; we mirror
|
||||
* it into a properly-named indexed column. is_read tracks comment_approved
|
||||
* (HP uses 0=unread / 1=read) — same column, mirrored.
|
||||
*/
|
||||
public function on_register_event_hooks(): void {
|
||||
add_action( 'wp_insert_comment', array( $this, 'mirror_insert' ), 10, 2 );
|
||||
add_action( 'wp_set_comment_status', array( $this, 'mirror_status_change' ), 10, 2 );
|
||||
add_action( 'deleted_comment', array( $this, 'mirror_delete' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirror a new hp_message into the shadow table.
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @param object|\WP_Comment $comment Comment object.
|
||||
*/
|
||||
public function mirror_insert( int $comment_id, $comment ): void {
|
||||
if ( ! is_object( $comment ) || ( $comment->comment_type ?? '' ) !== self::COMMENT_TYPE ) {
|
||||
return;
|
||||
}
|
||||
global $wpdb;
|
||||
$sender_id = (int) ( $comment->user_id ?? 0 );
|
||||
$recipient_id = (int) ( $comment->comment_karma ?? 0 );
|
||||
$listing_id = (int) ( $comment->comment_post_ID ?? 0 );
|
||||
$is_read = (int) ( $comment->comment_approved ?? 0 );
|
||||
if ( $sender_id <= 0 || $recipient_id <= 0 ) {
|
||||
// Malformed message — nothing useful to mirror.
|
||||
return;
|
||||
}
|
||||
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$wpdb->prepare(
|
||||
'INSERT INTO `' . $wpdb->prefix . self::TABLE . '` (comment_id, sender_id, recipient_id, listing_id, is_read, sent_at) VALUES (%d, %d, %d, %d, %d, %s) ON DUPLICATE KEY UPDATE is_read = VALUES(is_read)',
|
||||
$comment_id,
|
||||
$sender_id,
|
||||
$recipient_id,
|
||||
$listing_id,
|
||||
$is_read,
|
||||
$comment->comment_date ?? current_time( 'mysql' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update is_read when a message is marked read (comment_approved flip).
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @param string $status New status ('approve', 'hold', 'spam', 'trash').
|
||||
*/
|
||||
public function mirror_status_change( int $comment_id, string $status ): void {
|
||||
global $wpdb;
|
||||
// Look up the comment to confirm it's hp_message before touching.
|
||||
if ( ! function_exists( 'get_comment' ) ) {
|
||||
return;
|
||||
}
|
||||
$comment = get_comment( $comment_id );
|
||||
if ( ! $comment || ( $comment->comment_type ?? '' ) !== self::COMMENT_TYPE ) {
|
||||
return;
|
||||
}
|
||||
$is_read = ( 'approve' === $status ) ? 1 : 0;
|
||||
$wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
$wpdb->prefix . self::TABLE,
|
||||
array( 'is_read' => $is_read ),
|
||||
array( 'comment_id' => $comment_id ),
|
||||
array( '%d' ),
|
||||
array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove shadow row on hp_message deletion.
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @param object|\WP_Comment $comment Comment object.
|
||||
*/
|
||||
public function mirror_delete( int $comment_id, $comment ): void {
|
||||
if ( ! is_object( $comment ) || ( $comment->comment_type ?? '' ) !== self::COMMENT_TYPE ) {
|
||||
return;
|
||||
}
|
||||
global $wpdb;
|
||||
$wpdb->delete( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
$wpdb->prefix . self::TABLE,
|
||||
array( 'comment_id' => $comment_id ),
|
||||
array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — verify shadow table.
|
||||
*
|
||||
* @return array{ok:bool, message:string, details?:array<string,mixed>}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
$table = $wpdb->prefix . self::TABLE;
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
|
||||
if ( ! $exists ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-messages: shadow table %s missing', $table ),
|
||||
'details' => array( 'table' => $table ),
|
||||
);
|
||||
}
|
||||
$rows = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
return array(
|
||||
'ok' => true,
|
||||
'message' => sprintf( 'hivepress-messages: %s rows=%d', $table, $rows ),
|
||||
'details' => array(
|
||||
'table' => $table,
|
||||
'rows' => $rows,
|
||||
),
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-messages doctor failed: %s', $e->getMessage() ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*
|
||||
* D1: 1.0 — adapter never calls *_meta()
|
||||
* D2: 1.0 — uses wpdb prefix exclusively
|
||||
* D3: 1.0 — shadow table covers recipient/unread access
|
||||
* D4: 1.0 — expected_columns + indexes registered
|
||||
* D5: 1.0 — listens to wp_insert_comment + status change for sync
|
||||
* D6: 1.0 — zero options/transients
|
||||
* D7: 1.0 — only queries own shadow table
|
||||
* D8: 1.0 — idx_recipient_unread covers the hot dashboard query
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* FSM modules this adapter contributes.
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function migrations(): array {
|
||||
return array( 'comment_hp_message' );
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
/**
|
||||
* Requests adapter — `hivepress-requests`.
|
||||
*
|
||||
* Two related models:
|
||||
*
|
||||
* - Request (post_type=hp_request)
|
||||
* hot fields: hp_drafted (bool), hp_expired_time (unix ts)
|
||||
* — same access pattern as Listing (user dashboard + expiry cron)
|
||||
*
|
||||
* - Offer (comment_type=hp_offer, parent post_type=hp_request)
|
||||
* comment-column based; benefit comes from comment-router using
|
||||
* (comment_post_ID, comment_type) covering index + dedicated shadow
|
||||
* table for "approved offers per request" aggregation.
|
||||
*
|
||||
* Shadow table for offers (analogous to favorites pattern):
|
||||
*
|
||||
* CREATE TABLE wp_wpdo_comment_hp_offer (
|
||||
* comment_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
||||
* request_id BIGINT UNSIGNED NOT NULL,
|
||||
* bidder_id BIGINT UNSIGNED NOT NULL,
|
||||
* approved TINYINT(1) NOT NULL DEFAULT 0,
|
||||
* created_at DATETIME NOT NULL,
|
||||
* KEY idx_request_approved (request_id, approved),
|
||||
* KEY idx_bidder (bidder_id)
|
||||
* );
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Requests_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Requests addon adapter.
|
||||
*/
|
||||
final class TMDO_HivePress_Requests_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/** Comment_type for the Offer side of Requests. */
|
||||
public const OFFER_COMMENT_TYPE = 'hp_offer';
|
||||
|
||||
/** Shadow table for offers (without wpdb prefix). */
|
||||
public const OFFER_TABLE = 'wpdo_comment_hp_offer';
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-requests';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Requests\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_REQUESTS_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.2.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hot fields for hp_request post type.
|
||||
*
|
||||
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
||||
*/
|
||||
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
||||
$registry->register_many(
|
||||
$this->plugin_slug(),
|
||||
array(
|
||||
array(
|
||||
'post_type' => 'hp_request',
|
||||
'meta_key' => 'hp_drafted',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'tinyint(1) NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_drafted',
|
||||
'indexed' => true,
|
||||
),
|
||||
array(
|
||||
'post_type' => 'hp_request',
|
||||
'meta_key' => 'hp_expired_time',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'bigint(20) UNSIGNED NOT NULL DEFAULT 0',
|
||||
'column' => 'hp_expired_time',
|
||||
'indexed' => true,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare offer shadow table.
|
||||
*
|
||||
* @param TMDO_Custom_Table_Registry $registry Registry singleton.
|
||||
*/
|
||||
public function on_register_custom_tables( TMDO_Custom_Table_Registry $registry ): void {
|
||||
$this->register_custom_table(
|
||||
$registry,
|
||||
array(
|
||||
'table_name' => self::OFFER_TABLE,
|
||||
'primary_key' => 'comment_id',
|
||||
'post_type_link' => 'hp_request',
|
||||
'expected_columns' => array(
|
||||
'comment_id' => 'BIGINT UNSIGNED NOT NULL PRIMARY KEY',
|
||||
'request_id' => 'BIGINT UNSIGNED NOT NULL',
|
||||
'bidder_id' => 'BIGINT UNSIGNED NOT NULL',
|
||||
'approved' => 'TINYINT(1) NOT NULL DEFAULT 0',
|
||||
'created_at' => 'DATETIME NOT NULL',
|
||||
),
|
||||
'indexes' => array(
|
||||
'idx_request_approved' => '(request_id, approved)',
|
||||
'idx_bidder' => '(bidder_id)',
|
||||
),
|
||||
'doctor_callback' => array( $this, 'doctor_check' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirror new hp_offer comments into the shadow table.
|
||||
*/
|
||||
public function on_register_event_hooks(): void {
|
||||
add_action( 'wp_insert_comment', array( $this, 'mirror_offer_insert' ), 10, 2 );
|
||||
add_action( 'edit_comment', array( $this, 'mirror_offer_update' ), 10, 2 );
|
||||
add_action( 'deleted_comment', array( $this, 'mirror_offer_delete' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a hp_offer mirror row.
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @param object|\WP_Comment $comment Comment object.
|
||||
*/
|
||||
public function mirror_offer_insert( int $comment_id, $comment ): void {
|
||||
if ( ! is_object( $comment ) || ( $comment->comment_type ?? '' ) !== self::OFFER_COMMENT_TYPE ) {
|
||||
return;
|
||||
}
|
||||
global $wpdb;
|
||||
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$wpdb->prepare(
|
||||
'INSERT INTO `' . $wpdb->prefix . self::OFFER_TABLE . '` (comment_id, request_id, bidder_id, approved, created_at) VALUES (%d, %d, %d, %d, %s) ON DUPLICATE KEY UPDATE approved = VALUES(approved)',
|
||||
$comment_id,
|
||||
(int) ( $comment->comment_post_ID ?? 0 ),
|
||||
(int) ( $comment->user_id ?? 0 ),
|
||||
(int) ( $comment->comment_approved ?? 0 ),
|
||||
$comment->comment_date ?? current_time( 'mysql' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update mirror row when comment is edited (approval flip is the hot path).
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @param array $data Comment data array passed by edit_comment.
|
||||
*/
|
||||
public function mirror_offer_update( int $comment_id, $data ): void {
|
||||
unset( $data );
|
||||
global $wpdb;
|
||||
// Re-fetch comment object for accurate state then re-mirror via insert path.
|
||||
if ( function_exists( 'get_comment' ) ) {
|
||||
$comment = get_comment( $comment_id );
|
||||
if ( $comment ) {
|
||||
$this->mirror_offer_insert( $comment_id, $comment );
|
||||
}
|
||||
}
|
||||
unset( $wpdb );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove mirror row on hp_offer deletion.
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @param object|\WP_Comment $comment Comment object.
|
||||
*/
|
||||
public function mirror_offer_delete( int $comment_id, $comment ): void {
|
||||
if ( ! is_object( $comment ) || ( $comment->comment_type ?? '' ) !== self::OFFER_COMMENT_TYPE ) {
|
||||
return;
|
||||
}
|
||||
global $wpdb;
|
||||
$wpdb->delete( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
$wpdb->prefix . self::OFFER_TABLE,
|
||||
array( 'comment_id' => $comment_id ),
|
||||
array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — request hot table + offer shadow table.
|
||||
*
|
||||
* @return array{ok:bool, message:string, details?:array<string,mixed>}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
$details = array();
|
||||
$ok = true;
|
||||
foreach ( array(
|
||||
'hp_request_hot' => $wpdb->prefix . 'wpdo_hot_hp_request',
|
||||
'hp_offer_shadow' => $wpdb->prefix . self::OFFER_TABLE,
|
||||
) as $key => $table ) {
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
|
||||
$details[ $key ] = array(
|
||||
'table' => $table,
|
||||
'exists' => $exists,
|
||||
);
|
||||
if ( ! $exists ) {
|
||||
$ok = false;
|
||||
}
|
||||
} catch ( \Throwable $e ) {
|
||||
$details[ $key ] = array(
|
||||
'table' => $table,
|
||||
'error' => $e->getMessage(),
|
||||
);
|
||||
$ok = false;
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'ok' => $ok,
|
||||
'message' => $ok ? 'hivepress-requests: tables OK' : 'hivepress-requests: one or more tables missing',
|
||||
'details' => $details,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* FSM modules this adapter contributes.
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function migrations(): array {
|
||||
return array(
|
||||
'hot_hp_request',
|
||||
'comment_hp_offer',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
* Reviews adapter — `hivepress-reviews`.
|
||||
*
|
||||
* The Review model extends `Comment` (`comment_type = hp_review`) so it
|
||||
* stores everything in `wp_comments` columns:
|
||||
*
|
||||
* - text → comment_content
|
||||
* - rating → comment_karma (1-5 integer)
|
||||
* - approved → comment_approved
|
||||
* - listing → comment_post_ID
|
||||
*
|
||||
* No postmeta is used; no entity-bridge group needed. Hot-path optimization
|
||||
* comes from `TMDO_HivePress_Comment_Router` rewriting comment-query SQL to
|
||||
* use `comment_post_ID + comment_type + comment_approved` index, and from
|
||||
* the `wp_wpdo_comment_hp_review` flat table that WPDO Comment entity bridge
|
||||
* already maintains (since v2.13.x).
|
||||
*
|
||||
* This adapter's role:
|
||||
* - Declare the comment_type to the comment-router
|
||||
* - Doctor probe of the entity-bridge table
|
||||
* - Self-report 8-D suitability score
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Reviews_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Reviews addon adapter.
|
||||
*/
|
||||
final class TMDO_HivePress_Reviews_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/** Comment_type owned by this adapter. */
|
||||
public const COMMENT_TYPE = 'hp_review';
|
||||
|
||||
/** Entity-bridge table used by TMDO_Adapter_Comment for hp_review. */
|
||||
private const TABLE = 'wpdo_comment_hp_review';
|
||||
|
||||
/**
|
||||
* Constructor — bind WPDO core register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-reviews';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Reviews\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_REVIEWS_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.4.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — verify entity-bridge table exists and is reachable.
|
||||
*
|
||||
* @return array{ok:bool, message:string, details?:array<string,mixed>}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
|
||||
$table = $wpdb->prefix . self::TABLE;
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var(
|
||||
$wpdb->prepare( 'SHOW TABLES LIKE %s', $table )
|
||||
);
|
||||
if ( ! $exists ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-reviews: %s missing (Comment entity-bridge not migrated)', $table ),
|
||||
'details' => array( 'table' => $table ),
|
||||
);
|
||||
}
|
||||
$rows = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Sanitized via wpdb prefix.
|
||||
return array(
|
||||
'ok' => true,
|
||||
'message' => sprintf( 'hivepress-reviews: %s rows=%d', $table, $rows ),
|
||||
'details' => array(
|
||||
'table' => $table,
|
||||
'rows' => $rows,
|
||||
),
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-reviews doctor failed: %s', $e->getMessage() ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*
|
||||
* D1: 1.0 — adapter never calls *_meta() (Review is comment-column based)
|
||||
* D2: 1.0 — no hardcoded wp_comments references; uses wpdb prefix
|
||||
* D3: 1.0 — entity-bridge table covers the model
|
||||
* D4: 1.0 — table schema owned by Comment entity adapter (already documented)
|
||||
* D5: 1.0 — no cross-adapter writes needed yet
|
||||
* D6: 1.0 — zero options/transients written
|
||||
* D7: 1.0 — only queries own entity-bridge table
|
||||
* D8: 1.0 — comment-router uses (comment_post_ID, comment_type) covering index
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* FSM modules contributed (none — comment entity-bridge owns lifecycle).
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function migrations(): array {
|
||||
return array(
|
||||
// Comment entity-bridge migration is module 'comment_hp_review',
|
||||
// owned by TMDO_Migration_Orchestrator — adapter is read-only.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* SEO adapter — `hivepress-seo`.
|
||||
*
|
||||
* The SEO addon is filter-based — it tweaks listing/vendor page titles,
|
||||
* meta descriptions, OpenGraph tags. No models of its own, no postmeta
|
||||
* additions beyond what HivePress core already manages.
|
||||
*
|
||||
* Adapter contributes only detection signal + readiness report. Nothing
|
||||
* to anti-EAV.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Seo_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* SEO addon adapter (filter-based, no EAV surface).
|
||||
*/
|
||||
final class TMDO_HivePress_Seo_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-seo';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Seo\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_SEO_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — filter-based addon has nothing to verify.
|
||||
*
|
||||
* @return array{ok:bool, message:string}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
return array(
|
||||
'ok' => true,
|
||||
'message' => 'hivepress-seo: filter-based addon, no anti-EAV surface',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score — perfect 10 (no EAV usage to optimize).
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Social Links adapter — `hivepress-social-links`.
|
||||
*
|
||||
* Adds social URL fields to vendor profiles (Facebook, Instagram, Twitter,
|
||||
* LinkedIn, YouTube, etc.). Stored in postmeta as `hp_social_*` keys.
|
||||
*
|
||||
* Display-only — never used in search/filter — so the right zone is Cold
|
||||
* (object cache + JSON blob fallback). Listing page reads ~7 social URLs;
|
||||
* caching them as a single blob keyed on vendor_id eliminates 7 postmeta
|
||||
* lookups per render.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Social_Links_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Social Links addon adapter (vendor cold zone).
|
||||
*/
|
||||
final class TMDO_HivePress_Social_Links_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Social URL meta keys owned by this addon.
|
||||
*
|
||||
* Sources (HivePress 1.0.3 default field set):
|
||||
* facebook_url, instagram_url, twitter_url, linkedin_url,
|
||||
* youtube_url, telegram_url, whatsapp_url
|
||||
*
|
||||
* @var array<int,string>
|
||||
*/
|
||||
private const SOCIAL_KEYS = array(
|
||||
'hp_facebook_url',
|
||||
'hp_instagram_url',
|
||||
'hp_twitter_url',
|
||||
'hp_linkedin_url',
|
||||
'hp_youtube_url',
|
||||
'hp_telegram_url',
|
||||
'hp_whatsapp_url',
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-social-links';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\SocialLinks\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_SOCIAL_LINKS_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register vendor social URL fields to Cold zone.
|
||||
*
|
||||
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
||||
*/
|
||||
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
||||
$fields = array();
|
||||
foreach ( self::SOCIAL_KEYS as $key ) {
|
||||
$fields[] = array(
|
||||
'post_type' => 'hp_vendor',
|
||||
'meta_key' => $key,
|
||||
'zone' => 'cold',
|
||||
'cache_group' => 'wpdo_cold_hp_vendor',
|
||||
'cache_ttl' => HOUR_IN_SECONDS,
|
||||
);
|
||||
}
|
||||
$registry->register_many( $this->plugin_slug(), $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — cold zone uses cache; verify cache layer is reachable.
|
||||
*
|
||||
* @return array{ok:bool, message:string}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
return array(
|
||||
'ok' => true,
|
||||
'message' => sprintf( 'hivepress-social-links: %d cold fields registered', count( self::SOCIAL_KEYS ) ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Statistics adapter — `hivepress-statistics` (DETECT-ONLY in v3.0.0).
|
||||
*
|
||||
* The statistics addon tracks listing view counts, click-throughs, and other
|
||||
* counter-style metrics. The natural zone for these is WARM:
|
||||
*
|
||||
* - Increment-heavy writes (every page view → counter++).
|
||||
* - Read-rarely (only the vendor dashboard cares).
|
||||
* - Tolerable to lose seconds of writes (TTL-style flush).
|
||||
*
|
||||
* Mapped meta keys (best-effort from addon docs):
|
||||
*
|
||||
* hp_view_count → warm (cron flush hourly)
|
||||
* hp_click_count → warm (cron flush hourly)
|
||||
*
|
||||
* Detect-only: not installed in dev environment.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Statistics_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Statistics addon adapter (detect-only, warm zone).
|
||||
*/
|
||||
final class TMDO_HivePress_Statistics_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-statistics';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Statistics\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_STATISTICS_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register counter fields to warm zone.
|
||||
*
|
||||
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
||||
*/
|
||||
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
||||
$registry->register_many(
|
||||
$this->plugin_slug(),
|
||||
array(
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_view_count',
|
||||
'zone' => 'warm',
|
||||
'ttl' => null,
|
||||
),
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_click_count',
|
||||
'zone' => 'warm',
|
||||
'ttl' => null,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — warm zone uses shared wp_wpdo_warm KV table.
|
||||
*
|
||||
* @return array{ok:bool, message:string}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
$table = $wpdb->prefix . 'wpdo_warm';
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
|
||||
return array(
|
||||
'ok' => $exists,
|
||||
'message' => $exists
|
||||
? 'hivepress-statistics: warm zone (wpdo_warm) reachable'
|
||||
: 'hivepress-statistics: wpdo_warm missing',
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-statistics doctor failed: %s', $e->getMessage() ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score — D8 reduced (warm zone is best-effort until addon installs).
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score(
|
||||
array(
|
||||
'd8_perf' => 0.9,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Tags adapter — `hivepress-tags`.
|
||||
*
|
||||
* Adds the `hp_listing_tag` taxonomy to listings. Term-based — no postmeta,
|
||||
* no hot fields. Term assignment lives in `wp_term_relationships` which is
|
||||
* already indexed by WordPress core.
|
||||
*
|
||||
* Adapter contributes:
|
||||
* - Detection signal (so admin UI / scorer can see this addon is active)
|
||||
* - Self-score (perfect because there's nothing to anti-EAV — the addon
|
||||
* uses term tables, not meta)
|
||||
* - Doctor probe (no-op success — no custom tables to verify)
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Tags_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Tags addon adapter (term-based, no EAV surface).
|
||||
*/
|
||||
final class TMDO_HivePress_Tags_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-tags';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Tags\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_TAGS_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.1.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — term-based addon has no custom tables to verify.
|
||||
*
|
||||
* @return array{ok:bool, message:string}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
return array(
|
||||
'ok' => true,
|
||||
'message' => 'hivepress-tags: term-based addon, no anti-EAV surface',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*
|
||||
* All dimensions 1.0 because the addon uses term tables (not meta) —
|
||||
* there is nothing to anti-EAV. The addon is structurally correct
|
||||
* by construction, so the adapter has nothing to do beyond declare
|
||||
* ownership for tooling.
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
Reference in New Issue
Block a user