-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefresh_statistics.php
More file actions
191 lines (172 loc) · 6.86 KB
/
refresh_statistics.php
File metadata and controls
191 lines (172 loc) · 6.86 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
<?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
#===================================================================================
*/
/*
# Action: Refresh selected statistics
# 1. Remove present-day raw_data files for selected statistics (one-by-one)
# 2. Fetch data for selected statistics (one-by-one)
*/
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['refresh_selected_statistics'])) {
$login = $_SESSION['logged in'];
system("sudo lib/libcontentaction.pl --start $login Refresh_statistics");
$list_of_statistics_to_refresh = $_POST['statistics_to_refresh'];
if ($list_of_statistics_to_refresh == "") {
$log_info = 'You apparently didn\'t choose any statistics to refresh.';
logToSyslog($log_info);
displayMessageFieldset('ERROR!', $log_info, '?tab=refresh_statistics');
}
else {
$list_of_statistics_to_refresh = explode(",", $list_of_statistics_to_refresh);
$number_of_selected_statistics_to_refresh = count($list_of_statistics_to_refresh);
$body = 'Status: <br>';
$success = true;
for($i=0; $i < $number_of_selected_statistics_to_refresh; $i++) {
//Remove present-day raw_data files for selected statistics
system("sudo lib/libcontentaction.pl --refresh $list_of_statistics_to_refresh[$i]");
//$command = "/var/www/bugzilla_statistics/manager/lib/libcontentaction.pl --fetch $fetch_statistics_from_bugzilla_file $list_of_statistics_to_refresh[$i]";
exec("sudo lib/libcontentaction.pl --fetch $statistics_user $fetch_statistics_from_bugzilla_file $list_of_statistics_to_refresh[$i]", &$output, &$return_var);
if ($return_var == 9) {
$body .= '<p>Updating' . $list_of_statistics_to_refresh[$i];
$body .= '<br>Success! Selected statistics has been updated<br>';
$path = searchString($common_parameters_file, "STATS_URL_BASE") . '?s=' . searchString($list_of_statistics_to_refresh[$i], "STATISTICS") . '&p=all';
$body .= '<a href = "' . $path . '" target="_blank">' . searchString($list_of_statistics_to_refresh[$i], "STATISTICS") . '</a></p>';
}
else {
$success = false;
$body .= 'Updating' . $list_of_statistics_to_refresh[$i];
$body .= '<br>ERROR occured while updating statistics.<br><br>';
}
}
if ($success == true) {
$body .= 'All selected statistics have been updated.';
displayMessageFieldset('Success!', $body, '?tab=refresh_statistics');
}
else {
$body .= 'Refresh of some statistics listed above has failed. Check <a href="#" onclick="handleWantsList(false)">syslog</a> for details.';
displayMessageFieldset('Status', $body, '?tab=refresh_statistics');
echo '
<br>
<div id="list_false" style="display:none; width:100%; height: 310px; margin: auto;">
<fieldset id="message_fieldset" style="width:99%; height: 300px;"><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>
';
}
}
system("sudo lib/libcontentaction.pl --end $login 'Refresh statistics'");
}
/*
# Action: Refresh ALL statistics
# 1. Remove present-day raw_data files for ALL statistics (at once)
# 2. Fetch data for ALL statistics (at once)
*/
else if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['refresh_all'])) {
system("sudo lib/libcontentaction.pl --start $login 'Refresh all statistics'");
//Remove present-day raw_data files for ALL statistics
// and then
//Fetch data for ALL statistics
exec("sudo lib/libcontentaction.pl --refresh-all $common_parameters_file $statistics_user $fetch_statistics_file", &$output, &$return_var);
// check whether refreshing was successfull
if ($return_var == 9) {
system("sudo lib/libcontentaction.pl --end $login 'Refresh all statistics'");
$path = searchString($common_parameters_file, "STATS_URL_BASE");
$body = 'All statistics have been succesfully refreshed. <br> <a href="' . $path . '?s="target="_blank">' . $path . '</a>';
displayMessageFieldset('Success!', $body, '?tab=refresh_statistics');
}
else {
$success = false;
$body = 'Refresh of some statistics has failed. Check <a href="#" onclick="handleWantsList(false)">syslog</a> for details.';
displayMessageFieldset('Status', $body, '?tab=refresh_statistics');
echo '
<br>
<div id="list_false" style="display:none; width:100%; height: 310px; margin: auto;">
<fieldset id="message_fieldset" style="width:99%; height: 300px;"><legend>Syslog</legend>
<div class="scroll">
';
system("sudo lib/libcontentaction.pl --end $login 'Refresh all statistics'");
$syslog = loadFileContentToVariable('log/syslog');
$syslog = explode("\n",$syslog);
echo '
<p>' . displayArray($syslog) . '</p>';
echo '
</div>
</fieldset><br>
</div>
<br><br>
';
}
}
/*
# Initial view of 'Refresh statistics tab'
# List of existing statistics
# And two buttons: Refres all & Refresh selected statistics
*/
else {
echo '
<form name="refresh_statistics" action="index.php?tab=refresh_statistics" method="POST">
<fieldset id="interior">
<legend>Statistics directory: ' . $path_to_statistics_directory . '</legend>
';
echo '
<div id="refreshFileTree" class="tree"></div>
<input type="hidden" class="input_text" name="statistics_to_refresh"/>
</fieldset>
<table align="right" style="overflow: auto; width: 100%" id="submit_button_table">
<tr>
<td style="width: 100px;">
<p align="right">
<input style="margin-top: 1px; margin-right: 0px;" type="submit" name="refresh_all" value="Refresh all" onClick="showSpinner()">
<input style="margin-top: 1px; margin-right: 0px;" type="submit" name="refresh_selected_statistics" value="Refresh selected statistics" onClick="showSpinner()">
</td>
</tr>
</table>
</form>
<br><br>
';
}
?>
<script type="text/javascript">
var statistics_to_refresh = new Array();
$(document).ready( function() {
$('#refreshFileTree').fileTree({
root: '<?php echo $path_to_statistics_directory; ?>',
script: 'lib/file_tree/jqueryFileTree.php',
multiFolder: 'true'
},
function(file) {
addSelectedToArray(file);
});
});
function addSelectedToArray(file) {
// check whether item is already selected
var idx = statistics_to_refresh.indexOf(file);
if(idx != -1) {
document.getElementById(file).style.background = 'none';
statistics_to_refresh.splice(idx, 1);
}
else {
document.getElementById(file).style.background = '#68b3e3';
statistics_to_refresh.push(file);
}
document.refresh_statistics.statistics_to_refresh.value = statistics_to_refresh;
}
</script>