3 * GForge Plugin SVNTracker Class
5 * Copyright 2004 (c) Francisco Gimeno <kikov @nospam@ kikov.org>
6 * Copyright 2005 (c) Guillaume Smet <guillaume-gforge@smet.org>
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
9 * This file is part of GForge-plugin-svntracker
11 * GForge-plugin-svntracker is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * GForge-plugin-svntracker is distributed in the hope that it will
17 * be useful, but WITHOUT ANY WARRANTY; without even the implied
18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * The svntrackerPlugin class. It implements the Hooks for the presentation
27 * of table in tracker and task in detailed mode.
31 class svntrackerPlugin extends Plugin {
33 function __construct() {
35 $this->name = "svntracker" ;
36 $this->text = "Source Code and Tracker/Task Integration";
37 $this->hooks[] = "groupisactivecheckbox";
38 $this->hooks[] = "groupisactivecheckboxpost";
39 $this->hooks[] = "artifact_extra_detail";
40 $this->hooks[] = "task_extra_detail";
41 $this->hooks[] = "update_svn_repository";
42 $this->hooks[] = "cmd_for_post_commit_hook";
45 function groupisactivecheckbox (&$params) {
46 $group = group_get_object($params['group']);
47 if ($group->usesPlugin('scmsvn') || $group->usesPlugin('websvn')) {
48 parent::groupisactivecheckbox($params);
53 * It display a table with commit related to this tracker or task_extra_detail
55 * @param string $Query Query to be executed to get the commit entries.
56 * @param integer $group_id Group_id of the actual Group_id
59 function getCommitEntries($DBResult,$group_id) {
60 $group = &group_get_object($group_id);
61 $Rows= db_numrows($DBResult);
64 echo '<tr><td colspan="2">';
65 echo '<h4>'._('Links to related SVN commits').':</h4>';
67 $title_arr=$this->getTitleArr();
68 echo $GLOBALS['HTML']->listTableTop ($title_arr);
70 for ($i=0; $i<$Rows; $i++) {
71 $Row = db_fetch_array($DBResult);
72 echo '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'.
73 '<td>'. $this->getFileLink($group->getUnixName(),
74 $Row['file'],$Row['actual_version']). '</td>'.
75 '<td>'. date(_('Y-m-d'), $Row['svn_date']).'</td>'.
76 '<td>'. $this->getDiffLink($group->getUnixName(),
79 $Row['actual_version']).'</td>'.
80 '<td>'. $this->getActualVersionLink($group->getUnixName(),
81 $Row['file'], $Row['actual_version']).
83 <td>'. htmlspecialchars($Row['log_text']).'</td>
84 <td>'. util_make_link_u ($Row['author'],
85 user_get_object_by_name ($Row['author'])->getId(),
86 $Row['author']).'</td>
89 echo $GLOBALS['HTML']->listTableBottom();
95 * Return an array with titles of Box to display the entries
97 * @return Array The array containing the titles
100 function getTitleArr() {
102 $title_arr[]=_('Filename');
103 $title_arr[]=_('Date');
104 $title_arr[]=_('Previous Version');
105 $title_arr[]=_('Current Version');
106 $title_arr[]=_('Log Message');
107 $title_arr[]=_('Author');
112 * Return a link to the File in svnweb
114 * @param String $GroupName is the Name of the project
115 * @param String $FileName is the FileName ( with path )
116 * @param Int $LatestRevision is the last revision for the file
118 * @return String The string containing a link to the File in the svnweb
121 function getFileLink($GroupName, $FileName, $LatestRevision) {
122 return util_make_link ('/scm/viewvc.php'.$FileName .
123 '?root='.$GroupName.'&view=log&rev=' .
129 * Return a link to the File in viewcvs in the specified Version
131 * @param String $GroupName is the Name of the project
132 * @param String $FileName is the FileName ( with path )
133 * @param String $Version the version to retrieve
135 * @return String The string containing a link to the File in the viewcvs
138 function getActualVersionLink($GroupName, $FileName, $Version) {
139 return util_make_link ('/scm/viewvc.php'.$FileName .
140 '?root='.$GroupName.'&rev='.$Version,
145 * Return a link to the diff between two versions of a File in viewcvs
147 * @param String $GroupName is the Name of the project
148 * @param String $FileName is the FileName ( with path )
149 * @param String $PrevVersion First version to retrieve
150 * @param String $ActualVersion Second version to retrieve
152 * @return String The string containing a link to the File in the cvsweb
155 function getDiffLink($GroupName, $FileName, $PrevVersion, $ActualVersion) {
156 return util_make_link ('/scm/viewvc.php'.$FileName .
157 '?root='.$GroupName.'&r1='.$PrevVersion .
158 '&r2='.$ActualVersion,
159 _('Diff To').' '.$PrevVersion);
164 * Function to add svntracker lines to a loginfo file
166 * @param string $path The filename of loginfo
169 /*function addCvsTrackerToFile($path) {
170 global $cvs_binary_version;
172 $FOut = fopen($path, "a");
174 fwrite($FOut, "# BEGIN added by gforge-plugin-cvstracker\n");
175 if ( $cvs_binary_version == "1.12" ) {
176 $Line = "ALL ( php -q -d include_path=".ini_get('include_path').
177 " ".forge_get_config('plugins_path')."/cvstracker/bin/post.php".
180 if ( $cvs_binary_version == "1.11") {
181 $Line = "ALL ( php -q -d include_path=".ini_get('include_path').
182 " ".forge_get_config('plugins_path')."/cvstracker/bin/post.php".
186 fwrite($FOut, "# END added by gforge-plugin-cvstracker\n");
192 * Retrieve a file into a temporary directory from a SVN server
194 * @param String $repos Repository Name
195 * @param String $file File Name
197 * return String the FileName in the working repository
199 /*function getCvsFile($repos,$file) {
200 $actual_dir = getcwd();
201 $tempdirname = tempnam("/tmp","cvstracker");
204 if (!unlink($tempdirname))
207 // Create the temporary directory and returns its name.
208 if (!mkdir($tempdirname))
211 if (!chdir($tempdirname))
213 system("cvs -d ".$repos." co ".$file);
216 return $tempdirname.$file;
220 * putCvsFile commit a file to the repository
222 * @param String $repos Repository
223 * @param String $file to commit
224 * @param String $message to commit
226 /*function putCvsFile($repos,$file,$message="Automatic updated by cvstracker") {
227 system("cvs -d ".$repos." ci -m \"".$message."\" ".$file);
232 * The function to be called for a Hook
234 * @param String $hookname The name of the hookname that has been happened
235 * @param String $params The params of the Hook
238 function CallHook ($hookname, &$params) {
239 global $group_id, $aid;
241 if ($hookname == "artifact_extra_detail") {
242 $DBResult = db_query_params ('SELECT * FROM plugin_svntracker_data_master,
243 plugin_svntracker_data_artifact WHERE plugin_svntracker_data_artifact.group_artifact_id=$1 AND plugin_svntracker_data_master.holder_id=plugin_svntracker_data_artifact.id ORDER BY svn_date',
245 $this->getCommitEntries($DBResult, $group_id);
246 } elseif ($hookname == "task_extra_detail") {
247 $DBResult = db_query_params ('SELECT * FROM plugin_svntracker_data_master,
248 plugin_svntracker_data_artifact WHERE plugin_svntracker_data_artifact.project_task_id=$1 AND plugin_svntracker_data_master.holder_id=plugin_svntracker_data_artifact.id ORDER BY svn_date',
249 array ($params['task_id']));
250 $this->getCommitEntries($DBResult, $group_id);
251 } elseif ($hookname == 'cmd_for_post_commit_hook') {
252 $params['hooks'][$this->name] = '/usr/bin/php -d include_path='.ini_get('include_path').
253 ' '.forge_get_config('plugins_path').'/svntracker/bin/post.php '.$params['repos'].' "$2"';
254 } /*elseif ($hookname == "update_svn_repository") {
255 $Group = group_get_object($params["group_id"]);
256 if ($Group->usesPlugin("cvstracker")) {
258 $FIn = fopen(getCvsFile( $params["file_name"],
259 "CVSROOT/loginfo"),"r");
261 while (!feof($FIn)) {
262 $Line = fgets ($FIn);
263 if(!preg_match("/^#/", $Line) &&
264 preg_match("/cvstracker/",$Line)) {
270 if($LineFound==FALSE) {
271 $newfile=getCvsFile($params["file_name"],
273 $this->addCvsTrackerToFile($newfile);
274 $this->putCvsFile($params["file_name"],
284 // c-file-style: "bsd"