This commit is contained in:
Hanson.xyz Dev
2026-01-04 17:50:08 -06:00
parent 7e45ce0756
commit acc8ac87a0
4131 changed files with 232562 additions and 250244 deletions
+151
View File
@@ -39,6 +39,7 @@ class MLS_CLI {
WP_CLI::add_command('mls cache', array($instance, 'cache'));
WP_CLI::add_command('mls recovery', array($instance, 'recovery'));
WP_CLI::add_command('mls media', array($instance, 'media'));
WP_CLI::add_command('mls geo', array($instance, 'geo'));
}
/**
@@ -1078,4 +1079,154 @@ class MLS_CLI {
rmdir($dir);
}
/**
* Geographic coordinate validation commands.
*
* ## OPTIONS
*
* <action>
* : Action to perform: validate, stats, or show-invalid
*
* ## EXAMPLES
*
* # Validate all property coordinates
* wp mls geo validate
*
* # Show validation statistics
* wp mls geo stats
*
* # Show properties with invalid coordinates
* wp mls geo show-invalid
*
* @param array $args Positional arguments
* @param array $assoc_args Associative arguments
*/
public function geo($args, $assoc_args) {
if (empty($args[0])) {
WP_CLI::error('Please specify an action: validate, stats, or show-invalid');
return;
}
$action = $args[0];
switch ($action) {
case 'validate':
$this->geo_validate();
break;
case 'stats':
$this->geo_stats();
break;
case 'show-invalid':
$this->geo_show_invalid();
break;
default:
WP_CLI::error("Unknown action: {$action}. Use validate, stats, or show-invalid.");
}
}
/**
* Validate all property coordinates
*/
private function geo_validate() {
WP_CLI::log('Validating property coordinates against state boundaries...');
WP_CLI::log('');
$progress = null;
$progress_callback = function($processed, $total, $valid, $invalid) use (&$progress) {
if ($progress === null) {
$progress = WP_CLI\Utils\make_progress_bar('Validating', $total);
}
$progress->tick();
};
$results = MLS_Geo_Validator::validate_all_properties($progress_callback);
if ($progress) {
$progress->finish();
}
WP_CLI::log('');
WP_CLI::success("Validation complete!");
WP_CLI::log(" Total properties: " . number_format($results['total']));
WP_CLI::log(" Valid coordinates: " . number_format($results['valid']));
WP_CLI::log(" Invalid coordinates: " . number_format($results['invalid']));
if ($results['invalid'] > 0) {
WP_CLI::log('');
WP_CLI::log("Properties with invalid coordinates will be excluded from map views.");
WP_CLI::log("Run 'wp mls geo show-invalid' to see details.");
}
}
/**
* Show coordinate validation statistics
*/
private function geo_stats() {
$stats = MLS_Geo_Validator::get_stats();
WP_CLI::log('Coordinate Validation Statistics:');
WP_CLI::log('');
WP_CLI::log(" Total properties: " . number_format($stats['total']));
WP_CLI::log(" Valid coordinates: " . number_format($stats['valid']));
WP_CLI::log(" Invalid coordinates: " . number_format($stats['invalid']));
WP_CLI::log(" Null coordinates: " . number_format($stats['null_coords']));
if ($stats['total'] > 0) {
$pct_valid = round(($stats['valid'] / $stats['total']) * 100, 1);
$pct_invalid = round(($stats['invalid'] / $stats['total']) * 100, 1);
WP_CLI::log('');
WP_CLI::log(" Valid %: {$pct_valid}%");
WP_CLI::log(" Invalid %: {$pct_invalid}%");
}
}
/**
* Show properties with invalid coordinates
*/
private function geo_show_invalid() {
global $wpdb;
$table = $this->plugin->get_db()->properties_table();
$invalid = $wpdb->get_results(
"SELECT listing_id, listing_key, street_number, street_name, city, state_or_province, latitude, longitude
FROM {$table}
WHERE coordinates_invalid = 1
ORDER BY city, street_name
LIMIT 100"
);
if (empty($invalid)) {
WP_CLI::success("No properties with invalid coordinates found.");
return;
}
WP_CLI::log("Properties with invalid coordinates (showing up to 100):");
WP_CLI::log('');
$items = array();
foreach ($invalid as $row) {
$address = trim($row->street_number . ' ' . $row->street_name);
$items[] = array(
'MLS ID' => $row->listing_id,
'Address' => $address ?: '(no address)',
'City' => $row->city,
'State' => $row->state_or_province,
'Lat' => $row->latitude,
'Lng' => $row->longitude,
);
}
WP_CLI\Utils\format_items('table', $items, array('MLS ID', 'Address', 'City', 'State', 'Lat', 'Lng'));
$total = $wpdb->get_var("SELECT COUNT(*) FROM {$table} WHERE coordinates_invalid = 1");
if ($total > 100) {
WP_CLI::log('');
WP_CLI::log("... and " . ($total - 100) . " more.");
}
}
}