Thread MySQL Abfrage in Bugzilla Template einbauen (4 answers)
Opened by Frederic_S at 2010-11-16 13:47

Frederic_S
 2010-11-16 13:47
#142775 #142775
User since
2010-11-16
2 Artikel
BenutzerIn
[default_avatar]
Hallo zusammen!

Ich bin mit der grandiosen Aufgabe beauftragt worden, Bugzilla für die Firma anzupassen. Hierzu muss ich eine Reihe von Templates verändern und u.a. maßgeschneiderte Queries einbauen. Leider verstehe ich recht wenig von Perl - ich komme eigentlich aus dem PHP Bereich.

Ein typisches Bugzilla Template sieht so aus:

Code: (dl )
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  <table class="bz_buglist" cellspacing="0" cellpadding="4" width="100%">
<tr class="bz_buglist_header bz_first_buglist_header">
[% IF dotweak %]
<th>&nbsp;</th>
[% END %]
<th colspan="[% splitheader ? 2 : 1 %]" class="first-child">
<a href="buglist.cgi?
[% urlquerypart FILTER html %]&amp;order=
[% PROCESS new_order id='bug_id' %]
[%-#%]&amp;query_based_on=
[% defaultsavename OR searchname FILTER url_quote %]">ID
[% PROCESS order_arrow id='bug_id' ~%]
</a>
</th>

[% IF splitheader %]

[% FOREACH id = displaycolumns %]
[% NEXT UNLESS loop.count() % 2 == 0 %]
[% column = columns.$id %]
[% PROCESS columnheader %]
[% END %]

</tr><tr class="bz_buglist_header">
[% IF dotweak %]
<th>&nbsp;</th>
[% END %]
<th>&nbsp;</th>

[% FOREACH id = displaycolumns %]
[% NEXT IF loop.count() % 2 == 0 %]
[% column = columns.$id %]
[% PROCESS columnheader %]
[% END %]

[% ELSE %]

[% FOREACH id = displaycolumns %]
[% column = columns.$id %]
[% PROCESS columnheader %]
[% END %]

[% END %]

</tr>
[% END %]

[% BLOCK columnheader %]
<th colspan="[% splitheader ? 2 : 1 %]">
<a href="buglist.cgi?[% urlquerypart FILTER html %]&amp;order=
[% PROCESS new_order %]
[%-#%]&amp;query_based_on=
[% defaultsavename OR searchname FILTER url_quote %]">
[%- abbrev.$id.title || field_descs.$id || column.title -%]
[% PROCESS order_arrow ~%]
</a>
</th>
[% END %]

[% BLOCK new_order %]
[% desc = '' %]
[% IF (om = order.match("\\b$id( DESC)?")) %]
[% desc = ' DESC' IF NOT om.0 %]
[% END %]
[% id _ desc FILTER url_quote %]
[% IF id != 'bug_id' AND order %]
[% ',' _ order.remove("\\b$id( DESC)?(,\\s*|\$)") FILTER url_quote %]
[% END %]
[% END %]

[% BLOCK order_arrow %]
[% IF order.match("^$id DESC") %]
<span class="bz_sort_order_primary">&#x25BC;</span>
[% ELSIF order.match("^$id(,\\s*|\$)") %]
<span class="bz_sort_order_primary">&#x25B2;</span>
[% ELSIF order.match("\\b$id DESC") %]
<span class="bz_sort_order_secondary">&#x25BC;</span>
[% ELSIF order.match("\\b$id(,\\s*|\$)") %]
<span class="bz_sort_order_secondary">&#x25B2;</span>
[% END %]
[% END %]

[%############################################################################%]
[%# Bug Table #%]
[%############################################################################%]

[% tableheader %]

[% FOREACH bug = bugs %]
[% count = loop.count() %]

<tr class="bz_bugitem
bz_[% bug.bug_severity FILTER css_class_quote -%]
bz_[% bug.priority FILTER css_class_quote -%]
bz_[% bug.bug_status FILTER css_class_quote -%]
[%+ "bz_$bug.resolution" FILTER css_class_quote IF bug.resolution -%]
[%+ "bz_secure" IF bug.secure_mode -%]
[%+ "bz_secure_mode_$bug.secure_mode" FILTER css_class_quote IF bug.secure_mode -%]
[%+ count % 2 == 1 ? "bz_row_odd" : "bz_row_even" -%]
">

[% IF dotweak %]
<td class="bz_checkbox_column">
<input type="checkbox" name="id_[% bug.bug_id %]">
</td>
[% END %]
<td class="first-child bz_id_column">
<a name="b[% bug.bug_id %]"
href="show_bug.cgi?id=[% bug.bug_id %]">[% bug.bug_id %]</a>
<span style="display: none">[%+ '[SEC]' IF bug.secure_mode %]</span>
</td>

[% FOREACH column = displaycolumns %]
<td [% 'style="white-space: nowrap"' IF NOT abbrev.$column.wrap %]
class="bz_[% column FILTER css_class_quote %]_column">
[% IF abbrev.$column.maxlength %]
<span title="[%- display_value(column, bug.$column) FILTER html %]">
[% END %]
[% IF abbrev.$column.format_value %]
[%- bug.$column FILTER format(abbrev.$column.format_value) FILTER html -%]
[% ELSIF column == 'actual_time' ||
column == 'remaining_time' ||
column == 'estimated_time' %]
[% PROCESS formattimeunit time_unit=bug.$column %][Waypoint 11]
[%# Display the login name of the user if their real name is empty. %]
[% ELSIF column.match('_realname$') && bug.$column == '' %]
[% SET login_column = column.remove('_realname$') %]
[% bug.${login_column}.truncate(abbrev.$column.maxlength,
abbrev.$column.ellipsis) FILTER html %]

[% ELSE %]
[%- display_value(column, bug.$column).truncate(abbrev.$column.maxlength, abbrev.$column.ellipsis) FILTER html -%]
[% END %]
[% IF abbrev.$column.maxlength %]
</span>
[% END %]
</td>
[% END %]

</tr>

[% IF loop.last() && time_info.time_present == 1 %]
[% PROCESS time_summary_line %]
[% END %]

[% END %]

</table>


Man sieht also, einzelne Befehle sind in [% %] gestellt.

Was ich nun erreichen möchte, ist das äquivalent zu dem PHP Befehl:

Code: (dl )
1
2
3
4
5
6
$BUG_CHECK = MYSQL_QUERY("SELECT bug_id FROM bugs WHERE product_id='$PRODUCT_ID'");

while($zeile = mysql_fetch_array($BUG_CHECK))
{
$BUG_ID = $zeile[bug_id];
}


Ich möchte also einen Wert aus der Datenbank auslesen und in eine Variable reinschreiben.

Die Query selbst habe ich bereits:

Code: (dl )
[% user_select = "SELECT userid FROM profiles WHERE login_name=user.login"; %]


Im Netz und in Büchern habe ich folgende Methode gefunden, meinen Wunsch zu realisieren:

Code: (dl )
1
2
3
[% execute = connect->query(user_select); %]

[% while (@results = execute->fetchrow()) {userid = results[0]} %]


Hier wird mir allerdings ein parse-error ausgegeben und das Skript wird abgebrochen, mit der Meldung:

Quote
file error - parse error - list/table.html.tmpl line 285: unexpected token (>) [% execute = connect->query(user_select); %]


Kann mir jemand hier vllt. weiterhelfen?

Grüße

Frederic
Last edited: 2010-11-16 14:02:32 +0100 (CET)

View full thread MySQL Abfrage in Bugzilla Template einbauen