[Fusionforge-commits] r15114 - in trunk/src: common/include plugins/scmsvn/common www/activity

Franck VILLAUME nerville at fusionforge.org
Tue Mar 13 20:19:49 CET 2012


Author: nerville
Date: 2012-03-13 20:19:48 +0100 (Tue, 13 Mar 2012)
New Revision: 15114

Modified:
   trunk/src/common/include/SCMPlugin.class.php
   trunk/src/plugins/scmsvn/common/SVNPlugin.class.php
   trunk/src/www/activity/index.php
Log:
new feature : add basic activity stream for scmsvn plugin

Modified: trunk/src/common/include/SCMPlugin.class.php
===================================================================
--- trunk/src/common/include/SCMPlugin.class.php	2012-03-13 18:49:22 UTC (rev 15113)
+++ trunk/src/common/include/SCMPlugin.class.php	2012-03-13 19:19:48 UTC (rev 15114)
@@ -84,7 +84,7 @@
 				$this->updateRepositoryList($params);
 				break;
 			}
-			case 'scm_generate_snapshots': {// Optional
+			case 'scm_generate_snapshots': { // Optional
 				session_set_admin();
 				$this->generateSnapshots($params);
 				break;
@@ -102,6 +102,10 @@
 				$this->myPageBox($params);
 				break;
 			}
+			case "activity": { //Optional
+				$this->activity($params);
+				break;
+			}
 			default: { // Forgot something
 			}
 		}

Modified: trunk/src/plugins/scmsvn/common/SVNPlugin.class.php
===================================================================
--- trunk/src/plugins/scmsvn/common/SVNPlugin.class.php	2012-03-13 18:49:22 UTC (rev 15113)
+++ trunk/src/plugins/scmsvn/common/SVNPlugin.class.php	2012-03-13 19:19:48 UTC (rev 15114)
@@ -49,6 +49,7 @@
 		$this->_addHook('scm_update_repolist');
 		$this->_addHook('scm_generate_snapshots');
 		$this->_addHook('scm_gather_stats');
+		$this->_addHook('activity');
 
 		$this->provides['svn'] = true;
 
@@ -374,8 +375,8 @@
 			$updates = 0;
 			$usr_adds    = array();
 			$usr_updates = array();
-
-			$repo = forge_get_config('repos_path', 'scmsvn') . '/' . $project->getUnixName() ;
+ 
+			$repo = forge_get_config('repos_path', 'scmsvn') . '/' . $project->getUnixName();
 			if (!is_dir ($repo) || !is_file ("$repo/format")) {
 				echo "No repository\n";
 				db_rollback();
@@ -386,7 +387,7 @@
 			$d2 = date('Y-m-d', $end_time + 150000);
 
 			$pipe = popen ("svn log file://$repo --xml -v -q -r '".'{'.$d2.'}:{'.$d1.'}'."' 2> /dev/null", 'r' ) ;
-
+ 
 			// cleaning stats_cvs_* table for the current day
 			$res = db_query_params('DELETE FROM stats_cvs_group WHERE month=$1 AND day=$2 AND group_id=$3',
 						array($month_string,
@@ -397,7 +398,7 @@
 				db_rollback();
 				return false;
 			}
-
+ 
 			$res = db_query_params ('DELETE FROM stats_cvs_user WHERE month=$1 AND day=$2 AND group_id=$3',
 						array ($month_string,
 						       $day,
@@ -407,15 +408,14 @@
 				db_rollback () ;
 				return false ;
 			}
-
+ 
 			$xml_parser = xml_parser_create();
 			xml_set_element_handler($xml_parser, "SVNPluginStartElement", "SVNPluginEndElement");
 			xml_set_character_data_handler($xml_parser, "SVNPluginCharData");
-
+ 
 			// Analyzing history stream
 			while (!feof($pipe) &&
-			       $data = fgets ($pipe, 4096)) {
-
+				$data = fgets ($pipe, 4096)) {
 				if (!xml_parse ($xml_parser, $data, feof ($pipe))) {
 					debug("Unable to parse XML with error " .
 					      xml_error_string(xml_get_error_code($xml_parser)) .
@@ -427,11 +427,11 @@
 				}
 			}
 
-			xml_parser_free ($xml_parser);
+			xml_parser_free($xml_parser);
 
 			// inserting group results in stats_cvs_groups
 			if ($updates > 0 || $adds > 0) {
-				if (!db_query_params ('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
+				if (!db_query_params('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
 						      array ($month_string,
 							     $day,
 							     $project->getID(),
@@ -439,14 +439,14 @@
 							     $updates,
 							     $adds))) {
 					echo "Error while inserting into stats_cvs_group\n" ;
-					db_rollback () ;
-					return false ;
+					db_rollback();
+					return false;
 				}
 			}
 
 			// building the user list
 			$user_list = array_unique( array_merge( array_keys( $usr_adds ), array_keys( $usr_updates ) ) );
-
+ 
 			foreach ( $user_list as $user ) {
 				// trying to get user id from user name
 				$u = &user_get_object_by_name ($user) ;
@@ -544,6 +544,60 @@
 		system ("rm -rf $tmp") ;
 	}
 
+	function activity($params) {
+		global $last_user, $last_time, $last_tag, $time_ok, $start_time, $end_time,
+			$adds, $deletes, $updates, $commits, $date_key,
+			$usr_adds, $usr_deletes, $usr_updates,
+			$messages, $last_message, $times;
+		$group_id = $params['group'];
+		$project = group_get_object($group_id);
+		if (! $project->usesPlugin($this->name)) {
+			return false;
+		}
+
+		if (in_array('scm', $params['show'])) {
+			$start_time = $params['begin'];
+			$end_time = $params['end'];
+			$d1 = date('Y-m-d', $start_time - 80000);
+			$d2 = date('Y-m-d', $end_time + 80000);
+
+			$repo = forge_get_config('repos_path', 'scmsvn') . '/' . $project->getUnixName();
+			$pipe = popen("svn log file://$repo --xml -v -r '".'{'.$d2.'}:{'.$d1.'}'."' 2> /dev/null", 'r' );
+			$xml_parser = xml_parser_create();
+			xml_set_element_handler($xml_parser, "SVNPluginStartElement", "SVNPluginEndElement");
+			xml_set_character_data_handler($xml_parser, "SVNPluginCharData");
+			while (!feof($pipe) && $data = fgets($pipe, 4096)) {
+				if (!xml_parse($xml_parser, $data, feof ($pipe))) {
+					debug("Unable to parse XML with error " .
+						xml_error_string(xml_get_error_code($xml_parser)) .
+						" on line " .
+						xml_get_current_line_number($xml_parser));
+					return false;
+					break;
+				}
+			}
+			xml_parser_free($xml_parser);
+			if ($adds > 0 || $updates > 0) {
+				$i = 0;
+				foreach ($messages as $message) {
+					$result = array();
+					$result['section'] = 'scm';
+					$result['group_id'] = $group_id;
+					$result['ref_id'] = 'viewvc.php/?root='.$project->getUnixName();
+					$result['description'] = $message;
+					$result['realname'] = '';
+					$result['activity_date'] = $times[$i];
+					$result['subref_id'] = 0;
+					$params['results'][] = $result;
+					$i++;
+				}
+			}
+		}
+		$params['ids'][] = 'scm';
+		$params['texts'][] = _('SCM SVN Commits');
+		return true;
+	}
+
 	function installOrUpdateCmds($project, $unix_group_name, $repos) {
 
 		$hooks = array();
@@ -628,48 +682,57 @@
 
 function SVNPluginCharData($parser, $chars) {
 	global $last_tag, $last_user, $last_time, $start_time, $end_time,
-		$time_ok, $user_list;
+		$time_ok, $user_list, $last_message, $messages, $times;
 	switch ($last_tag) {
-	case "AUTHOR":
-		$last_user = preg_replace('/[^a-z0-9_-]/', '', strtolower(trim($chars)));
-		break;
-	case "DATE":
-		$chars = preg_replace('/T(\d\d:\d\d:\d\d)\.\d+Z?$/', ' ${1}', $chars);
-		$last_time = strtotime($chars);
-		if ($start_time <= $last_time && $last_time < $end_time) {
-			$time_ok = true;
-		} else {
-			$time_ok = false;
+		case "AUTHOR": {
+			$last_user = preg_replace('/[^a-z0-9_-]/', '', strtolower(trim($chars)));
+			break;
 		}
-		break;
+		case "DATE": {
+			$chars = preg_replace('/T(\d\d:\d\d:\d\d)\.\d+Z?$/', ' ${1}', $chars);
+			$last_time = strtotime($chars);
+			if ($start_time <= $last_time && $last_time < $end_time) {
+				$time_ok = true;
+			} else {
+				$time_ok = false;
+			}
+			$times[] = $last_time;
+			break;
+		}
+		case "MSG": {
+			$messages[] = $chars;
+			break;
+		}
 	}
 }
 
 function SVNPluginStartElement($parser, $name, $attrs) {
 	global $last_user, $last_time, $last_tag, $time_ok,
-		$adds, $updates, $usr_adds, $usr_updates;
+		$adds, $updates, $usr_adds, $usr_updates, $last_message, $messages, $times;
 	$last_tag = $name;
 	switch($name) {
-	case "LOGENTRY":
-		// Make sure we clean up before doing a new log entry
-		$last_user = "";
-		$last_time = "";
-		break;
-	case "PATH":
-		if ($time_ok) {
-			if ($attrs['ACTION'] == "M") {
-				$updates++;
-				if ($last_user) {
-					$usr_updates[$last_user] = isset($usr_updates[$last_user]) ? ($usr_updates[$last_user]+1) : 0 ;
+		case "LOGENTRY": {
+			// Make sure we clean up before doing a new log entry
+			$last_user = "";
+			$last_time = "";
+			break;
+		}
+		case "PATH": {
+			if ($time_ok) {
+				if ($attrs['ACTION'] == "M") {
+					$updates++;
+					if ($last_user) {
+						$usr_updates[$last_user] = isset($usr_updates[$last_user]) ? ($usr_updates[$last_user]+1) : 0 ;
+					}
+				} elseif ($attrs['ACTION'] == "A") {
+					$adds++;
+					if ($last_user) {
+						$usr_adds[$last_user] = isset($usr_adds[$last_user]) ? ($usr_adds[$last_user]+1) : 0 ;
+					}
 				}
-			} elseif ($attrs['ACTION'] == "A") {
-				$adds++;
-				if ($last_user) {
-					$usr_adds[$last_user] = isset($usr_adds[$last_user]) ? ($usr_adds[$last_user]+1) : 0 ;
-				}
 			}
+			break;
 		}
-		break;
 	}
 }
 

Modified: trunk/src/www/activity/index.php
===================================================================
--- trunk/src/www/activity/index.php	2012-03-13 18:49:22 UTC (rev 15113)
+++ trunk/src/www/activity/index.php	2012-03-13 19:19:48 UTC (rev 15114)
@@ -5,6 +5,7 @@
  * Copyright 1999 dtype
  * Copyright 2006 (c) GForge, LLC
  * Copyright 2010-2011, Franck Villaume - Capgemini
+ * Copyright 2012, Franck Villaume - TrivialDev
  * http://fusionforge.org/
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -75,7 +76,7 @@
 if (!$group_id) {
 	exit_no_group();
 }
-$group=group_get_object($group_id);
+$group = group_get_object($group_id);
 if (!$group || !is_object($group)) {
 	exit_permission_denied('home');
 }
@@ -91,6 +92,10 @@
 }
 
 if (forge_get_config('use_tracker') && $group->usesTracker()) {
+// These lines are currently commented due to lack of explanations.
+// We need to enable these lines only if you use the commit tracker plugin I suppose.
+// 	$ids[]		= 'commit';
+// 	$texts[]	= _('Commit Tracking');
 	$ids[]		= 'trackeropen';
 	$texts[]	= _('Tracker Opened');
 	$ids[]		= 'trackerclose';
@@ -149,6 +154,7 @@
 if (count($show) < 1) {
 	$show = $ids;
 }
+
 foreach ($show as $showthis) {
 	if (array_search($showthis, $ids) === false) {
 		exit_error(_('Invalid Data Passed to query'), 'home');
@@ -200,6 +206,10 @@
 
 		if (!isset($cached_perms[$s][$ref])) {
 			switch ($s) {
+				case 'scm': {
+					$cached_perms[$s][$ref] = forge_check_perm('scm', $ref, 'read');
+					break;
+				}
 				case 'commit':
 				case 'trackeropen':
 				case 'trackerclose': {
@@ -245,13 +255,18 @@
 		if (!check_perm_for_activity($arr)) {
 			continue;
 		}
-		if ($last_day != strftime($date_format,$arr['activity_date'])) {
+		if ($last_day != strftime($date_format, $arr['activity_date'])) {
 			//	echo $HTML->listTableBottom($theader);
-			echo '<tr class="tableheading"><td colspan="3">'.strftime($date_format,$arr['activity_date']).'</td></tr>';
+			echo '<tr class="tableheading"><td colspan="3">'.strftime($date_format, $arr['activity_date']).'</td></tr>';
 			//	echo $HTML->listTableTop($theader);
-			$last_day=strftime($date_format,$arr['activity_date']);
+			$last_day=strftime($date_format, $arr['activity_date']);
 		}
 		switch (@$arr['section']) {
+			case 'scm': {
+				$icon = html_image('ic/cvs16b.png','','',array('alt'=>'Source Code'));
+				$url = util_make_link($arr['ref_id'],_('scm commit: ').$arr['description']);
+				break;
+			}
 			case 'commit': {
 				$icon = html_image('ic/cvs16b.png','','',array('alt'=>'Source Code'));
 				$url = util_make_link('/tracker/?func=detail&atid='.$arr['ref_id'].'&aid='.$arr['subref_id'].'&group_id='.$arr['group_id'],_('Commit for Tracker Item').' [#'.$arr['subref_id'].'] '.$arr['description']);




More information about the Fusionforge-commits mailing list