Guard against stupid forum software containing duplicate subscriptions
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 28 Aug 2015 17:17:04 +0000 (19:17 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 28 Aug 2015 17:18:19 +0000 (19:18 +0200)
wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php

index 2b1ce6f44c871b51534e01b6bea579b45b5cc4bc..ff1c719aa78345d33d15ae580ca8ab5fcc271615 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\importer;
 use wcf\data\user\object\watch\UserObjectWatchEditor;
+use wcf\system\database\DatabaseException
 
 /**
  * Imports watched objects.
@@ -31,7 +32,16 @@ class AbstractWatchedObjectImporter extends AbstractImporter {
                $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
                if (!$data['userID']) return 0;
                
-               $watch = UserObjectWatchEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID)));
+               try {
+                       $watch = UserObjectWatchEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID)));
+               }
+               catch (DatabaseException $e) {
+                       // 23000 = INTEGRITY CONSTRAINT VIOLATION a.k.a. duplicate key
+                       if ($e->getCode() != 23000) {
+                               throw $e;
+                       }
+               }
+               
                return $watch->watchID;
        }
 }