Merge remote branch 'origin/platal-1.0.1'
[platal.git] / classes / profile.php
index 304ca7b..9b2e4b0 100644 (file)
@@ -538,11 +538,15 @@ class Profile
 
     public function getMainAddress()
     {
-        $addr = $this->getAddresses(self::ADDRESS_PERSO | self::ADDRESS_MAIN);
-        if (count($addr) == 0) {
-            return null;
+        $main = $this->getAddresses(self::ADDRESS_MAIN);
+        $perso = $this->getAddresses(self::ADDRESS_PERSO);
+
+        if (count($main)) {
+            return array_pop($main);
+        } else if (count($perso)) {
+            return array_pop($perso);
         } else {
-            return array_pop($addr);
+            return null;
         }
     }
 
@@ -1007,7 +1011,7 @@ class Profile
         }
     }
 
-    public static function rebuildSearchTokens($pids)
+    public static function rebuildSearchTokens($pids, $transaction = true)
     {
         if (!is_array($pids)) {
             $pids = array($pids);
@@ -1049,7 +1053,9 @@ class Profile
                                                     $eltScore, $key['public']);
             }
         }
-        XDB::startTransaction();
+        if ($transaction) {
+            XDB::startTransaction();
+        }
         XDB::execute('DELETE FROM  search_name
                             WHERE  pid IN {?}',
                      $pids);
@@ -1057,7 +1063,9 @@ class Profile
             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