2 /** FusionForge ClearCase plugin
4 * Copyright 2003-2009, Roland Mas
5 * Copyright 2004, GForge, LLC
6 * Copyright (C) 2010-2012 Alain Peyrat - Alcatel-Lucent
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * 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 forge_define_config_item ('default_server', 'scmccase', forge_get_config ('web_host')) ;
26 forge_define_config_item ('tag_pattern', 'scmccase', '') ;
28 class CCasePlugin extends SCMPlugin {
29 function CCasePlugin () {
32 $this->name = "scmccase";
33 $this->text = 'CCASE';
34 $this->hooks[] = "scm_page";
35 $this->hooks[] = "scm_admin_update";
36 $this->hooks[] = "scm_admin_page";
37 $this->hooks[] = "scm_stats";
38 $this->hooks[] = "scm_createrepo";
39 $this->hooks[] = "scm_plugin";
44 function CallHook ($hookname, &$params) {
49 $group_id = $params['group_id'] ;
50 $this->display_scm_page ($group_id) ;
52 case "scm_admin_update":
53 $this->scm_admin_update ($params) ;
55 case "scm_admin_page":
56 $this->display_scm_admin_page ($params) ;
59 $this->display_stats ($params) ;
61 case 'scm_createrepo':
62 $this->createOrUpdateRepo ($params) ;
65 $scm_plugins=& $params['scm_plugins'];
66 $scm_plugins[]=$this->name;
73 function display_scm_page ($group_id) {
76 $project = group_get_object($group_id);
78 if ($project->usesPlugin ("scmccase")) {
79 $vob_tag = preg_replace("/GROUPNAME/", $project->getUnixName (), forge_get_config('tag_pattern', 'scmccase')) ;
81 print '<h2>ClearCase</h2>
82 <p>Documentation for ClearCase is probably available somewhere.
85 // Table for summary info
87 print '<table class="fullwidth"><tr class="top"><td class="twothirdswidth">' ;
91 echo "<b>".print(_('ClearCase Access'))."</b>" ;
94 printf (_('Either mount the VOB with <tt>cleartool mount %1$s</tt> or select the <tt>%1$s</tt> VOB in your ClearCase Explorer.'),
100 print '</td><td class="onethirdwidth">' ;
105 if (session_loggedin()) {
106 $perm =& $project->getPermission();
107 $anonymous = !$perm->isMember();
110 if ($project->enableAnonCVS() || !$anonymous) {
111 echo $HTML->boxTop(_('History'));
113 echo '<b>'._('Browse the ClearCase tree').'</b><p>'._('Browsing the ClearCase tree gives you a great view into the current status of this project\'s code. You may also view the complete histories of any file in the repository.').'</p>' ;
115 $browse_url = "http://" . $this->GetGroupServer($group_id) . "/ccweb" ;
116 // $browse_url = $browse_url . "?vob_tag=".$vob_tag ;
118 printf (_('<a href="%1$s">Browse</a> CCase tree'),
122 echo $HTML->boxBottom();
125 print '</td></tr></table>' ;
129 function scm_admin_update ($params) {
130 $group = group_get_object($params['group_id']);
132 if ($params['scmccase_ccase_server'] && $params['scmccase_ccase_server'] != "") {
133 $this->SetGroupServer ($params['group_id'], $params['scmccase_ccase_server']) ;
135 $this->SetGroupServer ($params['group_id'], $this->GetDefaultServer ()) ;
139 function display_scm_admin_page ($params) {
140 $group = group_get_object($params['group_id']);
142 if ( $group->usesPlugin ( $this->name ) ) {
143 print '<input type="text" name="scmccase_ccase_server" value="'.$this->GetGroupServer ($params['group_id']).'"> <strong>'._('ClearCase server').'</strong><br /><br />' ;
147 function display_stats ($params) {
148 $group_id = $params['group_id'] ;
149 $result = db_query_params ('
151 FROM plugin_scmccase_stats
154 $commit_num = db_result($result,0,0);
155 $add_num = db_result($result,0,1);
162 $commit_count=number_format($commit_num, 0);
163 $add_count=number_format($add_num, 0);
164 echo ' (CCase: <strong>'.$commit_count.'</strong> ';
165 printf(ngettext("commit","commits",$commit_count),$commit_count);
166 echo ', <strong>'.$add_count.'</strong> ';
167 printf(ngettext("add","adds",$add_count),$add_count);
172 function GetDefaultServer () {
173 return forge_get_config('default_server', 'scmccase') ;
176 function GetGroupServer ($group_id) {
177 $res = db_query_params ('SELECT ccase_host FROM plugin_scmccase_group_usage WHERE group_id = $1',
179 if (db_numrows($res) == 0) {
180 return forge_get_config('default_server', 'scmccase') ;
182 return db_result($res,0,'ccase_host');
186 function SetGroupServer ($group_id, $server) {
188 $res = db_query_params ('SELECT ccase_host FROM plugin_scmccase_group_usage WHERE group_id = $1',
190 if (db_numrows($res) == 0) {
191 $res = db_query_params ('INSERT INTO plugin_scmccase_group_usage (group_id, ccase_host) VALUES ($1, $2)',
195 $res = db_query_params ('UPDATE plugin_scmccase_group_usage SET ccase_host = $1 WHERE group_id = $2',
202 function createOrUpdateRepo ($params) {
203 return true ; // Disabled for now
205 $group_id = $params['group_id'] ;
207 $project = group_get_object($group_id);
208 if (!$project || !is_object($project)) {
210 } elseif ($project->isError()) {
214 if (! $project->usesPlugin ($this->name)) {
218 // TODO (by someone who uses ClearCase): trigger repository creation
224 // c-file-style: "bsd"