/** @return User\XML\Import\ReadyToBeImportedUsersCollection */
 public function transform(UsersToBeImportedCollection $collection_from_archive, $filename)
 {
     $csv_lines = $this->parseCSVFile($filename);
     $collection_for_import = new ReadyToBeImportedUsersCollection();
     foreach ($collection_from_archive->toArray() as $username => $to_be_imported_user) {
         if (isset($csv_lines[$username])) {
             $action = $csv_lines[$username];
             $collection_for_import->add($this->transformUser($collection_from_archive, $username, $action, $to_be_imported_user), $to_be_imported_user->getOriginalUserId(), $to_be_imported_user->getUserName(), $to_be_imported_user->getOriginalLdapId());
         } else {
             if ($to_be_imported_user instanceof AlreadyExistingUser) {
                 $collection_for_import->add($to_be_imported_user, $to_be_imported_user->getOriginalUserId(), $to_be_imported_user->getUserName(), $to_be_imported_user->getOriginalLdapId());
             } else {
                 throw new MissingEntryInMappingFileException("user {$username} should be in the mapping file");
             }
         }
     }
     return $collection_for_import;
 }
예제 #2
0
 private function getUserFromXML(SimpleXMLElement $xml_element)
 {
     $format = (string) $xml_element['format'];
     switch ($format) {
         case 'email':
             $email = (string) $xml_element;
             $user = $this->user_manager->getUserByEmail($email);
             if (!$user) {
                 $user = $this->user_manager->getUserAnonymous();
                 $user->setEmail((string) $xml_element);
             }
             break;
         case 'username':
             $username = (string) $xml_element;
             if ($username === self::$NONE_USERNAME) {
                 $user = $this->user_manager->getUserByUserName($username);
             } else {
                 $imported_user = $this->collection->getUserByUserName($username);
                 $user = $imported_user->getRealUser($this->user_manager);
             }
             break;
         case 'ldap':
             $ldap_id = (string) $xml_element;
             $imported_user = $this->collection->getUserByLdapId($ldap_id);
             $user = $imported_user->getRealUser($this->user_manager);
             break;
         case 'id':
             $user_id = (int) $xml_element;
             $imported_user = $this->collection->getUserById($user_id);
             $user = $imported_user->getRealUser($this->user_manager);
             break;
         default:
             // should not get here since xml is validated beforehand
             throw new RuntimeException("Unknown user format {$format}");
     }
     return $user;
 }