Seeing as SugarCRM is now truly Open Source, I decided to support them buy using SugarCRM as a contact database for a client.
This script extracts contact data from Sugar, and imports it into an LDAP tree, so that Thunderbird clients can use it as an address book.
It’s written for Sugar 5.0, and a suitable LDAP installation with the Mozilla Schema
A suitable VIEW for printing out a contact directory would look like:
CREATE OR REPLACE VIEW sugarab
AS
SELECT c.id
, c.description
, salutation
, first_name
, last_name
, title
, department
,
do_not_call
, phone_home
, phone_mobile
, phone_work
, phone_other
, c.phone_fax
,
primary_address_street
, primary_address_city
, primary_address_state
,
primary_address_postalcode
, primary_address_country
, alt_address_street
,
alt_address_city
, alt_address_state
, alt_address_postalcode
, alt_address_country
,
assistant
, assistant_phone
, lead_source
, birthdate
,
a.name
AS account_name
,
e1.email_address
AS primary_email
, e2.email_address
AS secondary_email
FROM contacts
AS c
LEFT OUTER JOIN accounts_contacts
AS j
ON (c.id
= j.contact_id
AND j.deleted
= 0)
LEFT OUTER JOIN accounts
AS a
ON (j.account_id
= a.id
AND a.deleted
= 0)
LEFT OUTER JOIN email_addr_bean_rel
as eb
ON (eb.bean_id
= c.id
AND eb.deleted
= 0)
LEFT OUTER JOIN email_addresses
as e1
ON (eb.email_address_id
= e1.id
AND eb.primary_address
= 1 AND e1.deleted
= 0)
LEFT OUTER JOIN email_addresses
as e2
ON (eb.email_address_id
= e2.id
AND e1.id
!= e2.id
AND e2.deleted
= 0)
WHERE c.deleted
= 0;
Comments
Erk, there is already a plugin
Jonathan Carter has pointed out to me that there already is a Thunderbird Plugin for Sugar. Why the stupid idiots haven’t registered it on add-ons.mozilla.com, I don’t know… I’ll have to try it out :-)
Fix for utf-8
Problem with this script
I filled in ldap and mysql data, added mozilla.scheme to openldap, but when i run this script i get this error:
File "sugarslurp.py", line 174, in
l.add_s(dn, ldap.modlist.addModlist(entry))
File "/usr/lib/python2.5/site-packages/ldap/ldapobject.py", line 185, in add_s
return self.result(msgid,all=1,timeout=self.timeout)
File "/usr/lib/python2.5/site-packages/ldap/ldapobject.py", line 427, in result
res_type,res_data,res_msgid = self.result2(msgid,all,timeout)
File "/usr/lib/python2.5/site-packages/ldap/ldapobject.py", line 431, in result2
res_type, res_data, res_msgid, srv_ctrls = self.result3(msgid,all,timeout)
File "/usr/lib/python2.5/site-packages/ldap/ldapobject.py", line 437, in result3
ldap_result = self._ldap_call(self._l.result3,msgid,all,timeout)
File "/usr/lib/python2.5/site-packages/ldap/ldapobject.py", line 96, in _ldap_call
result = func(*args,**kwargs)
ldap.INVALID_SYNTAX: {'info': 'c: value #0 invalid per syntax', 'desc': 'Invalid syntax'}
Any clues?
Thank you
Re: INVALID SYNTAX
Looks like it’s setting something as ‘c’ (Country) which it shouldn’t be.
Print out entry before storing it, and try to work out what’s going on.
I tweeked the script (removed
I tweeked the script (removed Mozilla scheme) and now i've managet to import data from Sugar to LDAP(phonebook).
Great stuff....thanks fro the code.
thanks for the code Stefano
awesome job!
This little snippet of python had us syncing SugarCRM contacts to eDirectory in a few hours. Really appreciate you giving this away for us to take advantage of.
I've tweaked your script somewhat to comply with eDirectory LDAP schema. Anyone too lazy to customise their own can contact us at http://loyfam.com.au/index.php?page=contact-us for a copy of our version of this great bit of code.
thanks again
Aaron.
Bigger version of such task
We've made something closely related to such task.
We have published on sugarForge some python scripts using triggers from MySQL to detect sync needed between Sugar and an LDAP branch.
Theses scripts handle much more things (custom tables, fields and custom fields mappings, surgar users sync, etc.)
People reading this page might be interedted in such scripts.
Feedback welcome!
http://www.sugarforge.org/projects/ldapcontactsync/
Post new comment