3 * GForge Plugin CVSTracker Class
5 * Copyright 2004 (c) Francisco Gimeno <kikov @nospam@ kikov.org>
6 * Copyright 2005 (c) Guillaume Smet <guillaume-gforge@smet.org>
9 * This file is part of GForge-plugin-cvstracker
11 * GForge-plugin-cvstracker 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-cvstracker 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
22 * along with GForge-plugin-cvstracker; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
27 * The cvstrackerPlugin class. It implements the Hooks for the presentation
28 * of table in tracker and task in detailed mode.
32 class cvstrackerPlugin extends Plugin {
33 function cvstrackerPlugin () {
35 $this->name = "cvstracker" ;
36 $this->text = "CVS<->Tracker";
37 $this->hooks[] = "groupisactivecheckbox";
38 $this->hooks[] = "groupisactivecheckboxpost";
39 $this->hooks[] = "artifact_extra_detail";
40 $this->hooks[] = "task_extra_detail";
41 $this->hooks[] = "update_cvs_repository";
42 $this->hooks[] = "get_cvs_loginfo_lines";
46 * It display a table with commit related to this tracker or task_extra_detail
48 * @param string $Query Query to be executed to get the commit entries.
49 * @param integer $group_id Group_id of the actual Group_id
52 function getCommitEntries($Query,$group_id) {
53 global $Language, $sys_shortdatefmt;
55 $group = &group_get_object($group_id);
57 if (!$group->usesPlugin($this->name)) {
61 $DBResult = db_query($Query);
62 $Rows= db_numrows($DBResult);
65 echo '<tr><td colspan="2">';
66 echo '<h4>'._('Links to related CVS commits').':</h4>';
68 $title_arr=$this->getTitleArr();
69 echo $GLOBALS['HTML']->listTableTop ($title_arr);
71 for ($i=0; $i<$Rows; $i++) {
72 $Row = db_fetch_array($DBResult);
73 echo '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'.
74 '<td>'. $this->getFileLink($group->getUnixName(),
75 $Row['file'],$Row['actual_version']). '</td>'.
76 '<td>'. date($sys_shortdatefmt, $Row['cvs_date']).'</td>'.
77 '<td>'. $this->getDiffLink($group->getUnixName(),
80 $Row['actual_version']).'</td>'.
81 '<td>'. $this->getActualVersionLink($group->getUnixName(),
82 $Row['file'], $Row['actual_version']).
84 <td>'. htmlspecialchars($Row['log_text']).'</td>
85 <td><a href="/users/'. $Row['author'].'">'.
86 $Row['author'].'</a></td>
89 echo $GLOBALS['HTML']->listTableBottom();
92 echo '<h4>'._('No commits have been made.').'</h4>';
97 * Return an array with titles of Box to display the entries
99 * @return Array The array containing the titles
102 function getTitleArr() {
105 $title_arr[]=_('Filename');
106 $title_arr[]=_('Date');
107 $title_arr[]=_('Previous Version');
108 $title_arr[]=_('Current Version');
109 $title_arr[]=_('Log Message');
110 $title_arr[]=_('Author');
115 * Return a link to the File in cvsweb
117 * @param String $GroupName is the Name of the project
118 * @param String $FileName is the FileName ( with path )
120 * @return String The string containing a link to the File in the cvsweb
123 function getFileLink($GroupName, $FileName, $LatestRevision) {
124 global $sys_default_domain;
125 return '<a href="/scm/viewvc.php/'.
126 $FileName.'?root='.$GroupName.'&view=log">'.$FileName.'</a>';
130 * Return a link to the File in cvsweb in the specified Version
132 * @param String $GroupName is the Name of the project
133 * @param String $FileName is the FileName ( with path )
134 * @param String $Version the version to retrieve
136 * @return String The string containing a link to the File in the cvsweb
139 function getActualVersionLink($GroupName, $FileName, $Version) {
140 global $sys_default_domain;
141 return '<a href="/scm/viewvc.php/'.
142 $FileName.'?root='.$GroupName.'&pathrev='.$Version.'&view=markup">'.
147 * Return a link to the diff between two versions of a File in cvsweb
149 * @param String $GroupName is the Name of the project
150 * @param String $FileName is the FileName ( with path )
151 * @param String $PrevVersion First version to retrieve
152 * @param String $ActualVersion Second version to retrieve
154 * @return String The string containing a link to the File in the cvsweb
157 function getDiffLink($GroupName, $FileName, $PrevVersion, $ActualVersion) {
158 global $sys_default_domain,$Language;
159 return '<a href="/scm/viewvc.php/'.
160 $FileName.'?root='.$GroupName.'&r1='.$PrevVersion.'&r2='.
162 _('Diff To').' '.$PrevVersion.'</a>';
167 * Function to add cvstracker lines to a loginfo file
169 * @param string $path The filename of loginfo
172 function addCvsTrackerToFile($path) {
173 global $sys_plugins_path, $sys_users_host, $cvs_binary_version;
175 $FOut = fopen($path, "a");
177 fwrite($FOut, "# BEGIN added by gforge-plugin-cvstracker\n");
178 if ( $cvs_binary_version == "1.12" ) {
179 $Line = "ALL ( php -q -d include_path=".ini_get('include_path').
180 " ".$sys_plugins_path."/cvstracker/bin/post.php".
183 if ( $cvs_binary_version == "1.11") {
184 $Line = "ALL ( php -q -d include_path=".ini_get('include_path').
185 " ".$sys_plugins_path."/cvstracker/bin/post.php".
189 fwrite($FOut, "# END added by gforge-plugin-cvstracker\n");
195 * Function to get cvstracker loginfo lines
198 * return array with the loginfo lines.
200 function getCvsTrackerLogInfoLines() {
201 global $sys_plugins_path, $sys_users_host, $cvs_binary_version;
203 $array[]="# BEGIN added by gforge-plugin-cvstracker\n";
204 if ( $cvs_binary_version == "1.11" ) {
205 $array[] = "ALL ( php -q -d include_path=".ini_get('include_path').
206 " ".$sys_plugins_path."/cvstracker/bin/post.php".
208 }else { //it's version 1.12
209 $array[] = "ALL ( php -q -d include_path=".ini_get('include_path').
210 " ".$sys_plugins_path."/cvstracker/bin/post.php".
213 $array[]= "# END added by gforge-plugin-cvstracker\n";
219 * Retrieve a file into a temporary directory from a CVS server
221 * @param String $repos Repository Name
222 * @param String $file File Name
224 * return String the FileName in the working repository
226 function getCvsFile($repos,$file) {
227 $actual_dir = getcwd();
228 $tempdirname = tempnam("/tmp","cvstracker");
231 if (!unlink($tempdirname))
234 // Create the temporary directory and returns its name.
235 if (!mkdir($tempdirname))
238 if (!chdir($tempdirname))
240 system("cvs -d ".$repos." co ".$file);
243 return $tempdirname.$file;
247 * putCvsFile commit a file to the repository
249 * @param String $repos Repository
250 * @param String $file to commit
251 * @param String $message to commit
253 function putCvsFile($repos,$file,$message="Automatic updated by cvstracker") {
254 system("cvs -d ".$repos." ci -m \"".$message."\" ".$file);
259 * The function to be called for a Hook
261 * @param String $hookname The name of the hookname that has been happened
262 * @param String $params The params of the Hook
265 function CallHook ($hookname, $params) {
266 global $group_id,$Language, $G_SESSION, $HTML, $use_cvstrackerplugin,$aid ;
267 $use_cvstrackerplugin = getIntFromRequest('use_cvstrackerplugin');
268 if ($hookname == "groupisactivecheckbox") {
269 //Check if the group is active
270 $group = &group_get_object($group_id);
271 if ($group->usesPlugin('scmcvs')) {
274 echo ' <input type="CHECKBOX" name="use_cvstrackerplugin" value="1" ';
275 // Checked or Unchecked?
276 if ( $group->usesPlugin ( $this->name ) ) {
282 echo "<strong>Use ".$this->text." Plugin</strong>";
286 } elseif ($hookname == "groupisactivecheckboxpost") {
287 $group = &group_get_object($group_id);
288 if ( $use_cvstrackerplugin == 1 ) {
289 $group->setPluginUse ( $this->name );
291 $group->setPluginUse ( $this->name, false );
293 } elseif ($hookname == "artifact_extra_detail") {
294 $Query="SELECT * FROM plugin_cvstracker_data_master,".
295 "plugin_cvstracker_data_artifact".
296 " WHERE plugin_cvstracker_data_artifact.group_artifact_id='$aid' ".
297 " AND plugin_cvstracker_data_master.holder_id=".
298 " plugin_cvstracker_data_artifact.id ORDER BY cvs_date";
299 $this->getCommitEntries($Query, $group_id);
300 } elseif ($hookname == "task_extra_detail") {
301 $Query="SELECT * FROM plugin_cvstracker_data_master,".
302 "plugin_cvstracker_data_artifact".
303 " WHERE plugin_cvstracker_data_artifact.project_task_id='".
304 $params['task_id']."' ".
305 " AND plugin_cvstracker_data_master.holder_id=".
306 " plugin_cvstracker_data_artifact.id ORDER BY cvs_date";
307 $this->getCommitEntries($Query, $group_id);
308 } elseif ($hookname == "update_cvs_repository") {
309 $Group = group_get_object($params["group_id"]);
310 if ($Group->usesPlugin("cvstracker")) {
312 $FIn = fopen(getCvsFile( $params["file_name"],
313 "CVSROOT/loginfo"),"r");
315 while (!feof($FIn)) {
316 $Line = fgets ($FIn);
317 if(!preg_match("/^#/", $Line) &&
318 preg_match("/cvstracker/",$Line)) {
324 if($LineFound==FALSE) {
325 $newfile=getCvsFile($params["file_name"],
327 $this->addCvsTrackerToFile($newfile);
328 $this->putCvsFile($params["file_name"],
332 } elseif ($hookname == "get_cvs_loginfo_lines") {
333 $GLOBALS['loginfo_lines']=$this->getCvsTrackerLogInfoLines();
340 // c-file-style: "bsd"