-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag_info.sh
executable file
·102 lines (78 loc) · 3.64 KB
/
tag_info.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# Globale Variablen
SCRIPTNAME=$(basename $0 .sh)
EXIT_SUCCESS=0
EXIT_FAILURE=1
EXIT_ERROR=2
EXIT_BUG=10
#usage
#tag_info id_[name] [Kategorien ...]
source ${0%/*}/config
# noch erstes element entfernen - da infoname
for element in "$@"
do
if [ "$element" == "$1" ]
then
#infoname=$element
id=`echo "$1" | awk -F'_' '//{print $NF}'`
else
category_name="'`basename $element`'"
#TODO clean solution
## if [[ "$WORD" =~ ^(a|b|c)$ ]]; then
## if [[ "$category_name" =~ ^(`echo $ramdisk/category | sed "s/ /|/g"`)$ ]]; then
# Problem if you try to extract categories from infoname
#if [[ `echo $ramdisk/category/*` != "* $category_name *" ]]
# then
#add_category $element;
#fi
# 2013-04-02 msoon: only using item_id and prevent adding parent categorys
dbquery="select id from category where (lower(name)=lower($category_name) OR id in (select category.id from category, category_alias where category.id=category_alias.category_id and lower(category_alias.name)=lower($category_name))) and
id not in
(
select distinct parent from category where
id in (select category_id from category_info where item_id=$id)
OR
id in (select distinct parent from category where id in (select category_id from category_info where item_id=$id) )
OR
id in (select parent from category where id in (select distinct parent from category where id in (select category_id from category_info where item_id=$id) ))
OR
id in (select parent from category where id in ( select parent from category where id in (select distinct parent from category where id in (select category_id from category_info where item_id=$id) )))
OR
id in (select parent from category where id in (select parent from category where id in ( select parent from category where id in (select distinct parent from category where id in (select category_id from category_info where item_id=$id) )))
)
)"
if [[ $VERBOSE = y ]] ; then
echo dbquery: "$dbquery;"
echo ""
echo -e "\E[35mcategory to add: `sqlite3 \"$database\" \"select name from category where id in ($dbquery);\"`"; tput sgr0
fi
sqlite3 "$database" "insert into category_item (category_id,item_id,item_type_id) values (($dbquery),$id,1);" 2> /dev/null
# to delete parents if subcategory is added
dbquery="select name from category where
id in
(
select distinct parent from category where
id in (select id from category where lower(name)=lower($category_name))
OR
id in (select parent from category where id in (select id from category where lower(name)=lower($category_name)) )
OR
id in (select parent from category where id in (select parent from category where id in (select id from category where lower(name)=lower($category_name)) ))
OR
id in (select parent from category where id in ( select parent from category where id in (select parent from category where id in (select id from category where lower(name)=lower($category_name)) )))
OR
id in (select parent from category where id in (select parent from category where id in ( select parent from category where id in (select parent from category where id in (select id from category where lower(name)=lower($category_name)) )))));"
if [[ $VERBOSE = y ]] ; then
echo dbquery: $dbquery
echo ""
fi
sqlite3 "$database" "$dbquery" | xargs echo > $ramdisk/rm_tag_categorys
if [[ $VERBOSE = y ]] ; then
echo -e "\E[35mcategorys to remove: `cat \"$ramdisk/rm_tag_categorys\"`"; tput sgr0
echo ""
fi
rm_tag_info "$id" `cat $ramdisk/rm_tag_categorys`
if [[ $USE_HISTORY = y ]] ; then
sqlite3 $database "insert into history (item_id,item_type_id,categories,zones,timestamp,command) values ($id) ,1,`echo $category_name | sed "s/','/,/g"`,$zones,(select datetime()),'$SCRIPTNAME');"
fi
fi
done