4 * FusionForge source control management
6 * Copyright 2009, Roland Mas
7 * Copyright 2013, Christoph Niethammer
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_once $gfcommon.'include/cron_utils.php';
30 require_once $gfcommon.'include/Plugin.class.php' ;
31 require_once $gfcommon.'include/PluginManager.class.php' ;
33 // SCM-specific plugins subsystem
34 require_once $gfcommon.'include/SCMPlugin.class.php' ;
36 session_set_admin () ;
38 setup_plugin_manager () ;
41 date_default_timezone_set(@date_default_timezone_get());
43 $starttime = $endtime - 86400 ;
45 $shortopts = "v"; // enable verbose mode
47 "all", // consider all commits from registration date saved in db up to now
48 "allepoch", // consider all commits from start of the epoch (1970-01-01) up to now
49 "startdate:", // consider only commits later than given startdate (YYYY-MM-DD), overwritten by all/allepoch
50 "enddate:", // consider only commits before given enddate (YYYY-MM-DD), overwritten by all/allepoch
51 "group_id:", // update data only for group with given id
52 "unix_group_name:" // update data only for group with given unix name
54 $options = getopt($shortopts, $longopts);
58 $qpa = db_construct_qpa(false, 'SELECT group_id, group_name, register_time FROM groups WHERE status=$1 AND use_scm=$2', array ('A', 1));
60 if ( isset($options['v']) ) {
63 if ( isset($options['startdate']) ) {
64 $starttime = strtotime($options['startdate']) ;
65 ($verbose) && print "Startdate: ".date("Y-m-d", $starttime)."\n";
67 if ( isset($options['enddate']) ) {
68 $endtime = strtotime($options['enddate']) ;
69 ($verbose) && print "Enddate: ".date("Y-m-d", $endtime)."\n";
71 if ( isset($options['group_id']) ) {
72 ($verbose) && print "group_id: ".$options['group_id']."\n";
73 $qpa = db_construct_qpa($qpa, ' AND group_id=$1', array($options['group_id']));
75 if ( isset($options['unix_group_name']) ) {
76 ($verbose) && print "unix_group_name: ".$options['unix_group_name']."\n";
77 $qpa = db_construct_qpa($qpa, ' AND unix_group_name=$1', array($options['unix_group_name']));
80 $qpa = db_construct_qpa($qpa, ' ORDER BY group_id DESC');
82 $res = db_query_qpa($qpa);
85 $this->setError('Unable to get list of projects using SCM: '.db_error());
91 while ($data = db_fetch_array ($res)) {
92 print "Processing GroupId ".$data['group_id']." (".$data['group_name'].")\n";
95 if ( isset($options['all']) ) {
96 $time = date($data['register_time']);
99 if ( isset($options['allepoch']) ) {
103 $last_seen_day = '' ;
104 while ($time < $etime) {
105 $day = date ('Y-m-d', $time) ;
106 if ($day != $last_seen_day) {
107 $last_seen_day = $day ;
108 ($verbose) && print "processing $day\n" ;
109 $hook_params = array ('group_id' => $data['group_id'],
111 'year' => date ('Y', $time),
112 'month' => date ('n', $time),
113 'day' => date ('j', $time)) ;
114 plugin_hook ('scm_gather_stats', $hook_params) ;
116 $time = $time + 86400 ;
120 if ($output) cron_entry(28, $output);
124 // c-file-style: "bsd"