Author Topic: External addressbook  (Read 3972 times)

Offline wendy

  • Newbie
  • *
  • Posts: 8
External addressbook
« on: August 10, 2010, 11:39:11 AM »
Hi,

I've been playing around with the address books a bit and managed to create a small plugin that adds a new address table to the roundcube DB and uses this table in addition to the usual 'contacts' table.

However, what I actually need is to take addresses from an existing external database (an Oracle one..).

In the plugin I extend rcube_contacts and then simply change the table name after creating a new instance. I'm not yet very familiar with roundcube so it's a little difficult to see whether it would be possible to change this to allow a connection to a completely different database instead. Is there a hook that will let me overwrite the function that gets the contacts for a particular address source from the DB?

I had a look at the plugin google_contacts, which does something similar to what I want. Except that it syncs by copying all google addresses into a table in the roundcube DB. This isn't really an option for us as there are way too many users with way too many addresses - we would prefer to not have to sync these but to get them straight from the external database.

If it would make it easier I would also be quite happy to completely disable the existing addressbook functionality and only use the "autocomplete" for new messages, if that autocomplete could refer to my own list of addresses.

Any ideas on this would be greatly appreciated!

Thanks,
Wendy

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
External addressbook
« Reply #1 on: August 10, 2010, 11:47:27 AM »
It should be able to that with the addressbooks_list and addressbook_get hooks.

Offline wendy

  • Newbie
  • *
  • Posts: 8
External addressbook
« Reply #2 on: August 10, 2010, 11:54:40 AM »
Well.. that's what I'm using now. At the moment I have something in the get_address_book hook (is that the same as addressbook_get? Names I find in other plugins never match the ones I find in the list of hooks)

                
if ($p['id'] === $this->abook_id) {
                        require_once(
dirname(__FILE__) . '/my_contacts_backend.php');

                        
$p['instance'] = new my_contacts_backend($rcmail->db$rcmail->user->ID);
                        
$p['instance']->groups false;

                        
$rcmail->output->command('enable_command''add''import'false);
                }


where my_contacts_backend is the class that extends rcube_contacts and does just this:


    
function __construct($dbconn$user)
    {
        
$rcmail rcmail::get_instance();
        
$rcmail->config->set('db_table_contacts'$rcmail->config->get('db_table_my_contacts'));
        
parent::__construct($dbconn$user);
        
$this->db_name get_table_name('my_contacts');
    }


So obviously this connects to the default roundcube database and then changes the table name to "my_contacts". What I'm not sure about is how to change this behaviour - presumably I need to extend this class and at some point call the parent constructor and at that point I'll have to pass in a database object. But as far as I can tell this is always a rcube_mdb2 object, so I can't just pass in anything there.

I know I'm being a bit vague, but I find this a little difficult to explain.. sorry :)

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
External addressbook
« Reply #3 on: August 10, 2010, 12:05:38 PM »
get_address_book was renamed addressbook_get, what version of RoundCube are you using? The class you'd be working with is rcube_addressbook found in /program/include/rcube_contacts.php

Offline wendy

  • Newbie
  • *
  • Posts: 8
External addressbook
« Reply #4 on: August 10, 2010, 12:11:15 PM »
As far as I know this was only just installed on our server, but not entirely sure. The version mentioned in index.php is "Version 0.4-beta". I'll see if it needs updating.

I was looking at rcube_contacts (which extends rcube_addressbook) instead of actually extending rcube_addressbook directly. Mainly because that is what the google_contacts plugin does and I've based most of my code on that. I will have a closer look at that class and see if that'll help.

Thanks!

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
External addressbook
« Reply #5 on: August 10, 2010, 12:42:54 PM »
0.4 stable came out a couple of days ago, I'd recommend updating.