#!/usr/bin/env php
<?php
/**
 * Copyright 2011-2015 Horde LLC (http://www.horde.org/)
 *
 * @license  http://www.horde.org/licenses/bsd BSD
 * @package Content
 */

if (file_exists(__DIR__ . '/../../content/lib/Application.php')) {
    $baseDir = __DIR__ . '/../';
} else {
    require_once 'PEAR/Config.php';
    $baseDir = PEAR_Config::singleton()
        ->get('horde_dir', null, 'pear.horde.org') . '/content/';
}
require_once $baseDir . 'lib/Application.php';
Horde_Registry::appInit('content', array('cli' => true));

$parser = new Horde_Argv_Parser();
list($opts, $tags) = $parser->parseArgs();
if (!count($tags)) {
    throw new InvalidArgumentException('List at least one tag to add.');
}

require CONTENT_BASE . '/lib/Tags/Tag.php';
require CONTENT_BASE . '/lib/Tags/TagMapper.php';

$m = new Content_TagMapper($injector->getInstance('Horde_Db_Adapter'));
foreach ($tags as $tag) {
    $t = $m->create(array('tag_name' => $tag));
    echo 'Created new tag with id ' . $t->tag_id . ' and name "' . $t->tag_name . "\".\n";
}
exit(0);
