| 1 |
<?php |
| 2 |
/** |
| 3 |
* Reconciliation feed sanity guard. |
| 4 |
* |
| 5 |
* Pure function (no WordPress dependency) so it can be unit tested in |
| 6 |
* isolation. Reconciliation deletes every local listing absent from the MLS |
| 7 |
* feed; a well-formed but truncated feed would therefore trigger a mass |
| 8 |
* deletion. This decides whether the feed is a plausible size before any |
| 9 |
* deletion is allowed. |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly |
| 14 |
} |
| 15 |
|
| 16 |
/** Feed must carry at least this fraction of the local ListingKey count. */ |
| 17 |
const MLSIMPORT_RECONCILIATION_MIN_FEED_FRACTION = 0.8; |
| 18 |
|
| 19 |
/** |
| 20 |
* Whether the reconciliation feed is a plausible size relative to the local set. |
| 21 |
* |
| 22 |
* @param int $feed_count Number of ListingKeys returned by the MLS feed. |
| 23 |
* @param int $local_count Number of local listings carrying a ListingKey. |
| 24 |
* @return bool True when reconciliation may proceed. |
| 25 |
*/ |
| 26 |
function mlsimport_reconciliation_feed_is_plausible( int $feed_count, int $local_count ): bool { |
| 27 |
// With no local listings there is nothing to reconcile against; refuse. |
| 28 |
if ( $local_count <= 0 ) { |
| 29 |
return false; |
| 30 |
} |
| 31 |
// Plausible only when the feed covers at least the required fraction of locals. |
| 32 |
return $feed_count >= $local_count * MLSIMPORT_RECONCILIATION_MIN_FEED_FRACTION; |
| 33 |
} |
| 34 |
|