Ignore potential collisions if importing follower
authorAlexander Ebert <ebert@woltlab.com>
Sun, 28 Jul 2013 11:20:16 +0000 (13:20 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 28 Jul 2013 11:20:16 +0000 (13:20 +0200)
Under certain circumstances, the default inserts could fail if a user is being merged during the process and follows the same user as the merged user.

wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php

index f357d209ac332d0f96f17852e900d80885ff2074..3aa714ae62e7377e8eb2853271608a8e57fc747f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 namespace wcf\system\importer;
-use wcf\data\user\follow\UserFollowAction;
+use wcf\system\WCF;
 
 /**
  * Imports followers.
@@ -21,10 +21,16 @@ class UserFollowerImporter implements IImporter {
                $data['followUserID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['followUserID']);
                if (!$data['userID'] || !$data['followUserID']) return 0;
                
-               $action = new UserFollowAction(array(), 'create', array(
-                       'data' => $data         
+               $sql = "INSERT IGNORE INTO      wcf".WCF_N."_user_follow
+                                               (userID, followUserID, time)
+                       VALUES                  (?, ?, ?)";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(
+                       $data['userID'],
+                       $data['followUserID'],
+                       $data['time']
                ));
-               $returnValues = $action->executeAction();
-               return $returnValues['returnValues']->followID;
+               
+               return WCF::getDB()->getInsertID('wcf'.WCF_N.'_user_follow', 'followID');
        }
 }