FOSUserBundle: Custom password / Migration from old DB structure

后端 未结 2 671
我寻月下人不归
我寻月下人不归 2020-12-28 11:20

I want to move to Symfony2, because I am totally impressed by its modernity and good programming.

Now I am taking a users table from my old system, with 10,000 users

2条回答
  •  生来不讨喜
    2020-12-28 11:44

    It is very easy to do with FOSUserBundle. This is the code for it:

    $userManager = $this->get('fos_user.user_manager');
    
    foreach ($items as $item) {
        $newItem = $userManager->createUser();
    
        //$newItem->setId($item->getObjId());
        // FOSUserBundle required fields
        $newItem->setUsername($item->getUsername());
        $newItem->setEmail($item->getEmail());
        $newItem->setPlainPassword($item->getPassword()); // get original password
        $newItem->setEnabled(true);
    
        $userManager->updateUser($newItem, true);
    }
    

提交回复
热议问题