From fe96a80796049f77a577916d038ffecb913565b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Thu, 17 Nov 2011 16:33:17 +0100 Subject: [PATCH] Adds helper to add new users for promotion for which we already have users, eg for second year masters. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- bin/promo_update_help.php | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 bin/promo_update_help.php diff --git a/bin/promo_update_help.php b/bin/promo_update_help.php new file mode 100755 index 0000000..aaf5c27 --- /dev/null +++ b/bin/promo_update_help.php @@ -0,0 +1,91 @@ +#!/usr/bin/php5 -q +debug = 0; // Do not store backtraces + +$opts = getopt('f:p:'); + +if (empty($opts['f']) || empty($opts['p'])) { + print "File name missing (-f=file_name) or promotion missing (-p=file_name).\n"; + exit; +} + +$file = $opts['f']; +$handle = fopen($file, 'r'); +$promo_year = $opts['p']; + +$already = array(); +$new = array(); +$ambiguous = array(); + +while ($line = trim(fgets($handle))) { + $data = explode(';', $line); + $cond = new PFC_And(new UFC_NameTokens(split_name_for_search($data[0]), array(), false, false, Profile::LASTNAME)); + $cond->addChild(new UFC_NameTokens(split_name_for_search($data[1]), array(), false, false, Profile::FIRSTNAME)); + $uf = new UserFilter($cond); + $profiles = $uf->getProfiles(); + switch (count($profiles)) { + case 0: + $new[] = $line; + break; + case 1: + foreach ($profiles as $profile) { + $already[] = $profile->hrid(); + } + break; + default: + $hrids = array(); + foreach ($profiles as $profile) { + $hrids[] = $profile->hrid(); + } + $ambiguous[] = $line . ': ' . implode(', ', $hrids); + break; + } +} + +$cond = new UFC_Promo('=', UserFilter::GRADE_MST, $promo_year); +$uf = new UserFilter($cond); +$profiles = $uf->getProfiles(); +$promo = array(); +foreach ($profiles as $profile) { + $promo[] = $profile->hrid(); +} + +$intersect = array_intersect($promo, $already); +if (count($intersect) != count($already)) { + print "There seems to be a problem: intersection of this promo and already found users differ.\n"; +} +$to_remove = array_diff($promo, $intersect); + +sort($new); +sort($ambiguous); +sort($to_remove); + +print "New users:\n" . implode("\n", $new) . "\n\n"; +print "Ambiguous users:\n" . implode("\n", $ambiguous) . "\n\n"; +print "Users to remove (louk out for ambiguous users before!):\n" . implode("\n", $to_remove) . "\n"; + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> -- 2.1.4