Fixes calls to auth_user_* from marketPromo.php
authorStéphane Jacob <sj@m4x.org>
Sun, 28 Feb 2010 00:55:44 +0000 (01:55 +0100)
committerStéphane Jacob <sj@m4x.org>
Sun, 28 Feb 2010 16:12:30 +0000 (17:12 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
bin/marketPromo.php

index 036449e..c385c1d 100755 (executable)
@@ -2,8 +2,8 @@
 <?php
 
 ini_set('include_path', '.:../include:/usr/share/php');
-require_once('connect.db.inc.php');
-require_once('marketing.inc.php');
+require_once 'connect.db.inc.php';
+require_once 'marketing.inc.php';
 
 $opts = getopt('f:l:m:');
 if (($opts['f'] && $opts['f'] == '-') || empty($opts['f'])) { 
@@ -19,24 +19,26 @@ $logcol = intval($opts['l']);
 $handle = fopen($file, 'r');
 
 while ($data = fgetcsv($handle)) {
-    $login = $data[$logcol];
-    $matri = preg_replace('/1(\d{2})(\d{3})/', '20${1}0\2', $data[$matcol]);
-    if (!is_numeric($matri)) {
-        echo "ERROR The matricule ($matri) is not a numerical value\n";
+    $login  = $data[$logcol];
+    $xorgid = preg_replace('/1(\d{2})(\d{3})/', '20${1}0\2', $data[$matcol]);
+    if (!is_numeric($xorgid)) {
+        echo "ERROR The matricule ($xorgid) is not a numerical value.\n";
         break;
     }
-    $query = XDB::query("SELECT  user_id
-                           FROM  auth_user_md5
-                          WHERE  matricule = {?}",
-                        $matri);
+    $query = XDB::query("SELECT  a.uid
+                           FROM  profiles         AS p
+                     INNER JOIN  account_profiles AS ap ON (p.pid = ap.pid AND FIND_IN_SET('owner', perms)
+                     INNER JOIN  accounts         AS a  ON (a.uid = ap.uid)
+                          WHERE  p.xorg_id = {?}",
+                        $xorgid);
     $uid = $query->fetchOneCell();
     if (!$uid) {
-        echo "WARNING Can't find uid for matricule $matri (login $login)\n";
+        echo "WARNING Can't find uid for matricule $xorgid (login $login)\n";
         continue;
     }
     $market = Marketing::get($uid, "$login@poly.polytechnique.fr");
     if (!is_null($market)) {
-        echo "WARNING A marketing has already been to $matri on $login\n";
+        echo "WARNING A marketing has already been to $xorgid on $login\n";
         continue;
     }
     $market = new Marketing($uid, "$login@poly.polytechnique.fr", 'default', null, 'staff');