Moves user_reindex to Profile.
authorStéphane Jacob <sj@m4x.org>
Fri, 19 Feb 2010 17:06:34 +0000 (18:06 +0100)
committerStéphane Jacob <sj@m4x.org>
Sat, 20 Feb 2010 00:31:37 +0000 (01:31 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
bin/search.rebuild_db.php
classes/profile.php
include/name.func.inc.php
include/user.func.inc.php
modules/register.php

index d506fa4..966287e 100755 (executable)
@@ -21,7 +21,6 @@
  ***************************************************************************/
 
 require('./connect.db.inc.php');
-require('user.func.inc.php');
 
 ini_set('memory_limit', "16M");
 $globals->debug = 0; // Do not store backtraces
@@ -31,7 +30,7 @@ $res = XDB::iterRow("SELECT  user_id
 $i = 0;
 $n = $res->total();
 while ($uid = $res->next()->fetchOneCell()) {
-    user_reindex($uid);
+    Profile::rebuildSearchTokens($uid);
     printf("\r%u / %u",  ++$i, $n);
 }
 
index 8136f0b..ad80d8a 100644 (file)
@@ -578,6 +578,38 @@ class Profile
             return $table[$type];
         }
     }
+
+    public static function rebuildSearchTokens($pid)
+    {
+        XDB::execute('DELETE FROM  search_name
+                            WHERE  uid = {?}',
+                     $pid);
+        $keys = XDB::iterator("SELECT  CONCAT(n.particle, n.name) AS name, e.score,
+                                       FIND_IN_SET('public', e.flags) AS public
+                                 FROM  profile_name      AS n
+                           INNER JOIN  profile_name_enum AS e ON (n.typeid = e.id)
+                                WHERE  n.pid = {?}",
+                              $pid);
+
+        foreach ($keys as $i => $key) {
+            if ($key['name'] == '') {
+                continue;
+            }
+            $toks  = preg_split('/[ \'\-]+/', $key['name']);
+            $token = '';
+            $first = 5;
+            while ($toks) {
+                $token = strtolower(replace_accent(array_pop($toks) . $token));
+                $score = ($toks ? 0 : 10 + $first) * ($key['score'] / 10);
+                XDB::execute('REPLACE INTO  search_name (token, uid, soundex, score, flags)
+                                    VALUES  ({?}, {?}, {?}, {?}, {?})',
+                             $token, $uid, soundex_fr($token), $score, $key['public']);
+                $first = 0;
+            }
+        }
+
+
+    }
 }
 
 /** Iterator over a set of Profiles
index 663aef9..f1f3f68 100644 (file)
@@ -282,8 +282,7 @@ function set_alias_names(&$sn_new, $sn_old, $update_new = false, $new_alias = nu
                            VALUES  ({?}, 'alias', 'usage', {?})",
                      $new_alias, S::i('uid'));
     }
-    require_once('user.func.inc.php');
-    user_reindex(S::i('uid'));
+    Profile::rebuildSearchTokens(S::i('uid'));
     return $has_new;
 }
 
index 487507a..ef0e133 100644 (file)
@@ -84,45 +84,6 @@ function user_clear_all_subs($user_id, $really_del=true)
 }
 
 // }}}
-// {{{ function _user_reindex
-
-function _user_reindex($uid, $keys)
-{
-    foreach ($keys as $i => $key) {
-        if ($key['name'] == '') {
-            continue;
-        }
-        $toks  = preg_split('/[ \'\-]+/', $key['name']);
-        $token = "";
-        $first = 5;
-        while ($toks) {
-            $token = strtolower(replace_accent(array_pop($toks) . $token));
-            $score = ($toks ? 0 : 10 + $first) * ($key['score'] / 10);
-            XDB::execute("REPLACE INTO  search_name (token, uid, soundex, score, flags)
-                                VALUES  ({?}, {?}, {?}, {?}, {?})",
-                         $token, $uid, soundex_fr($token), $score, $key['public']);
-            $first = 0;
-        }
-    }
-}
-
-// }}}
-// {{{ function user_reindex
-
-function user_reindex($uid) {
-    XDB::execute("DELETE FROM  search_name
-                        WHERE  uid = {?}",
-                 $uid);
-    $res = XDB::iterator("SELECT  CONCAT(n.particle, n.name) AS name, e.score,
-                                  FIND_IN_SET('public', e.flags) AS public
-                            FROM  profile_name      AS n
-                      INNER JOIN  profile_name_enum AS e ON (n.typeid = e.id)
-                           WHERE  n.pid = {?}",
-                         $uid);
-    _user_reindex($uid, $res);
-}
-
-// }}}
 // {{{ function get_X_mat
 function get_X_mat($ourmat)
 {
index b3885fb..73c9fa7 100644 (file)
@@ -255,8 +255,6 @@ class RegisterModule extends PLModule
             return PL_FORBIDDEN;
         }
 
-        require_once('user.func.inc.php');
-
         // Retrieve the pre-registration information using the url-provided
         // authentication token.
         if ($hash) {
@@ -325,7 +323,7 @@ class RegisterModule extends PLModule
         }
 
         // Add the registration email address as first and only redirection.
-        require_once('emails.inc.php');
+        require_once 'emails.inc.php';
         $user = User::getSilent($uid);
         $redirect = new Redirect($user);
         $redirect->add_email($email);
@@ -342,7 +340,6 @@ class RegisterModule extends PLModule
                     AXLetter::subscribe(S::user()->id());
                     break;
                 case 'imap':
-                    require_once 'emails.inc.php';
                     $user = S::user();
                     $storage = new EmailStorage($user, 'imap');
                     $storage->activate();
@@ -378,8 +375,7 @@ class RegisterModule extends PLModule
         $mymail->send();
 
         // Index the user, to allow her to appear in searches.
-        require_once('user.func.inc.php');
-        user_reindex($uid);
+        Profile::rebuildSearchTokens($uid);
 
         // Notify other users which were watching for her arrival.
         require_once 'notifs.inc.php';