Re: [Kolab-devel] Accessing contacts from roundcube cli

Thomas Brüderli <[email protected]>
Newsgroups gmane.comp.kde.devel.kolab
Message-ID <5201F424.7080005__11743.3312967934$1375859759$gmane$org@kolabsys.com>
Andrzej Kwiatkowski wrote:
> Hi,

Hello!
> 
> I need to write cmd tool to access kolab adressbook from cli.
> 
> Script looks like:
> 
> 
> require_once INSTALL_PATH.'program/include/clisetup.php';
> 
> $RCMAIL = rcmail::get_instance();
> 
> $RCMAIL->login($user, $pass, $host = null, $cookiecheck = false);
> 
> $RCMAIL->task="addressbook";
> 
> $RCMAIL->plugins->init($RCMAIL, $RCMAIL->task);
> $RCMAIL->plugins->load_plugins((array)$RCMAIL->config->get('plugins',
> array()), array('filesystem_attachments', 'jqueryui'));
> 
> 
> Now i would like to list address sources
> so i try to do:
> 
> $ka=new kolab_addressbook(null);
> 
> print_r($ka->get_address_sources()); - line 107
> 
> But this gives me:
> PHP Fatal error:  Call to undefined method
> kolab_addressbook::get_address_sources() in abook.php on line 107
> 
> when i add $ka->init(); before line 107 i got:
> 
> HP Fatal error:  Call to a member function load_plugin() on a non-object
> in /program/lib/Roundcube/rcube_plugin.php on line 102


$RCMAIL->plugins->init() is already executed in rcmail::get_instance().
Furthermore, get_address_sources() is a method of $RCMAIL and not the
kolab_addressbook class.

The tricky part is to set the task right in order to load the plugins.
Here's my suggestion for the script:

  require_once INSTALL_PATH.'program/include/clisetup.php';

  $RCMAIL = rcmail::get_instance();
  $RCMAIL->login($user, $pass, $host, false);
  $RCMAIL->plugins->task = "addressbook";
  $RCMAIL->plugins->load_plugin('kolab_addressbook');

  $sources = $RCMAIL->get_address_sources();
  foreach ($sources as $abook) {
    if ($abook instanceof rcube_kolab_contacts) {
      // do stuff here
    }
  }

Please note that this code is untested but just written to this email.

~Thomas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.