b4400a68e5
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
147 lines
4.3 KiB
PHP
147 lines
4.3 KiB
PHP
<?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 )
|