[Kolab-devel] Accessing contacts from roundcube cli
Thomas Brüderli
bruederli at kolabsys.com
Wed Aug 7 09:15:48 CEST 2013
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
More information about the devel
mailing list