5777210184
- Favorites/Messages adapters reduced to detection only; Requests keeps hot_hp_request fields, drops hp_offer mirror - Delete TMDO_HivePress_Comment_Router (read path to wpdo_comment_hp_* tables that no installer creates) - Verify: addon unit 141 OK, integration 52 OK; phpcs 41E/57W → 35E/48W - PR: PR-013
145 lines
4.2 KiB
PHP
145 lines
4.2 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. Queries use the core
|
|
* `wp_comments` indexes on `comment_post_ID` / `comment_type`, and the
|
|
* `wp_wpdo_comment_hp_review` flat table is maintained by the WPDO Comment
|
|
* entity bridge (since v2.13.x).
|
|
*
|
|
* This adapter's role:
|
|
* - 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 — reads use the core wp_comments (comment_post_ID, comment_type) indexes
|
|
*/
|
|
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 )
|