54 lines
1.4 KiB
PHP
Executable File
54 lines
1.4 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
/**
|
|
* This script imports VCARD data into turba address books.
|
|
* The VCARD data is read from standard input, the address book and user name
|
|
* passed as parameters.
|
|
*
|
|
* Copyright 2005-2017 Horde LLC (http://www.horde.org/)
|
|
*
|
|
* See the enclosed file LICENSE for license information (ASL). If you
|
|
* did not receive this file, see http://www.horde.org/licenses/apache.
|
|
*
|
|
* @author Jan Schneider <jan@horde.org>
|
|
*/
|
|
|
|
if (file_exists(__DIR__ . '/../../turba/lib/Application.php')) {
|
|
$baseDir = __DIR__ . '/../';
|
|
} else {
|
|
require_once 'PEAR/Config.php';
|
|
$baseDir = PEAR_Config::singleton()
|
|
->get('horde_dir', null, 'pear.horde.org') . '/turba/';
|
|
}
|
|
require_once $baseDir . 'lib/Application.php';
|
|
Horde_Registry::appInit('turba', array('cli' => true));
|
|
|
|
// Read command line parameters.
|
|
if (count($argv) != 3) {
|
|
$cli->message('Too many or too few parameters.', 'cli.error');
|
|
usage();
|
|
}
|
|
$source = $argv[1];
|
|
$user = $argv[2];
|
|
|
|
$registry->setAuth($user, array());
|
|
|
|
// Read standard input.
|
|
$vcard = $cli->readStdin();
|
|
if (empty($vcard)) {
|
|
$cli->message('No import data provided.', 'cli.error');
|
|
usage();
|
|
}
|
|
|
|
// Import data.
|
|
$result = $registry->call('contacts/import', array($vcard, 'text/x-vcard', $source));
|
|
|
|
$cli->message('Imported successfully ' . count($result) . ' contacts', 'cli.success');
|
|
|
|
function usage()
|
|
{
|
|
$GLOBALS['cli']->writeln('Usage: turba-import-vcards source user');
|
|
exit;
|
|
}
|
|
|