Fixed user import issues
authorMarcel Werk <burntime@woltlab.com>
Sun, 29 Sep 2013 13:58:02 +0000 (15:58 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 29 Sep 2013 13:58:02 +0000 (15:58 +0200)
wcfsetup/install/files/lib/system/importer/UserImporter.class.php

index 730b1323bbb9356b77aba38c0d186bb11ef72bce..75da10caf15226a0014987d4f4e600551b11a9b6 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\importer;
 use wcf\data\user\group\UserGroup;
+use wcf\data\user\option\UserOptionList;
 use wcf\data\user\User;
 use wcf\data\user\UserEditor;
 use wcf\system\database\DatabaseException;
@@ -30,6 +31,12 @@ class UserImporter extends AbstractImporter {
         */
        protected $eventIDs = array();
        
+       /**
+        * list of user options
+        * @var array<wcf\data\user\option\UserOption>
+        */
+       protected $userOptions = array();
+       
        /**
         * Creates a new UserImporter object.
         */
@@ -43,6 +50,10 @@ class UserImporter extends AbstractImporter {
                while ($row = $statement->fetchArray()) {
                        $this->eventIDs[] = $row['eventID'];
                }
+               
+               $userOptionList = new UserOptionList();
+               $userOptionList->readObjects();
+               $this->userOptions = $userOptionList->getObjects();
        }
        
        /**
@@ -81,6 +92,37 @@ class UserImporter extends AbstractImporter {
                                        $userOptions[$optionID] = $optionValue;
                                }
                        }
+                       
+                       // fix option values
+                       foreach ($userOptions as $optionID => &$optionValue) {
+                               switch ($this->userOptions[$optionID]->optionType) {
+                                       case 'boolean':
+                                               if ($optionValue) $optionValue = 1;
+                                               else $optionValue = 0;
+                                               break;
+                                                       
+                                       case 'integer':
+                                               $optionValue = intval($optionValue);
+                                               if ($optionValue > 2147483647) $optionValue = 2147483647;
+                                               break;
+                                                       
+                                       case 'float':
+                                               $optionValue = floatval($optionValue);
+                                               break;
+                                                       
+                                       case 'textarea':
+                                               if (strlen($optionValue) > 16777215) $optionValue = substr($optionValue, 0, 16777215);
+                                               break;
+                                                       
+                                       case 'birthday':
+                                       case 'date':
+                                               if (!preg_match('/^\d{4}\-\d{2}\-\d{2}$/', $optionValue)) $optionValue = '0000-00-00';
+                                               break;
+                                               
+                                       default:
+                                               if (strlen($optionValue) > 65535) $optionValue = substr($optionValue, 0, 65535);
+                               }
+                       }
                }
                
                // create user