Author Topic: New Plugin: import_atmail_contacts  (Read 5515 times)

Offline mrballcb

  • Newbie
  • *
  • Posts: 4
New Plugin: import_atmail_contacts
« on: February 12, 2014, 02:35:02 PM »
Hello all,

I have an ageing Atmail installation (old 4.x version in perl) that I'm working to convert to Roundcube.  I started with a Horde migration script I found on http://trac.roundcube.net/wiki/Plugin_Repository, and adapted it to migrate the Atmail addressbook including groups into a Roundcube user's addressbook, all using the user login hook.  I'd like some experienced eyes to look over my work and provide suggestions about code quality and/or how to make it better.

https://github.com/mrballcb/import_atmail_contacts

I've run this against live data (on a test system) and it works properly for me.  Anybody with a similar system who can test this against live data is encouraged to provide feedback and results.

One enhancement I would like guidance on:
I would like to be able to store an "addressbook_migrated" state in the user configuration.  I'm hesitant to touch the preferences field in the users table as I am not sure if that's the right place.  I've not researched this enough (at all actually) to figure out how to do it.  If anybody could provide links to documentation or code samples where I could see how it's best done, I would be most appreciative.

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
Re: New Plugin: import_atmail_contacts
« Reply #1 on: February 12, 2014, 04:18:37 PM »
One enhancement I would like guidance on:
I would like to be able to store an "addressbook_migrated" state in the user configuration.  I'm hesitant to touch the preferences field in the users table as I am not sure if that's the right place.  I've not researched this enough (at all actually) to figure out how to do it.  If anybody could provide links to documentation or code samples where I could see how it's best done, I would be most appreciative.
You could move it to the user_create hook, that way it would only run the first time the user logged in.

Offline mrballcb

  • Newbie
  • *
  • Posts: 4
Re: New Plugin: import_atmail_contacts
« Reply #2 on: February 12, 2014, 05:17:07 PM »
I did consider that, but was warned off by the docs.  That implies that the user object doesn't exist yet, and I didn't think I could create contacts without the user object existing.

> When a somebody logs in the first time and a local user is created.
> Return values will also be used to create the default identity for this new user.

I guess I have nothing to lose by at least _trying_ it with that hook.  I'll give it a shot tomorrow.  Thanks for bringing that hook back up and into my awareness.

Offline mrballcb

  • Newbie
  • *
  • Posts: 4
Re: New Plugin: import_atmail_contacts
« Reply #3 on: February 12, 2014, 06:47:43 PM »
I did consider that, but was warned off by the docs.  That implies that the user object doesn't exist yet, and I didn't think I could create contacts without the user object existing.

> When a somebody logs in the first time and a local user is created.
> Return values will also be used to create the default identity for this new user.

I guess I have nothing to lose by at least _trying_ it with that hook.  I'll give it a shot tomorrow.  Thanks for bringing that hook back up and into my awareness.
I tried using the user_create hook and it was as I expected.  Some (one?) of the method calls that this plugin requires fail because the user object hasn't been created yet.  I didn't debug _why_ it failed, just that it didn't import the addressbook entries.

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
Re: New Plugin: import_atmail_contacts
« Reply #4 on: February 12, 2014, 07:21:39 PM »
Maybe you could set a session variable in the user_create that you could pick up in the login hook?

Offline mrballcb

  • Newbie
  • *
  • Posts: 4
Re: New Plugin: import_atmail_contacts
« Reply #5 on: February 13, 2014, 11:42:39 AM »
Thanks for the suggestion.  I adapted your thought process and made these modifications:
  • Added a hook on user_create to trigger_atmail_abook_import
  • Added a function trigger_atmail_abook_import
  • Moved the hook on 'login_after' into the new trigger_atmail_abook_import

Now the login_after only gets executed on the first login, triggered by user_create.  This greatly simplifies the logic, means I don't have to touch session variables, and is one less login hook on every login after the first one (for that user).

Thanks again, I would not have thought of chaining add_hook commands like this without your comment.