PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.1.1
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.1.1
7.2.1 7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 All 36 releases
mlsimport / includes / mlsimport-reconciliation-guard.php

mlsimport-reconciliation-guard.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.1.1, at includes/mlsimport-reconciliation-guard.php

34 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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