2 /** FusionForge ClearCase plugin
4 * Copyright 2003-2009, Roland Mas
5 * Copyright 2004, GForge, LLC
6 * Copyright (C) 2010-2012 Alain Peyrat - Alcatel-Lucent
7 * Copyright 2014, Franck Villaume - TrivialDev
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation; either version 2 of the License,
14 * or (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * 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 forge_define_config_item ('default_server', 'scmccase', forge_get_config ('scm_host')) ;
27 forge_define_config_item ('tag_pattern', 'scmccase', '') ;
29 class CCasePlugin extends SCMPlugin {
30 function __construct() {
32 parent::__construct();
33 $this->name = "scmccase";
34 $this->text = 'CCASE';
35 $this->hooks[] = "scm_page";
36 $this->hooks[] = "scm_admin_update";
37 $this->hooks[] = "scm_admin_page";
38 $this->hooks[] = "scm_stats";
39 $this->hooks[] = "scm_createrepo";
40 $this->hooks[] = "scm_plugin";
45 function CallHook($hookname, &$params) {
50 $group_id = $params['group_id'] ;
51 $this->display_scm_page ($group_id) ;
53 case "scm_admin_update":
54 $this->scm_admin_update ($params) ;
56 case "scm_admin_page":
57 $this->display_scm_admin_page ($params) ;
60 $this->display_stats ($params) ;
62 case 'scm_createrepo':
63 $this->createOrUpdateRepo ($params) ;
66 $scm_plugins=& $params['scm_plugins'];
67 $scm_plugins[]=$this->name;
74 function display_scm_page ($group_id) {
77 $project = group_get_object($group_id);
79 if ($project->usesPlugin ("scmccase")) {
80 $vob_tag = preg_replace("/GROUPNAME/", $project->getUnixName (), forge_get_config('tag_pattern', 'scmccase')) ;
82 print '<h2>ClearCase</h2>
83 <p>Documentation for ClearCase is probably available somewhere.
86 // Table for summary info
88 print '<table class="fullwidth"><tr class="top"><td class="twothirdswidth">' ;
92 echo "<b>"._('ClearCase Access')."</b>" ;
95 printf (_('Either mount the VOB with <kbd>cleartool mount %1$s</kbd> or select the <kbd>%1$s</kbd> VOB in your ClearCase Explorer.'),
101 print '</td><td class="onethirdwidth">' ;
106 if (session_loggedin()) {
107 $perm =& $project->getPermission();
108 $anonymous = !$perm->isMember();
111 if ($project->enableAnonCVS() || !$anonymous) {
112 echo $HTML->boxTop(_('History'));
114 echo '<b>'._('Browse the ClearCase tree').'</b>';
116 echo sprintf(_("Browsing the %s tree gives you a view into the current status of this project's code."), 'ClearCase');
118 echo _('You may also view the complete histories of any file in the repository.');
120 $browse_url = "http://" . $this->GetGroupServer($group_id) . "/ccweb" ;
121 // $browse_url = $browse_url . "?vob_tag=".$vob_tag ;
122 echo html_e('p', array(), util_make_link($browse_url, _('Browse the ClearCase tree')));
123 echo $HTML->boxBottom();
126 print '</td></tr></table>' ;
130 function scm_admin_update ($params) {
131 $group = group_get_object($params['group_id']);
133 if ($params['scmccase_ccase_server'] && $params['scmccase_ccase_server'] != "") {
134 $this->SetGroupServer ($params['group_id'], $params['scmccase_ccase_server']) ;
136 $this->SetGroupServer ($params['group_id'], $this->GetDefaultServer ()) ;
140 function display_scm_admin_page ($params) {
141 $group = group_get_object($params['group_id']);
143 if ( $group->usesPlugin ( $this->name ) ) {
144 print '<input type="text" name="scmccase_ccase_server" value="'.$this->GetGroupServer ($params['group_id']).'"> <strong>'._('ClearCase server').'</strong><br /><br />' ;
148 function display_stats ($params) {
149 $group_id = $params['group_id'] ;
150 $result = db_query_params ('
152 FROM plugin_scmccase_stats
155 $commit_num = db_result($result,0,0);
156 $add_num = db_result($result,0,1);
163 $commit_count=number_format($commit_num, 0);
164 $add_count=number_format($add_num, 0);
165 echo ' (CCase: <strong>'.$commit_count.'</strong> ';
166 printf(ngettext("commit","commits",$commit_count),$commit_count);
167 echo ', <strong>'.$add_count.'</strong> ';
168 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
221 function scm_admin_form(&$params) {
223 $project = $this->checkParams($params);
227 session_require_perm('project_admin', $params['group_id']);
229 if (forge_get_config('allow_multiple_scm') && ($params['allow_multiple_scm'] > 1)) {
230 echo html_ao('div', array('id' => 'tabber-'.$this->name, 'class' => 'tabbertab'));
232 if (forge_get_config('allow_multiple_scm') && ($params['allow_multiple_scm'] > 1)) {
233 echo html_ac(html_ap() - 1);
240 // c-file-style: "bsd"