Snapshot: MLS sync fixes, image refresh, plugin/theme updates

MLS plugin fixes from this session:
- Fix silent insert failures: location column NOT NULL was rejecting wpdb->insert calls,
  causing ~18k new properties since Dec 2025 to be lost. Inserts now build raw SQL
  with ST_PointFromText so the spatial column is populated atomically.
- Auto-refresh expired media URLs in MLS_Media_Handler::fetch_and_cache(), guarded by
  a property-level GET_LOCK so concurrent fetches share one API refresh.
- Normalize WP_Error to null in mls_get_property_image() so callers can rely on the
  documented string|null contract.
- Support comma-separated property_type filters in MLS_Query and MLS_Cluster so the
  homepage "View All Commercial" link (?property_type=Commercial+Sale,Land,Farm)
  actually filters correctly.
- Incremental sync now looks back 10 minutes past the latest modification timestamp
  as a safety margin against missed records.
- Smart sync exits silently (info-level, not warning) when a full sync is in progress.

Operational:
- New cron: weekly full sync Sundays at 3 AM (/usr/local/bin/mls-full-sync).
- New cron: hourly 2GB cap on mls-thumbnails/ and cache/transformed-images/
  (/usr/local/bin/mls-image-cache-cap).
- Logrotate config for wp-content/debug.log (2-day retention, daily rotation,
  delaycompress).

Repo policy:
- CLAUDE.md updated with explicit "commit everything except build artifacts" policy.
- .gitignore: untrack runtime image caches and debug.log rotations.

Other modifications in this snapshot are pre-existing in-flight theme/plugin/db_content_updates work.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-04-29 15:32:23 +00:00
parent 57b752f54e
commit b6df4dbb92
5385 changed files with 838580 additions and 2416 deletions
@@ -13,7 +13,7 @@ class MLS_DB {
* Schema version for index migrations
* Increment this when adding new indexes or columns
*/
const SCHEMA_VERSION = 5;
const SCHEMA_VERSION = 6;
/**
* Get table name with prefix
@@ -82,6 +82,13 @@ class MLS_DB {
return $this->get_table_name(MLS_TABLE_GEO_ZIPCODES);
}
/**
* Get manual properties table name
*/
public function manual_properties_table() {
return $this->get_table_name(MLS_TABLE_MANUAL_PROPERTIES);
}
/**
* Create all database tables
*/
@@ -143,6 +150,7 @@ class MLS_DB {
is_homeproz TINYINT(1) NOT NULL DEFAULT 0,
photos_count INT(5) DEFAULT 0,
media_expires_at DATETIME DEFAULT NULL,
modification_timestamp DATETIME NOT NULL,
photos_change_timestamp DATETIME DEFAULT NULL,
listing_contract_date DATE DEFAULT NULL,
@@ -332,6 +340,83 @@ class MLS_DB {
dbDelta($sql_geo_zipcodes);
// Manual properties table (for manually entered listings)
$table_manual = $wpdb->prefix . MLS_TABLE_MANUAL_PROPERTIES;
$sql_manual = "CREATE TABLE {$table_manual} (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
wp_post_id BIGINT(20) UNSIGNED NOT NULL,
listing_key VARCHAR(50) NOT NULL,
listing_id VARCHAR(50) DEFAULT NULL,
standard_status VARCHAR(30) NOT NULL DEFAULT 'Active',
list_price DECIMAL(15,2) DEFAULT NULL,
original_list_price DECIMAL(15,2) DEFAULT NULL,
close_price DECIMAL(15,2) DEFAULT NULL,
street_number VARCHAR(20) DEFAULT NULL,
street_name VARCHAR(100) DEFAULT NULL,
street_suffix VARCHAR(30) DEFAULT NULL,
unit_number VARCHAR(20) DEFAULT NULL,
full_address VARCHAR(255) DEFAULT NULL,
city VARCHAR(100) DEFAULT NULL,
state_or_province VARCHAR(50) DEFAULT 'MN',
postal_code VARCHAR(20) DEFAULT NULL,
county VARCHAR(100) DEFAULT NULL,
latitude DECIMAL(10,8) DEFAULT NULL,
longitude DECIMAL(11,8) DEFAULT NULL,
property_type VARCHAR(50) DEFAULT NULL,
property_sub_type VARCHAR(50) DEFAULT NULL,
bedrooms_total INT(3) DEFAULT NULL,
bathrooms_total DECIMAL(4,1) DEFAULT NULL,
bathrooms_full INT(3) DEFAULT NULL,
bathrooms_half INT(3) DEFAULT NULL,
living_area INT(10) DEFAULT NULL,
lot_size_area DECIMAL(12,4) DEFAULT NULL,
lot_size_units VARCHAR(20) DEFAULT 'Acres',
year_built INT(4) DEFAULT NULL,
stories INT(3) DEFAULT NULL,
garage_spaces INT(3) DEFAULT NULL,
architectural_style VARCHAR(100) DEFAULT NULL,
public_remarks TEXT DEFAULT NULL,
private_remarks TEXT DEFAULT NULL,
directions TEXT DEFAULT NULL,
list_agent_post_id BIGINT(20) UNSIGNED DEFAULT NULL,
co_list_agent_post_id BIGINT(20) UNSIGNED DEFAULT NULL,
is_homeproz TINYINT(1) NOT NULL DEFAULT 0,
is_featured TINYINT(1) NOT NULL DEFAULT 0,
virtual_tour_url VARCHAR(500) DEFAULT NULL,
association_fee DECIMAL(10,2) DEFAULT NULL,
list_date DATE DEFAULT NULL,
contract_date DATE DEFAULT NULL,
close_date DATE DEFAULT NULL,
expiration_date DATE DEFAULT NULL,
photos_count INT(5) DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY listing_key (listing_key),
UNIQUE KEY wp_post_id (wp_post_id),
KEY listing_id (listing_id),
KEY standard_status (standard_status),
KEY city (city),
KEY property_type (property_type),
KEY list_price (list_price),
KEY is_homeproz (is_homeproz),
KEY is_featured (is_featured),
KEY latitude (latitude),
KEY longitude (longitude)
) {$charset_collate};";
dbDelta($sql_manual);
// Run index migrations
self::run_index_migrations();
}
@@ -473,8 +558,66 @@ class MLS_DB {
update_option('mls_schema_version', 5);
}
// Migration to schema version 6: Add media_expires_at column for proactive URL refresh
if ($current_schema < 6) {
$table_properties = $wpdb->prefix . MLS_TABLE_PROPERTIES;
// Check if column exists
$column_exists = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = 'media_expires_at'",
DB_NAME,
$table_properties
));
if (!$column_exists) {
$wpdb->query("ALTER TABLE {$table_properties} ADD COLUMN media_expires_at DATETIME DEFAULT NULL AFTER photos_count");
}
// Add index for finding properties with expiring media
$existing_indexes = self::get_existing_indexes($table_properties);
if (!isset($existing_indexes['idx_media_expires_at'])) {
$wpdb->query("ALTER TABLE {$table_properties} ADD INDEX idx_media_expires_at (media_expires_at)");
}
update_option('mls_schema_version', 6);
}
// Migration to schema version 7: Add indexes for search query optimization
if ($current_schema < 7) {
$table_properties = $wpdb->prefix . MLS_TABLE_PROPERTIES;
$existing_indexes = self::get_existing_indexes($table_properties);
// Index for postal code searches
if (!isset($existing_indexes['idx_postal_code'])) {
$wpdb->query("ALTER TABLE {$table_properties} ADD INDEX idx_postal_code (postal_code)");
}
// Index for bathroom filter
if (!isset($existing_indexes['idx_bathrooms_total'])) {
$wpdb->query("ALTER TABLE {$table_properties} ADD INDEX idx_bathrooms_total (bathrooms_total)");
}
// Index for living area (sqft) filter
if (!isset($existing_indexes['idx_living_area'])) {
$wpdb->query("ALTER TABLE {$table_properties} ADD INDEX idx_living_area (living_area)");
}
// Index for state filter
if (!isset($existing_indexes['idx_state'])) {
$wpdb->query("ALTER TABLE {$table_properties} ADD INDEX idx_state (state_or_province)");
}
// Composite index for media refresh sync query
if (!isset($existing_indexes['idx_status_media_expires'])) {
$wpdb->query("ALTER TABLE {$table_properties} ADD INDEX idx_status_media_expires (standard_status, media_expires_at)");
}
update_option('mls_schema_version', 7);
}
// Future migrations go here:
// if ($current_schema < 6) { ... }
// if ($current_schema < 8) { ... }
}
/**
@@ -511,6 +654,7 @@ class MLS_DB {
MLS_TABLE_MEDIA_LOG,
MLS_TABLE_GEO_CITIES,
MLS_TABLE_GEO_ZIPCODES,
MLS_TABLE_MANUAL_PROPERTIES,
);
foreach ($tables as $table) {