File: content-tag-delete

package info (click to toggle)
php-horde-content 2.0.4-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 308 kB
  • ctags: 377
  • sloc: php: 1,454; xml: 474; makefile: 10; sh: 3
file content (44 lines) | stat: -rwxr-xr-x 1,223 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env php
<?php
/**
 * Copyright 2011-2014 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 tag to delete.');
}

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->findOne(array('tag_name' => $tag));
    if (!$t) {
        echo "$tag doesn't seem to exist, skipping it.\n";
        continue;
    }
    if ($t->delete()) {
        echo "Delete tag '$tag' (#".$t->tag_id.")\n";
        continue;
    } else {
        echo "Failed to delete '$tag'\n";
        exit(1);
    }
}
exit(0);