-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_new_stats.php
More file actions
411 lines (396 loc) · 13.3 KB
/
create_new_stats.php
File metadata and controls
411 lines (396 loc) · 13.3 KB
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
<?php
/*
#===================================================================================
# BAM Manager (Bugzilla Automated Metrics Manager): index.php
#
# Copyright 2011, Comarch SA
# Maintainers: Krystian Jedrzejowski <krystian.jedrzejowski@comarch.com>,
# Kamil Marek <kamil.marek@comarch.com>
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
#
# Date: Thu Jul 13 11:56:00 EET 2011
#===================================================================================
*/
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['path'])) {
system("sudo lib/libcontentaction.pl --start $login 'Create statistic'");
//New products variables (create_list_of_products.php file)
$list_name = $_POST['list_name'];
$add_products = $_POST['add_products'];
//Common variables
$path_of_conf_file= trim($_POST['path']);
$file_check = file_exists($path_of_conf_file);
$common_params = $common_parameters_file;
$bz_search = trim($_POST['bz_search']);
$name_of_stats = trim($_POST['name_of_stats']);
$existing_list = $_POST['existing_list'];
$subset_from_date = trim($_POST['subset_from_date']);
$classification = $_POST['classification'];
$lunch_method = $_POST['lunch_method'];
$subset_path = $_POST['subset_path'];
//Searching BZ search parameter in subset of file.
if($subset_path){
$subset_bz_search = searchString($subset_path, "BUGZILLA_URL_COMMON_PARAMS");
}
//Searching name of statistic in subset of file.
if($subset_path){
$subset_statistic_name = searchString($subset_path, "STATISTICS");
}
//Defining form array
if (!$file_check){
$list_name_empty = $list_name;
if($list_name_empty){
$products_file_check = file_exists($list_path = $path_to_products_directory . $list_name);
}
else{
$products_file_check = 0;
}
if(!$products_file_check){
$k = 0;
if($common_params){
$field_arr[$k] = "COMMON_PARAMS_FILE = ".$common_params;
$k++;
}
if($bz_search){
$field_arr[$k] = "BUGZILLA_URL_COMMON_PARAMS = ".$bz_search;
$k++;
}
elseif($subset_path){
$field_arr[$k] = "BUGZILLA_URL_COMMON_PARAMS = ".$subset_bz_search;
$k++;
}
if($name_of_stats){
$field_arr[$k] = "STATISTICS = ".$name_of_stats;
$k++;
}
if($existing_list){
$field_arr[$k] = "PRODUCTS_CONFIG_FILE = ".$existing_list;
$k++;
}
else{
//Creating list of products if chosen
$list_temp_file = 'tmp/'.rand();
saveToFile($list_temp_file, $add_products);
system("sudo lib/libcontentaction.pl --move $list_temp_file $list_path");
$field_arr[$k] = "PRODUCTS_CONFIG_FILE = ".$list_path;
$k++;
}
if($subset_path){
$field_arr[$k] = "SUBSET_OF = ".$subset_statistic_name;
$k++;
}
if($classification){
$field_arr[$k] = "INCOMPLETE_CLASSIFICATION = ".$classification;
$k++;
}
//Creating conf file
$create_config_temp_file = 'tmp/' . rand();
$complete_create_config_file = implode("\n", $field_arr);
file_put_contents($create_config_temp_file, $complete_create_config_file);
system("sudo lib/libcontentaction.pl --move $create_config_temp_file $path_of_conf_file");
//Adding lunch line to fetch_statistics.sh
$fetch = 'fetch_statistics_from_bugzilla.pl '.$path_of_conf_file;
$fetch=str_replace(' ', '__space__',$fetch);
system("sudo lib/libcontentaction.pl --save $fetch_statistics_file $fetch");
//Decide when statistic runs.
if($lunch_method == 'run_now' && !$subset_path){
//Lunch statistic now
$path = searchString($common_parameters_file, "STATS_URL_BASE");
$command = "lib/libcontentaction.pl --fetch $statistics_user $fetch_statistics_from_bugzilla_file $path_of_conf_file";
exec("sudo $command", &$output, &$return_var);
/*
// check whether fetching was successful
if ($return_var == 9) {
echo 'OK';
}
else {
echo 'ERROR';
}
*/
echo'
<fieldset id="interior" style="width:700px; margin: auto; padding: 20px;">
<legend>
Statistic has been successfully created
</legend>
Statistic has been created: <a href="'. $path ."?s=".$name_of_stats .'" target="_blank">
'. $path ."?s=". $name_of_stats .'</a>
 Check <a href="#" onclick="handleWantsList(false)">syslog</a> for details.
<br><br>
<a href="?tab=create_new_stats">Back to Create Form</a>
</fieldset>
';
echo'
<br>
<div id="list_false" style="display:none; width:100%; height: 310px; margin: auto;">
<fieldset id="interior" style="width:99%; height: 300px; margin:auto;"><legend>Syslog</legend>
<div class="scroll">
';
$syslog = loadFileContentToVariable('log/syslog');
$syslog = explode("\n",$syslog);
echo'
<p>' . displayArray($syslog) . '</p>
';
echo'
</div>
</fieldset><br>
</div>
<br><br>
';
}
elseif($lunch_method == 'run_now' && $subset_path){
//Lunch subset of
$path = searchString($common_parameters_file, "STATS_URL_BASE");
$dir_bin = dirname($fetch_statistics_from_bugzilla_file);
$create_subset_file = $dir_bin . "/create_subset.pl";
$create_subset_file = trim($create_subset_file);
$command_subset = "lib/libcontentaction.pl --subset $create_subset_file $path_of_conf_file $subset_from_date $statistics_user";
exec("sudo $command_subset", &$output, &$return_var);
/*
// check whether fetching was successful
if ($return_var == 9) {
echo 'OK';
}
else {
echo 'ERROR';
}
*/
echo'
<fieldset id="interior" style="width:700px; margin: auto; padding: 20px;">
<legend>
Statistic has been successfully created
</legend>
Statistic has been created:
<a href="'. $path ."?s=".$name_of_stats .'" target="_blank">
"'. $path ."?s=".$name_of_stats .'"
</a>
 Check <a href="#" onclick="handleWantsList(false)">syslog</a> for details.
<br><br>
<a href="?tab=create_new_stats">Back to Create Form</a>
</fieldset>
';
echo'
<br>
<div id="list_false" style="display:none; width:100%; height: 310px; margin: auto;">
<fieldset id="interior" style="width:99%; height: 300px; margin:auto;"><legend>Syslog</legend>
<div class="scroll">
';
$syslog = loadFileContentToVariable('log/syslog');
$syslog = explode("\n",$syslog);
echo'
<p>' . displayArray($syslog) . '</p>
';
}
elseif($lunch_method == 'run_auto'){
$path = searchString($common_parameters_file, "STATS_URL_BASE");
echo'
<fieldset id="interior" style="width:700px; margin: auto; padding: 20px;">
<legend>
Files have been successfully created
</legend>
Files have been created. Wait for next automatic run to see metrics under
<a href="'. $path ."?s=".$name_of_stats .'" target="_blank">
"'. $path ."?s=".$name_of_stats .'"</a>
<br><br>
<a href="?tab=create_new_stats">
Back to Create Form
</a>
</fieldset>
';
}
system("sudo lib/libcontentaction.pl --end $login 'Create statistic'");
}
else{
echo'
<fieldset id="interior" style="width:700px; margin: auto; padding: 20px;">
<legend>
Error
</legend>
Products file with specified name already exists. Please change name of products file.
<br><br>
<b>Press browser back button to correct file name.</b>
</fieldset>
';
}
}
else{
echo'
<fieldset id="interior" style="width:700px; margin: auto; padding: 20px;">
<legend>
Error
</legend>
File with specified name already exists. Please change name of file.
<br><br>
<b>Press browser back button to correct file name.</b>
</fieldset>
';
}
}
else {
echo'
<fieldset id="interior">
<legend>Create new statistics</legend>
<form name="create_form" action="index.php?tab=create_new_stats" method="POST"><br>
<table class="create" border="0"><br>
<tr>
<td class="left">
*Name of configuration file:
</td>
<td class="center_create">
<input type="button" name="browse" value="Browse" onclick="showFileTree()" />
<span id="inactive_path" style="padding: 2px"></span>
<input class="input_text" type="hidden" name="path" />
</td>
</tr>
<tr>
<td class="left">
*Bugzilla search:
</td>
<td class="center_create">
<input class="input_text" type="text" name="bz_search" />
<input class="input_text" type="hidden" name="bz_search_hidden" />
</td>
<td class="help">
<ul>?
<li>
Please provide bugzilla search parameters:<br> e.g. "bug_severity=blocker,critical,major,normal,minor,task&classification=Harmattan"
</li>
</ul>
</td>
</tr>
<tr>
<td class="left">
*Name of statistic:
</td>
<td class="center_create">
<input class="input_text" type="text" name="name_of_stats"/>
</td>
<td class="help">
<ul>?
<li>
Please specify name of statistic. Name has an affect on displaying statistics in subgroups.<br>Signs "_-_" divides into a subgroups e.g. Harmattan_with_PR1.2_flag_-_OS_-_Adaptation
</li>
</ul>
</td>
</tr>
<tr>
<td class="left">
*List of products:
</td>
<td class="center_create">
<input type="button" name="browse" value="Browse" id="browseProducts" onclick="showProductsTree()" />
<span id="inactive_products" style="padding: 2px"></span>
<input class="input_text" type="hidden" name="existing_list" />
</td>
</tr>
</table><br>
';
//Create list of products
$subpage = loadFileContentToVariable('create_list_of_products.php');
eval("?>".$subpage."<?php ");
echo'
<hr>
<table class="create"><br>
<tr>
<td rowspan="2" style="width:75px" align="right">
<input type="checkbox" name="subset_check" value="custom" onChange="enableField()">
</td>
<td style="width:200px" align="right">
Subset of:
</td>
<td>
<input id="subsetBrowse" type="button" disabled name="browse" value="Browse" onclick="showSubsetTree()" />
<span id="inactive_subset" style="padding: 2px"></span>
<input class="input_text" type="hidden" name="subset_path">
<input class="input_text" type="hidden" name="subset_path_hidden" />
</td>
</tr>
<tr>
<td style="width:150px" align="right">
Retrieve history from date:
</td>
<td class="center_create">
<input class="input_text" disabled type="text" name="subset_from_date" placeholder="YYYY-MM-DD"/>
<input class="input_text" type="hidden" name="subset_from_date_hidden" />
</td>
<td class="help">
<ul>?
<li>
Help text
</li>
</ul>
</td>
</tr>
</table><br>
<hr>
<table class="create"><br>
<tr>
<td class="left">
Incomplete classification:
<br>
<a href="#" class="classification" onClick="uncheck()" style="margin-left:20px;">>Uncheck all<</a>
</td>
<td>
<input type="radio" name="classification" value="true"> True
<br>
<input type="radio" name="classification" value="false"> False
</td>
</tr>
</table><br>
<hr>
<table class="create"><br>
<tr>
<td class="left">
*Define run method:
</td>
<td>
<input type="radio" id="run_now" name="lunch_method" value="run_now"> Run statistics now
<br>
<input type="radio" id="run_auto" name="lunch_method" value="run_auto"> Wait for automatic run (time of automatic run defined in settings)
</td>
</tr>
</table><br>
</fieldset>
<table id="submit_button_table" align="right" style="overflow: auto; width: 100%">
<tr>
<td style="width: 100px;">
<p align="right">
<input style="margin-top: 1px; margin-right: 0px;" valign="right" type="button" name="create_new_statistics" value="Create statistics" onclick="createCheckMandatoryFields()" />
</td>
</tr>
</table>
<br><br>
</form>
';
}
?>
<script type="text/javascript">
/*Shows whole statistic tree (statistics || subsets)*/
$(document).ready( function() {
$('#fileTree').fileTree({
root: '<?php echo $path_to_statistics_directory; ?>',
script: 'lib/file_tree/jqueryCreateFileTree.php'
},
function(file) {
createFile(file);
});
});
/*Shows products tree*/
$(document).ready( function() {
$('#productsFileTree').fileTree({
root: '<?php echo $path_to_products_directory; ?>',
script: 'lib/file_tree/jqueryProductsFileTree.php'
},
function(file) {
chooseProducts(file);
});
});
/*Shows subset tree*/
$(document).ready( function() {
$('#subsetFileTree').fileTree({
root: '<?php echo $path_to_statistics_directory; ?>',
script: 'lib/file_tree/jquerySubsetsFileTree.php'
},
function(file) {
chooseSubset(file);
});
});
</script>