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
133 lines
3.4 KiB
PHP
133 lines
3.4 KiB
PHP
<?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)
|
|
* stored in comment columns only — no comment meta to flatten.
|
|
* (The adapter used to mirror offers into `wpdo_comment_hp_offer`,
|
|
* a table nothing ever created.)
|
|
*
|
|
* @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';
|
|
|
|
/**
|
|
* 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,
|
|
),
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Doctor probe — request hot 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 . 'wpdo_hot_hp_request';
|
|
try {
|
|
$exists = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
|
|
return array(
|
|
'ok' => $exists,
|
|
'message' => $exists
|
|
? sprintf( 'hivepress-requests: %s present', $table )
|
|
: sprintf( 'hivepress-requests: %s missing', $table ),
|
|
);
|
|
} catch ( \Throwable $e ) {
|
|
return array(
|
|
'ok' => false,
|
|
'message' => sprintf( 'hivepress-requests doctor failed: %s', $e->getMessage() ),
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* FSM modules this adapter contributes.
|
|
*
|
|
* @return array<int,string>
|
|
*/
|
|
public function migrations(): array {
|
|
return array( 'hot_hp_request' );
|
|
}
|
|
}
|
|
|
|
} // end if ( ! class_exists )
|