Avoid double transaction.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 30 Oct 2010 07:27:37 +0000 (09:27 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 30 Oct 2010 07:27:37 +0000 (09:27 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/profile.php
include/name.func.inc.php
modules/admin.php

index 8eb66bb..9b2e4b0 100644 (file)
@@ -1011,7 +1011,7 @@ class Profile
         }
     }
 
         }
     }
 
-    public static function rebuildSearchTokens($pids)
+    public static function rebuildSearchTokens($pids, $transaction = true)
     {
         if (!is_array($pids)) {
             $pids = array($pids);
     {
         if (!is_array($pids)) {
             $pids = array($pids);
@@ -1053,7 +1053,9 @@ class Profile
                                                     $eltScore, $key['public']);
             }
         }
                                                     $eltScore, $key['public']);
             }
         }
-        XDB::startTransaction();
+        if ($transaction) {
+            XDB::startTransaction();
+        }
         XDB::execute('DELETE FROM  search_name
                             WHERE  pid IN {?}',
                      $pids);
         XDB::execute('DELETE FROM  search_name
                             WHERE  pid IN {?}',
                      $pids);
@@ -1061,7 +1063,9 @@ class Profile
             XDB::rawExecute('INSERT INTO  search_name (token, pid, soundex, score, flags)
                                   VALUES  ' . implode(', ', $names));
         }
             XDB::rawExecute('INSERT INTO  search_name (token, pid, soundex, score, flags)
                                   VALUES  ' . implode(', ', $names));
         }
-        XDB::commit();
+        if ($transaction) {
+            XDB::commit();
+        }
     }
 
     /** The school identifier consists of 6 digits. The first 3 represent the
     }
 
     /** The school identifier consists of 6 digits. The first 3 represent the
index d954263..b23fdff 100644 (file)
@@ -308,7 +308,7 @@ function set_alias_names(&$sn_new, $sn_old, $pid, $uid, $update_new = false, $ne
                            VALUES  ({?}, 'alias', 'usage', {?})",
                      $new_alias, $uid);
     }
                            VALUES  ({?}, 'alias', 'usage', {?})",
                      $new_alias, $uid);
     }
-    Profile::rebuildSearchTokens($pid);
+    Profile::rebuildSearchTokens($pid, false);
     return $has_new;
 }
 
     return $has_new;
 }
 
index 567895a..6b5fc43 100644 (file)
@@ -876,7 +876,7 @@ class AdminModule extends PLModule
                             XDB::execute('INSERT INTO  account_profiles (uid, pid, perms)
                                                VALUES  ({?}, {?}, {?})',
                                          $uid, $pid, 'owner');
                             XDB::execute('INSERT INTO  account_profiles (uid, pid, perms)
                                                VALUES  ({?}, {?}, {?})',
                                          $uid, $pid, 'owner');
-                            Profile::rebuildSearchTokens($pid);
+                            Profile::rebuildSearchTokens($pid, false);
                         }
                     }
                 }
                         }
                     }
                 }