Hello,
Recently I improved the crontabs/gather_scm_stats.php script.
I would be happy if you can comment on my improvements - and maybe include them
in one of the next
FusionForge releases (see attached patch).
The old script scanned all repos starting from the begin of the epoch
(1970-1-1)
when given the --all option, wasting a lot of time!
My improvements are implemented as additional command line options to not break
the old behavior.
The new options are:
--alldb : Scan repository starting from the group registration date
--unix_group_name NAME: scan only repo for the given unix group name NAME
--group_id ID: scan only repo for the given group id ID
--startdate YYYY-MM-YY : scan repo staring from the given date YYYY-MM-YY
--enddate YYYY-MM-DD : scan repo until given date YYYY-MM-YY
As I am not aware of the php versions supported by FusionForge, I would like to
note that I used the following
php functions which may only available for php 5.3:
* date_default_timezone_set()
* date_default_timezone_get()
* getopt()
Best regards
Christoph Niethammer
--- gather_scm_stats.php 2013-06-23 00:22:49.000000000 +0200
+++ gather_scm_stats.php 2013-06-24 10:48:02.000000000 +0200
@@ -4,6 +4,7 @@
* FusionForge source control management
*
* Copyright 2009, Roland Mas
+ * Copyright 2013, Christoph Niethammer
*
* This file is part of FusionForge. FusionForge is free software;
* you can redistribute it and/or modify it under the terms of the
@@ -34,46 +35,80 @@
setup_plugin_manager () ;
-$res = db_query_params ('SELECT group_id FROM groups WHERE status=$1 AND use_scm=1 ORDER BY group_id DESC',
+
+date_default_timezone_set(@date_default_timezone_get());
+$starttime = time() - 86400 ;
+$endtime = time();
+
+$shortopts = "v"; // enable verbose mode
+$longopts = array(
+ "alldb", // consider all commits from registration date saved in db up to now
+ "all", // consider all commits from start of the epoch (1970-01-01) up to now
+ "startdate:", // consider only commits later than given startdate (YYYY-MM-DD), overwritten by all/allsvn
+ "enddate:", // consider only commits before given enddate (YYYY-MM-DD), overwritten by all/allsvn
+ "group_id:", // update data only for group with given id
+ "unix_group_name:" // update data only for group with given unix name
+);
+$options = getopt($shortopts, $longopts);
+$EXTRA_WHERE = "";
+$verbose = false;
+
+if ( isset($options['v']) ) {
+ $verbose = true;
+}
+if ( isset($options['startdate']) ) {
+ $starttime = strtotime($options['startdate']) ;
+ ($verbose) && print "Startdate: ".date("Y-m-d", $starttime)."\n";
+}
+if ( isset($options['enddate']) ) {
+ $endtime = strtotime($options['enddate']) ;
+ ($verbose) && print "Enddate: ".date("Y-m-d", $endtime)."\n";
+}
+if ( isset($options['group_id']) ) {
+ $EXTRA_WHERE .= " AND group_id=".$options['group_id'] ;
+ ($verbose) && print "group_id: ".$options['group_id']."\n";
+}
+if ( isset($options['unix_group_name']) ) {
+ $EXTRA_WHERE .= " AND unix_group_name='".$options['unix_group_name']."'" ;
+ ($verbose) && print "unix_group_name: ".$options['unix_group_name']."\n";
+}
+
+$res = db_query_params ('SELECT group_id, group_name, register_time FROM groups WHERE status=$1 AND use_scm=1 '.$EXTRA_WHERE.' ORDER BY group_id DESC',
array ('A'));
if (!$res) {
$this->setError('Unable to get list of projects using SCM: '.db_error());
return false;
}
-$mode = 'day' ;
-if (count ($argv) >= 2 && $argv[1] == '--all') {
- $mode = 'all' ;
-}
+
while ($data = db_fetch_array ($res)) {
- if ($mode == 'day') {
- $time = time () - 86400 ;
- $hook_params = array ('group_id' => $data['group_id'],
- 'mode' => 'day',
- 'year' => date ('Y', $time),
- 'month' => date ('n', $time),
- 'day' => date ('j', $time)) ;
- plugin_hook ('scm_gather_stats', $hook_params) ;
- } elseif ($mode == 'all') {
- $last_seen_day = '' ;
- $time = 0 ;
- $now = time () ;
- while ($time < $now) {
- $day = date ('Y-m-d', $time) ;
- print "processing $day\n" ;
- if ($day != $last_seen_day) {
- $hook_params = array ('group_id' => $data['group_id'],
- 'mode' => 'day',
- 'year' => date ('Y', $time),
- 'month' => date ('n', $time),
- 'day' => date ('j', $time)) ;
- plugin_hook ('scm_gather_stats', $hook_params) ;
- $last_seen_day = $day ;
- }
- $time = $time + 80000 ;
- }
- }
+ print "Processing GroupId ".$data['group_id']." (".$data['group_name'].")\n";
+ $time = $starttime;
+ $etime = $endtime;
+ if ( isset($options['alldb']) ) {
+ $time = date($data['register_time']);
+ $etime = time();
+ }
+ if ( isset($options['all']) ) {
+ $time = 0;
+ $etime = time();
+ }
+ $last_seen_day = '' ;
+ while ($time < $etime) {
+ $day = date ('Y-m-d', $time) ;
+ if ($day != $last_seen_day) {
+ $last_seen_day = $day ;
+ print "processing $day\n" ;
+ $hook_params = array ('group_id' => $data['group_id'],
+ 'mode' => 'day',
+ 'year' => date ('Y', $time),
+ 'month' => date ('n', $time),
+ 'day' => date ('j', $time)) ;
+ plugin_hook ('scm_gather_stats', $hook_params) ;
+ }
+ $time = $time + 80000 ;
+ }
}
// Local Variables:
_______________________________________________
Fusionforge-general mailing list
[email protected]
http://lists.fusionforge.org/cgi-bin/mailman/listinfo/fusionforge-general