4 * Copyright 1999-2001 (c) VA Linux Systems
5 * Copyright 2013, Franck Villaume - TrivialDev
7 * This file is part of FusionForge. FusionForge is free software;
8 * you can redistribute it and/or modify it under the terms of the
9 * GNU General Public License as published by the Free Software
10 * Foundation; either version 2 of the Licence, or (at your option)
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 require dirname(__FILE__).'/../www/env.inc.php';
24 require_once $gfcommon.'include/pre.php';
25 require $gfcommon.'include/cron_utils.php';
31 $how_far_back=(time() - 86400);
33 $yesterday_formatted=date('Ymd',$how_far_back);
35 $year=date('Y', $how_far_back);
36 $month=date('m', $how_far_back);
37 $day=date('d', $how_far_back);
38 $day_begin=mktime(0,0,0,$month,$day,$year);
39 $day_end=($day_begin + 86400);
43 // logo showings by day
45 $err .= "\n\nBeginning stats_agg_logo_by_day ".date('Ymd H:i:s',time());
46 $rel = db_query_params ('DELETE FROM stats_agg_logo_by_day WHERE day=$1',
47 array ($yesterday_formatted));
49 $rel = db_query_params ('INSERT INTO stats_agg_logo_by_day
51 FROM activity_log WHERE type=0 AND day=$1 GROUP BY day',
52 array ($yesterday_formatted));
57 // logo showings by group
58 // new table format 2001-april
60 $err .= "\n\nBeginning stats_agg_logo_by_group ".date('Ymd H:i:s',time());
61 $rel = db_query_params ('DELETE FROM stats_agg_logo_by_group WHERE month=$1 AND day=$2',
65 $rel = db_query_params ('INSERT INTO stats_agg_logo_by_group SELECT $1::int AS month, $2::int AS newday,group_id,count(*) AS count
66 FROM activity_log WHERE type=0 AND day=$3 AND group_id <> 0 GROUP BY month,newday,group_id',
69 $yesterday_formatted)) ;
74 // site showings by group
75 // new table format 2001-april
77 $err .= "\n\nBeginning stats_agg_site_by_group ".date('Ymd H:i:s',time());
78 $rel = db_query_params ('DELETE FROM stats_agg_site_by_group WHERE month=$1 AND day=$2',
82 $rel = db_query_params ('INSERT INTO stats_agg_site_by_group SELECT $1::int AS month, $2::int AS newday,group_id,COUNT(*) AS count FROM activity_log WHERE type=0 AND day=$3 AND group_id <> 0 GROUP BY month,newday,group_id',
85 $yesterday_formatted)) ;
92 $err .= "\n\nBeginning stats_site_pages_by_day ".date('Ymd H:i:s',time());
93 $rel = db_query_params ('DELETE FROM stats_site_pages_by_day WHERE month=$1 AND day=$2',
97 $rel = db_query_params ('INSERT INTO stats_site_pages_by_day (month,day,site_page_views) SELECT $1::int AS month, $2::int AS newday, count(*) AS count FROM activity_log WHERE type=0 AND day=$3 GROUP BY month,newday',
100 $yesterday_formatted)) ;
105 // insert the number of developers per project into history table
107 $err .= "\n\nBeginning stats_project_developers ".date('Ymd H:i:s',time());
108 $rel = db_query_params ('DELETE FROM stats_project_developers WHERE month=$1 AND day=$2',
109 array ("$year$month",
112 $rel = db_query_params ('INSERT INTO stats_project_developers (month,day,group_id,developers)
113 SELECT $1::int AS month, $2::int, pfo_role.home_group_id AS group_id, COUNT(DISTINCT(pfo_user_role.user_id)) AS developers FROM pfo_user_role, pfo_role WHERE pfo_user_role.role_id = pfo_role.role_id AND pfo_role.home_group_id IS NOT NULL GROUP BY pfo_role.home_group_id',
114 array ("$year$month",
123 // populate stats_site table
125 $err .= "\n\nBeginning stats_site ".date('Ymd H:i:s',time());
126 include 'cronjobs/stats_site.inc';
127 site_stats_day($year,$month,$day);
130 // populate stats_project table
132 $err .= "\n\nBeginning stats_project ".date('Ymd H:i:s',time());
133 include 'cronjobs/stats_projects.inc';
134 project_stats_day($year,$month,$day);