Skip to main content
summaryrefslogtreecommitdiffstats
blob: b61d4c014a0e6207a742d81f74c1f6aa5eb9e0fb (plain) (blame)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# Copyright (c) 2012 Frank Becker and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#     Frank Becker - initial API and implementation
#

package Bugzilla::Extension::Mylyn;
use strict;
use base qw(Bugzilla::Extension);
use constant MORE_SUB_CLASSES => qw(
    Bugzilla::Extension::Mylyn::Gerrit
    Bugzilla::Extension::Mylyn::Git
 );
# This code for this is in ./extensions/Mylyn/lib/Util.pm
use Bugzilla::Extension::Mylyn::Util;

use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Product;
use Bugzilla::FlagType;

use Data::Dumper;

our $VERSION = '0.01';

<% if @custom_wf %>
use constant STATUS_WORKFLOW => (
	['IN_PROGRESS','UNCONFIRMED'],
	['CONFIRMED','VERIFIED'],
);
use constant STATUS_WORKFLOW_DELETE => (
	['IN_PROGRESS','CONFIRMED'],
);
<% end %>
<% if @custom_wf_and_status %>
use constant STATUS_WORKFLOW => (
	['VERIFIED','MODIFIED'],
	['ON_DEV','POST'],
	['MODIFIED','ON_DEV'],
);
use constant STATUS_WORKFLOW_DELETE => (
	['UNCONFIRMED','ASSIGNED'],
	['RESOLVED','UNCONFIRMED'],
	['VERIFIED','UNCONFIRMED'],
);
<% end %>

sub install_before_final_checks {
	my ($self, $args) = @_;
	print "Mylyn Extension: install-before_final_checks hook\n" unless $args->{silent};

	my $dbh = Bugzilla->dbh;
	if (!$dbh->selectrow_array('SELECT 1 FROM profiles where userid > 1')) {
		print "create additional profiles...\n" unless $args->{silent};

		# create tests@mylyn.eclipse.org
		# add this user to group bz_canusewhineatothers
		my $testu = Bugzilla::User->create({ login_name    => 'tests@mylyn.eclipse.org', 
<% if  @envversionInternal >= "5.1" %>

											 email         => 'tests@mylyn.eclipse.org',
<% end %>
											 realname      => 'Mylyn Test',
											 cryptpassword => 'mylyntest' });
		my $private_group = new Bugzilla::Group({name => 'bz_canusewhineatothers'});		
		my $sth = $dbh->prepare( "INSERT INTO user_group_map
								 (user_id, group_id, isbless, grant_type)
								 VALUES (?, ?, ?, ?)");
		$sth->execute($testu->id, $private_group->id, 0, GRANT_DIRECT);

		# create guest@mylyn.eclipse.org		
		Bugzilla::User->create({ login_name    => 'guest@mylyn.eclipse.org', 
<% if  @envversionInternal >= "5.1" %>
		email         => 'guest@mylyn.eclipse.org',
<% end %>
		realname      => 'Mylyn guest',
		cryptpassword => 'mylyntest' });
	}

	# create two new products
	if (!$dbh->selectrow_array('SELECT 1 FROM products where id > 1')) {
		print "create additional products...\n" unless $args->{silent};

		# Get the user who will be the owner of the Component.
		# We pick the tests@mylyn.eclipse.org, which is the
		# user Extension.pl just created.

		my ($testuser_id)  = $dbh->selectrow_array(
			'SELECT userid FROM profiles WHERE login_name = ? ' ,
			undef, 'tests@mylyn.eclipse.org');
		my $testuser = Bugzilla::User->new($testuser_id);

		my $product2 = Bugzilla::Product->create({
											name => 'Product with Spaces',
											description => 'Product with Spaces is the renamed Scratch Product.',
											version => Bugzilla::Version::DEFAULT_VERSION,
											classification => 'Unclassified',
											defaultmilestone => DEFAULT_MILESTONE,
						});
		Bugzilla::Component->create({ %{ ({
											name => 'Component 1',
											description => '1'
										}) },
										product => $product2,
            							initialowner => $testuser->login });
		Bugzilla::Component->create({ %{ ({
											name => 'Component 2',
											description => '2'
										}) },
										product => $product2,
										initialowner => $testuser->login });

		Bugzilla::Version->create({ <%= @VersionCreateName %> => 'a', product => $product2 });
		Bugzilla::Version->create({ <%= @VersionCreateName %> => 'b', product => $product2 });
		Bugzilla::Version->create({ <%= @VersionCreateName %> => 'c', product => $product2 });
		Bugzilla::Milestone->create({ <%= @VersionCreateName %> => 'M1.0', product => $product2 });
		Bugzilla::Milestone->create({ <%= @VersionCreateName %> => 'M2.0', product => $product2 });
		Bugzilla::Milestone->create({ <%= @VersionCreateName %> => 'M3.0', product => $product2 });

		my $product3 = Bugzilla::Product->create({
											name => 'ManualTest',
											description => 'Product for manual testing',
											version => Bugzilla::Version::DEFAULT_VERSION,
											classification => 'Unclassified',
											defaultmilestone => DEFAULT_MILESTONE,
											allows_unconfirmed => 0,
						});
		Bugzilla::Component->create({ %{ ({
											name => 'ManualC1',
											description => '1'
										}) },
										product => $product3,
									initialowner => $testuser->login });
		Bugzilla::Component->create({ %{ ({
											name => 'ManualC2',
											description => '2'
										}) },
										product => $product3,
									initialowner => $testuser->login });
 
		Bugzilla::Version->create({ <%= @VersionCreateName %> => 'R1', product => $product3 });
		Bugzilla::Version->create({ <%= @VersionCreateName %> => 'R1.1', product => $product3 });
		Bugzilla::Version->create({ <%= @VersionCreateName %> => 'R2.0', product => $product3 });
		Bugzilla::Milestone->create({ <%= @VersionCreateName %> => 'M1', product => $product3 });
		Bugzilla::Milestone->create({ <%= @VersionCreateName %> => 'M2', product => $product3 });
		Bugzilla::Milestone->create({ <%= @VersionCreateName %> => 'M3', product => $product3 });
	}

	# create the needed custon fields
	if (!$dbh->selectrow_array('SELECT 1 FROM fielddefs where name like "cf_%"')) {
		print "create additional fielddefs...\n" unless $args->{silent};
		Bugzilla::Field->create({ %{ ({
				description => 'free text custom field',
				type        => 1,
				sortkey     => 351,
				mailhead    => 1,
				enter_bug   => 1,
				obsolete    => 0,
				buglist     => 1,
			}) },
			name => 'cf_freetext', custom => 1
		});
		Bugzilla::Field->create({ %{ ({
				description => 'drop down custom field',
				type        => 2,
				sortkey     => 451,
				mailhead    => 1,
				enter_bug   => 1,
				obsolete    => 0,
				buglist     => 1,
			}) },
			name => 'cf_dropdown', custom => 1
		});

		# create the options for cf_dropdown		
		Bugzilla::Field::Choice->type('cf_dropdown')->create({
			value   => 'one', 
			sortkey => 0,
			is_open => 1,
		});
		Bugzilla::Field::Choice->type('cf_dropdown')->create({
			value   => 'two', 
			sortkey => 0,
			is_open => 1,
		});
		Bugzilla::Field::Choice->type('cf_dropdown')->create({
			value   => 'three', 
			sortkey => 0,
			is_open => 1,
		});
		
		Bugzilla::Field->create({ %{ ({
				description => 'large text box custom field',
				type        => 4,
				sortkey     => 551,
				mailhead    => 1,
				enter_bug   => 1,
				obsolete    => 0,
				buglist     => 1,
			}) },
			name => 'cf_largetextbox', custom => 1
		});
		Bugzilla::Field->create({ %{ ({
				description => 'multi selection box custom field',
				type        => 3,
				sortkey     => 651,
				mailhead    => 1,
				enter_bug   => 1,
				obsolete    => 0,
				buglist     => 1,
			}) },
			name => 'cf_multiselect', custom => 1
		});

		# create the options for cf_multiselect		
		Bugzilla::Field::Choice->type('cf_multiselect')->create({
			value   => 'Blue', 
			sortkey => 0,
			is_open => 1,
		});
		Bugzilla::Field::Choice->type('cf_multiselect')->create({
			value   => 'Green', 
			sortkey => 0,
			is_open => 1,
		});
		Bugzilla::Field::Choice->type('cf_multiselect')->create({
			value   => 'Red', 
			sortkey => 0,
			is_open => 1,
		});
		Bugzilla::Field::Choice->type('cf_multiselect')->create({
			value   => 'Yellow', 
			sortkey => 0,
			is_open => 1,
		});

		Bugzilla::Field->create({ %{ ({
				description => 'date time custom field',
				type        => 5,
				sortkey     => 751,
				mailhead    => 1,
				enter_bug   => 1,
				obsolete    => 0,
				buglist     => 1,
			}) },
			name => 'cf_datetime', custom => 1
		});
		Bugzilla::Field->create({ %{ ({
				description => 'bug id custom field',
				type        => 6,
				sortkey     => 851,
				mailhead    => 1,
				enter_bug   => 1,
				obsolete    => 0,
				buglist     => 1,
			}) },
			name => 'cf_bugid', custom => 1
		});
	}
#	if (!$dbh->selectrow_array('SELECT 1 FROM bug_status where value = "test"')) {
#		print "Anlegen von Status!!!!\n" unless $args->{silent};
#		Bugzilla::Status->create({ value => 'test', is_open => 0 });
#	}

	if (!$dbh->selectrow_array('SELECT 1 FROM flagtypes')) {
		print "create additional flagtypes...\n" unless $args->{silent};
		my $flagtype = Bugzilla::FlagType->insert_create_data({
			name        => 'BugFlag1',
			description => '1',
			target_type => 'bug',
			cc_list     => '',
			sortkey     => 1,
			is_active   => 1,
			is_requestable   => 0,
			is_requesteeble  => 0,
			is_multiplicable => 0,
		});
		# set the inclusion to __Any__:__Any__
		my $sth = $dbh->prepare("INSERT INTO flaginclusions
				(type_id, product_id, component_id) VALUES (?, ?, ?)");
		$sth->execute(bless($flagtype,, 'Bugzilla::FlagType' )->id, undef, undef);

		$flagtype = Bugzilla::FlagType->insert_create_data({
			name        => 'BugFlag2',
			description => '2',
			target_type => 'bug',
			cc_list     => '',
			sortkey     => 1,
			is_active   => 1,
			is_requestable   => 1,
			is_requesteeble  => 0,
			is_multiplicable => 0,
		});
		# set the inclusion to __Any__:__Any__
		$sth = $dbh->prepare("INSERT INTO flaginclusions
				(type_id, product_id, component_id) VALUES (?, ?, ?)");
		$sth->execute(bless($flagtype,, 'Bugzilla::FlagType' )->id, undef, undef);

		$flagtype = Bugzilla::FlagType->insert_create_data({
			name        => 'AttachmentFlag1',
			description => '1',
			target_type => 'attachment',
			cc_list     => '',
			sortkey     => 1,
			is_active   => 1,
			is_requestable   => 1,
			is_requesteeble  => 1,
			is_multiplicable => 1,
		});
		# set the inclusion to __Any__:__Any__
		$sth = $dbh->prepare("INSERT INTO flaginclusions
				(type_id, product_id, component_id) VALUES (?, ?, ?)");
		$sth->execute(bless($flagtype,, 'Bugzilla::FlagType' )->id, undef, undef);

		$flagtype = Bugzilla::FlagType->insert_create_data({
			name        => 'AttachmentFlag2',
			description => '2',
			target_type => 'attachment',
			cc_list     => '',
			sortkey     => 1,
			is_active   => 1,
			is_requestable   => 1,
			is_requesteeble  => 1,
			is_multiplicable => 1,
		});
		# set the inclusion to __Any__:__Any__
		$sth = $dbh->prepare("INSERT INTO flaginclusions
				(type_id, product_id, component_id) VALUES (?, ?, ?)");
		$sth->execute(bless($flagtype,, 'Bugzilla::FlagType' )->id, undef, undef);

		$flagtype = Bugzilla::FlagType->insert_create_data({
			name        => 'BugFlag3',
			description => '3',
			target_type => 'bug',
			cc_list     => '',
			sortkey     => 1,
			is_active   => 1,
			is_requestable   => 1,
			is_requesteeble  => 0,
			is_multiplicable => 1,
		});
		# set the inclusion to __Any__:__Any__
		$sth = $dbh->prepare("INSERT INTO flaginclusions
				(type_id, product_id, component_id) VALUES (?, ?, ?)");
		$sth->execute(bless($flagtype,, 'Bugzilla::FlagType' )->id, undef, undef);

		$flagtype = Bugzilla::FlagType->insert_create_data({
			name        => 'BugFlag4',
			description => '4',
			target_type => 'bug',
			cc_list     => '',
			sortkey     => 1,
			is_active   => 1,
			is_requestable   => 1,
			is_requesteeble  => 1,
			is_multiplicable => 1,
		});
		# set the inclusion to __Any__:__Any__
		$sth = $dbh->prepare("INSERT INTO flaginclusions
				(type_id, product_id, component_id) VALUES (?, ?, ?)");
		$sth->execute(bless($flagtype,, 'Bugzilla::FlagType' )->id, undef, undef);
	}

	if (!$dbh->selectrow_array('SELECT 1 FROM keyworddefs')) {
		print "create additional keyworddefs...\n" unless $args->{silent};
		Bugzilla::Keyword->create({ name => 'Keyword1', description => '1' });
		Bugzilla::Keyword->create({ name => 'Keyword2', description => '2' });
	}
<% if @custom_wf %>
	my %status_ids = @{ $dbh->selectcol_arrayref(
		'SELECT value, id FROM bug_status', {Columns=>[1,2]}) };
		my $old_id =  $status_ids{'IN_PROGRESS'};
		my $new_id = $status_ids{'UNCONFIRMED'};
    if (!$dbh->selectrow_array('SELECT 1 FROM status_workflow where old_status = '. $old_id . ' and new_status = '.$new_id)) {
		print "create additional status_workflow...\n" unless $args->{silent};
		my $sth_insert = $dbh->prepare('INSERT INTO status_workflow (old_status, new_status)
										VALUES (?, ?)');
		my $sth_delete = $dbh->prepare('DELETE FROM status_workflow
										WHERE old_status = ? AND new_status = ?');

		foreach my $pair (STATUS_WORKFLOW) {
			my $old_id = $pair->[0] ? $status_ids{$pair->[0]} : undef;
			my $new_id = $status_ids{$pair->[1]};
			$sth_insert->execute($old_id, $new_id);
		}
		foreach my $pair (STATUS_WORKFLOW_DELETE) {
			my $old_id = $pair->[0] ? $status_ids{$pair->[0]} : undef;
			my $new_id = $status_ids{$pair->[1]};
			$sth_delete->execute($old_id, $new_id);
		}
	}
<% end %>
<% if @custom_wf_and_status %>
	if (!$dbh->selectrow_array('SELECT 1 FROM bug_status where value = "ON_DEV"')) {
		print "Anlegen von Status!!!!\n" unless $args->{silent};
		Bugzilla::Status->create({ value => 'ON_DEV', is_open => 1 , sortkey => 800});
		Bugzilla::Status->create({ value => 'POST', is_open => 0 , sortkey => 900});
		Bugzilla::Status->create({ value => 'MODIFIED', is_open => 1 , sortkey => 1200});
	}
	my %status_ids = @{ $dbh->selectcol_arrayref(
		'SELECT value, id FROM bug_status', {Columns=>[1,2]}) };
		my $old_id =  $status_ids{'IN_PROGRESS'};
		my $new_id = $status_ids{'UNCONFIRMED'};
    if (!$dbh->selectrow_array('SELECT 1 FROM status_workflow where old_status = '. $old_id . ' and new_status = '.$new_id)) {
		print "create additional status_workflow...\n" unless $args->{silent};
		my $sth_insert = $dbh->prepare('INSERT INTO status_workflow (old_status, new_status)
										VALUES (?, ?)');
		my $sth_delete = $dbh->prepare('DELETE FROM status_workflow
										WHERE old_status = ? AND new_status = ?');
    	my $sth_delnul = $dbh->prepare('DELETE FROM status_workflow
                                    WHERE old_status IS NULL AND new_status = ?');
		foreach my $pair (STATUS_WORKFLOW) {
			my $old_id = $pair->[0] ? $status_ids{$pair->[0]} : undef;
			my $new_id = $status_ids{$pair->[1]};
			if (!$dbh->selectrow_array('SELECT 1 FROM status_workflow where old_status ='. $old_id . ' and new_status ='.$new_id)) {
				$sth_insert->execute($old_id, $new_id);
			}
		}
		foreach my $pair (STATUS_WORKFLOW_DELETE) {
			my $old_id = $pair->[0] ? $status_ids{$pair->[0]} : undef;
			my $new_id = $status_ids{$pair->[1]};
			$sth_delete->execute($old_id, $new_id);
		}
		my $new_id = $status_ids{'ASSIGNED'};
		$sth_delnul->execute($new_id);
	}
<% end %>
	
	print "Mylyn Extension: end of install-before_final_checks hook\n" unless $args->{silent};
}

sub bug_url_sub_classes {
    my ($self, $args) = @_;
    push @{ $args->{sub_classes} }, MORE_SUB_CLASSES;
}

__PACKAGE__->NAME;

Back to the top