4 * Portions Copyright 1999-2001 (c) VA Linux Systems
5 * The rest Copyright 2002-2004 (c) GForge Team
6 * Copyright 2013, Franck Villaume - TrivialDev
7 * http://fusionforge.org/
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require (dirname(__FILE__).'/../www/env.inc.php');
26 require_once $gfcommon.'include/pre.php';
27 require $gfcommon.'include/cron_utils.php';
35 Since we cannot crunch down all the data on the fly anymore,
36 we need to crunch it down once daily into a separate table,
37 then join against that table to get counts.
43 Create an aggregation table that includes counts of forum messages
45 if (forge_get_config('use_forum')) {
48 db_query_params ('LOCK TABLE forum_agg_msg_count IN ACCESS EXCLUSIVE MODE',
50 db_query_params ('LOCK TABLE forum IN ACCESS EXCLUSIVE MODE',
52 db_query_params ('LOCK TABLE forum_group_list IN ACCESS EXCLUSIVE MODE',
55 $res = db_query_params ('DELETE FROM forum_agg_msg_count',
59 $err .= "DELETE FROM forum_agg_msg_count : ".db_error();
62 $res = db_query_params ('INSERT INTO forum_agg_msg_count
63 SELECT fgl.group_forum_id,count(f.msg_id)
64 FROM forum_group_list fgl
65 LEFT JOIN forum f USING (group_forum_id)
66 GROUP BY fgl.group_forum_id',
70 $err .= "INSERT INTO forum_agg_msg_count : ".db_error();
77 Create an aggregation table that includes counts of artifacts
79 if (forge_get_config('use_tracker')) {
82 db_query_params ('LOCK TABLE artifact_counts_agg IN ACCESS EXCLUSIVE MODE',
84 db_query_params ('LOCK TABLE artifact IN ACCESS EXCLUSIVE MODE',
86 db_query_params ('LOCK TABLE artifact_group_list IN ACCESS EXCLUSIVE MODE',
89 $rel = db_query_params ('DELETE FROM artifact_counts_agg',
94 $rel=db_query_params ('INSERT INTO artifact_counts_agg
95 SELECT agl.group_artifact_id,
96 (SELECT count(*) FROM artifact WHERE status_id <> 3 AND group_artifact_id=agl.group_artifact_id),
97 (SELECT count(*) FROM artifact WHERE status_id=1 AND group_artifact_id=agl.group_artifact_id)
98 FROM artifact_group_list agl
99 LEFT JOIN artifact a USING (group_artifact_id)
100 GROUP BY agl.group_artifact_id',
110 Rebuild the project_sums_agg table, which saves us
111 from doing really expensive queries
112 each time the project summary is viewed
116 $res=db_query_params ('DELETE FROM project_sums_agg',
120 Get counts of mailing lists
122 if (forge_get_config('use_mail')) {
123 $res=db_query_params ('INSERT INTO project_sums_agg
124 SELECT group_id,$1 AS type,count(*) AS count
125 FROM mail_group_list WHERE is_public = 1
126 GROUP BY group_id,type',
132 Get counts of surveys
134 if (forge_get_config('use_survey')) {
135 $res=db_query_params ('INSERT INTO project_sums_agg
136 SELECT group_id,$1 AS type,count(*) AS count
139 GROUP BY group_id,type',