Search code examples
symfony-1.4sfguardlogin-system

take backup of sfguard users in symfony


We have created our project in Symfony 1.4 and ORM Propel. We have two Projects, one is the old, and another is new. Our old project was launched earlier this year and had many problems in it, and we tried to create a new project(with new Domain name, and better functionality). But we have some users using the old site with the login information(i.e SfGuard users). We want that our user from the old site can login to our new site using the same login information. We have tried by dumping the sfGuard user info(from old site) into the Fixtures and load it to our new site. But it didnt work. is there anyway that we can do it.


Solution

  • I dont have much information to give a more accurate (what do you mean that dumping did not worked?, what database are you using?) answer but from the data you provided, my first approach would be to create a task in the new project that uses both databases (the old and the new one), transverse over the users creating a new user in the new database with the information retrived from the old one. To do so, add both databases in your database.yml , create a old_sfGuard_schema.yml and specify the database to use and also define the sfGuard classes (the class names should be something like sfOldGuardUser , sfOldGuardCredential, and so on, in order not to crash with the current sfGuardClasses ) you need. Finally your code should sound something like this:

    public function execute([..])
    {
      foreach(sfOldGuardUsersPeer::doSelect(new Criteria()) as $old_user)
      {
       $new_user = new sfGuardUser();
       $new_user->setUsername($old_user->getUsername());
       [...]
       foreach($old_user->getCredentials() as $old_user_credential)
       {
         [....]
       }
       $new_user->save();
      }
    
    }
    

    Note this is a pseudo code, it will not run on symfony, but your code will end up looking something like this.

    Also an SQL patch could be made by dumping the database informacion regarding users into a csv and creating some kind of patch.sql generated by some code that creates all the queries required to add the old users to the new databse. Once is donde, apply the patch to the new database.