From 81c138e75ee032549a6ae11ebfb72fa9fb43b7bd Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sun, 26 May 2024 21:25:07 +0100 Subject: [PATCH] Move post-retirement check to config. --- conf/general-example | 12 +++++++++++ search/index.pl | 17 +++++++-------- www/includes/easyparliament/hansardlist.php | 23 ++++----------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/conf/general-example b/conf/general-example index 894de7bcac..0e74da8fb1 100644 --- a/conf/general-example +++ b/conf/general-example @@ -127,6 +127,18 @@ define ("RECESSFILE","https://www.theyworkforyou.com/pwdata/parl-recesses.txt"); define("TWFY_VOTES_URL", ""); +define('ENTRIES_AFTER_LEFT', '{ + "10170,2014-09-08": "2014-09-07", + "11068,2008-09": "2008-08-13", + "25394,2016-07-01": "2016-06-16", + "10599,2021-02": "2021-02-19", + "25942,2021-09-17": "2021-05-07", + "11667,2022-12": "2022-11-30", + "13485,2023-07": "2023-07-27", + "13485,2023-08": "2023-07-27", + "10578,2024-05-01": "2024-04-29", + "13633,2024-05": "2024-05-20" +}'); // ******************************************************************************* // More Email addresses. diff --git a/search/index.pl b/search/index.pl index b4db43eae2..ce0fc9a0af 100755 --- a/search/index.pl +++ b/search/index.pl @@ -117,6 +117,9 @@ 101 => { 2 => 1 }, ); +my $after_left = mySociety::Config::get('ENTRIES_AFTER_LEFT') || '{}'; +$after_left = decode_json($after_left); + # Be aware of redirected persons - code similar to xml2db.pl my %personredirect; my $pwmembers = mySociety::Config::get('PWMEMBERS'); @@ -369,18 +372,14 @@ sub get_person { $person_id = $personredirect{$person_id} || $person_id; # Special exemptions for people 'speaking' after they have left - # Note identical code to this in hansardlist.php - $hdate = '20140907' if $person_id == 10170 && $hdate eq '20140908'; - $hdate = '20080813' if $person_id == 11068 && substr($hdate, 0, 6) eq '200809'; - $hdate = '20160616' if $person_id == 25394 && $hdate eq '20160701'; - $hdate = '20210219' if $person_id == 10599 && substr($hdate, 0, 6) eq '202102'; - $hdate = '20221130' if $person_id == 11667 && substr($hdate, 0, 6) eq '202212'; - $hdate = '20230727' if $person_id == 13485 && $hdate gt '20230727'; - $hdate = '20240429' if $person_id == 10578 && $hdate gt '20240429'; + (my $hhdate = $hdate) =~ s/(\d\d\d\d)(\d\d)(\d\d)/\1-\2-\3/; + my $hhdate_month = substr($hhdate, 0, 7); + $hhdate = $after_left->{"$person_id,$hhdate"} || $hhdate; + $hhdate = $after_left->{"$person_id,$hhdate_month"} || $hhdate; + ($hdate = $hhdate) ~ s/-//g; # London questions answered after election $hdate = '20210507' if $major == 9 && ($hdate eq '20210511' || $hdate eq '20210510'); - $hdate = '20210507' if $person_id == 25942 && $major == 9 && $hdate eq '20210917'; my @matches = @{$dbh->selectall_arrayref($q_person, { Slice => {} }, $person_id, $hdate, $hdate, $hdate, $hdate)}; if (@matches > 1) { diff --git a/www/includes/easyparliament/hansardlist.php b/www/includes/easyparliament/hansardlist.php index b5bb85d487..45ff12baea 100644 --- a/www/includes/easyparliament/hansardlist.php +++ b/www/includes/easyparliament/hansardlist.php @@ -110,6 +110,7 @@ class HANSARDLIST { public function __construct() { $this->db = new ParlDB; + $this->after_left = json_decode(ENTRIES_AFTER_LEFT, 1) ?? []; } @@ -2088,30 +2089,14 @@ public function _get_speaker($person_id, $hdate, $htime, $major) { } # Special exemptions for people 'speaking' after they have left - # Note identical code to this in search/index.pl - if ($person_id == 10170 && $hdate == '2014-09-08') { - $hdate = '2014-09-07'; - } elseif ($person_id == 11068 && substr($hdate, 0, 7) == '2008-09') { - $hdate = '2008-08-13'; - } elseif ($person_id == 25394 && $hdate == '2016-07-01') { - $hdate = '2016-06-16'; - } elseif ($person_id == 10599 && substr($hdate, 0, 7) == '2021-02') { - $hdate = '2021-02-19'; - } elseif ($person_id == 11667 && substr($hdate, 0, 7) == '2022-12') { - $hdate = '2022-11-30'; - } elseif ($person_id == 13485 && $hdate > '2023-07-27') { - $hdate = '2023-07-27'; - } elseif ($person_id == 10578 && $hdate > '2024-04-29') { - $hdate = '2024-04-29'; - } + $hdate_month = substr($hdate, 0, 7); + $hdate = $this->after_left["$person_id,$hdate"] ?? $hdate; + $hdate = $this->after_left["$person_id,$hdate_month"] ?? $hdate; # London questions answered after election if ($major == 9 && ($hdate == '2021-05-11' || $hdate == '2021-05-10')) { $hdate = '2021-05-07'; } - if ($person_id == 25942 && $major == 9 && $hdate == '2021-09-17') { - $hdate = '2021-05-07'; - } # check for a person redirect $q = $this->db->query("SELECT gid_to FROM gidredirect