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>
8 * This file is part of GForge-plugin-svntracker
10 * GForge-plugin-svntracker is free software; you can redistribute it
11 * and/or modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * GForge-plugin-svntracker is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * The svntrackerPlugin class. It implements the Hooks for the presentation
26 * of table in tracker and task in detailed mode.
30 class svntrackerPlugin extends Plugin {
31 function svntrackerPlugin () {
33 $this->name = "svntracker" ;
34 $this->text = "Source Code and Tracker/Task Integration";
35 $this->hooks[] = "groupisactivecheckbox";
36 $this->hooks[] = "groupisactivecheckboxpost";
37 $this->hooks[] = "artifact_extra_detail";
38 $this->hooks[] = "task_extra_detail";
39 $this->hooks[] = "update_svn_repository";
40 $this->hooks[] = "cmd_for_post_commit_hook";
43 function groupisactivecheckbox (&$params) {
44 $group = group_get_object($params['group']);
45 if ($group->usesPlugin('scmsvn') || $group->usesPlugin('websvn')) {
46 parent::groupisactivecheckbox($params);
51 * It display a table with commit related to this tracker or task_extra_detail
53 * @param string $Query Query to be executed to get the commit entries.
54 * @param integer $group_id Group_id of the actual Group_id
57 function getCommitEntries($DBResult,$group_id) {
58 $group = &group_get_object($group_id);
59 $Rows= db_numrows($DBResult);
62 echo '<tr><td colspan="2">';
63 echo '<h4>'._('Links to related SVN commits').':</h4>';
65 $title_arr=$this->getTitleArr();
66 echo $GLOBALS['HTML']->listTableTop ($title_arr);
68 for ($i=0; $i<$Rows; $i++) {
69 $Row = db_fetch_array($DBResult);
70 echo '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'.
71 '<td>'. $this->getFileLink($group->getUnixName(),
72 $Row['file'],$Row['actual_version']). '</td>'.
73 '<td>'. date(_('Y-m-d'), $Row['svn_date']).'</td>'.
74 '<td>'. $this->getDiffLink($group->getUnixName(),
77 $Row['actual_version']).'</td>'.
78 '<td>'. $this->getActualVersionLink($group->getUnixName(),
79 $Row['file'], $Row['actual_version']).
81 <td>'. htmlspecialchars($Row['log_text']).'</td>
82 <td>'. util_make_link_u ($Row['author'],
83 user_get_object_by_name ($Row['author'])->getId(),
84 $Row['author']).'</td>
87 echo $GLOBALS['HTML']->listTableBottom();
93 * Return an array with titles of Box to display the entries
95 * @return Array The array containing the titles
98 function getTitleArr() {
100 $title_arr[]=_('Filename');
101 $title_arr[]=_('Date');
102 $title_arr[]=_('Previous Version');
103 $title_arr[]=_('Current Version');
104 $title_arr[]=_('Log Message');
105 $title_arr[]=_('Author');
110 * Return a link to the File in svnweb
112 * @param String $GroupName is the Name of the project
113 * @param String $FileName is the FileName ( with path )
114 * @param Int $LatestRevision is the last revision for the file
116 * @return String The string containing a link to the File in the svnweb
119 function getFileLink($GroupName, $FileName, $LatestRevision) {
120 return util_make_link ('/scm/viewvc.php'.$FileName .
121 '?root='.$GroupName.'&view=log&rev=' .
127 * Return a link to the File in viewcvs in the specified Version
129 * @param String $GroupName is the Name of the project
130 * @param String $FileName is the FileName ( with path )
131 * @param String $Version the version to retrieve
133 * @return String The string containing a link to the File in the viewcvs
136 function getActualVersionLink($GroupName, $FileName, $Version) {
137 return util_make_link ('/scm/viewvc.php'.$FileName .
138 '?root='.$GroupName.'&rev='.$Version,
143 * Return a link to the diff between two versions of a File in viewcvs
145 * @param String $GroupName is the Name of the project
146 * @param String $FileName is the FileName ( with path )
147 * @param String $PrevVersion First version to retrieve
148 * @param String $ActualVersion Second version to retrieve
150 * @return String The string containing a link to the File in the cvsweb
153 function getDiffLink($GroupName, $FileName, $PrevVersion, $ActualVersion) {
154 return util_make_link ('/scm/viewvc.php'.$FileName .
155 '?root='.$GroupName.'&r1='.$PrevVersion .
156 '&r2='.$ActualVersion,
157 _('Diff To').' '.$PrevVersion);
162 * Function to add svntracker lines to a loginfo file
164 * @param string $path The filename of loginfo
167 /*function addCvsTrackerToFile($path) {
168 global $cvs_binary_version;
170 $FOut = fopen($path, "a");
172 fwrite($FOut, "# BEGIN added by gforge-plugin-cvstracker\n");
173 if ( $cvs_binary_version == "1.12" ) {
174 $Line = "ALL ( php -q -d include_path=".ini_get('include_path').
175 " ".forge_get_config('plugins_path')."/cvstracker/bin/post.php".
178 if ( $cvs_binary_version == "1.11") {
179 $Line = "ALL ( php -q -d include_path=".ini_get('include_path').
180 " ".forge_get_config('plugins_path')."/cvstracker/bin/post.php".
184 fwrite($FOut, "# END added by gforge-plugin-cvstracker\n");
190 * Retrieve a file into a temporary directory from a SVN server
192 * @param String $repos Repository Name
193 * @param String $file File Name
195 * return String the FileName in the working repository
197 /*function getCvsFile($repos,$file) {
198 $actual_dir = getcwd();
199 $tempdirname = tempnam("/tmp","cvstracker");
202 if (!unlink($tempdirname))
205 // Create the temporary directory and returns its name.
206 if (!mkdir($tempdirname))
209 if (!chdir($tempdirname))
211 system("cvs -d ".$repos." co ".$file);
214 return $tempdirname.$file;
218 * putCvsFile commit a file to the repository
220 * @param String $repos Repository
221 * @param String $file to commit
222 * @param String $message to commit
224 /*function putCvsFile($repos,$file,$message="Automatic updated by cvstracker") {
225 system("cvs -d ".$repos." ci -m \"".$message."\" ".$file);
230 * The function to be called for a Hook
232 * @param String $hookname The name of the hookname that has been happened
233 * @param String $params The params of the Hook
236 function CallHook ($hookname, &$params) {
237 global $group_id, $G_SESSION, $HTML, $use_svntrackerplugin,$aid ;
239 if ($hookname == "artifact_extra_detail") {
240 $DBResult = db_query_params ('SELECT * FROM plugin_svntracker_data_master,
241 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',
243 $this->getCommitEntries($DBResult, $group_id);
244 } elseif ($hookname == "task_extra_detail") {
245 $DBResult = db_query_params ('SELECT * FROM plugin_svntracker_data_master,
246 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',
247 array ($params['task_id']));
248 $this->getCommitEntries($DBResult, $group_id);
249 } elseif ($hookname == 'cmd_for_post_commit_hook') {
250 $params['hooks'][$this->name] = '/usr/bin/php -d include_path='.ini_get('include_path').
251 ' '.forge_get_config('plugins_path').'/svntracker/bin/post.php '.$params['repos'].' "$2"';
252 } /*elseif ($hookname == "update_svn_repository") {
253 $Group = group_get_object($params["group_id"]);
254 if ($Group->usesPlugin("cvstracker")) {
256 $FIn = fopen(getCvsFile( $params["file_name"],
257 "CVSROOT/loginfo"),"r");
259 while (!feof($FIn)) {
260 $Line = fgets ($FIn);
261 if(!preg_match("/^#/", $Line) &&
262 preg_match("/cvstracker/",$Line)) {
268 if($LineFound==FALSE) {
269 $newfile=getCvsFile($params["file_name"],
271 $this->addCvsTrackerToFile($newfile);
272 $this->putCvsFile($params["file_name"],
282 // c-file-style: "bsd"