65 lines
1.7 KiB
PHP
Executable File
65 lines
1.7 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
/**
|
|
* This script imports plain text data into Mnemo notepads.
|
|
*
|
|
* The data is read from standard input, the notepad 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__ . '/../../mnemo/lib/Application.php')) {
|
|
$baseDir = __DIR__ . '/../';
|
|
} else {
|
|
require_once 'PEAR/Config.php';
|
|
$baseDir = PEAR_Config::singleton()
|
|
->get('horde_dir', null, 'pear.horde.org') . '/mnemo/';
|
|
}
|
|
require_once $baseDir . 'lib/Application.php';
|
|
Horde_Registry::appInit('mnemo', array('cli' => true));
|
|
|
|
// Read command line parameters.
|
|
if (count($argv) != 4) {
|
|
$cli->message('Too many or too few parameters.', 'cli.error');
|
|
usage();
|
|
}
|
|
$notepad = $argv[1];
|
|
$user = $argv[2];
|
|
$file = $argv[3];
|
|
|
|
// Read standard input.
|
|
if (!file_exists($file)) {
|
|
$cli>message("$file does not exist", 'cli.error');
|
|
usage();
|
|
}
|
|
$data = file_get_contents($file);
|
|
if (empty($data)) {
|
|
$cli->message('No import data provided.', 'cli.error');
|
|
usage();
|
|
}
|
|
$data = pathinfo($file, PATHINFO_FILENAME) . "\n\n" . $data;
|
|
|
|
// Set user.
|
|
$registry->setAuth($user, array());
|
|
|
|
// Import data.
|
|
try {
|
|
$result = $registry->notes->import($data, 'text/plain', $notepad);
|
|
$cli->message('Imported successfully ' . count($result) . ' notes', 'cli.success');
|
|
} catch (Mnemo_Exception $e) {
|
|
$cli->fatal($e->getMessage());
|
|
}
|
|
|
|
function usage()
|
|
{
|
|
$GLOBALS['cli']->writeln('Usage: mnemo-import-text-note notepad user file');
|
|
exit;
|
|
}
|
|
|