2 /** FusionForge CVS plugin
4 * Copyright 2004-2009, Roland Mas
6 * This file is part of FusionForge.
8 * FusionForge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version.
13 * FusionForge is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with FusionForge; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 class CVSPlugin extends SCM {
25 function CVSPlugin () {
29 $this->name = 'scmcvs';
31 $this->hooks[] = 'scm_page';
32 $this->hooks[] = 'scm_admin_update';
33 $this->hooks[] = 'scm_admin_page';
34 $this->hooks[] = 'scm_stats';
35 $this->hooks[] = 'scm_createrepo' ;
36 $this->hooks[] = 'scm_plugin';
38 require_once $GLOBALS['gfconfig'].'plugins/scmcvs/config.php' ;
40 $this->default_cvs_server = $default_cvs_server ;
42 $this->cvs_root = $cvs_root;
44 $this->cvs_root = "/cvsroot";
46 //$this->default_cvs_server = $default_cvs_server ;
47 //$this->this_server = $this_server ;
48 $this->enabled_by_default = $enabled_by_default ;
53 function getDefaultServer() {
54 return $this->default_cvs_server;
57 function CallHook ($hookname, $params) {
62 $group_id = $params['group_id'] ;
63 $this->getPage ($group_id) ;
65 case 'scm_admin_update':
66 $this->adminUpdate ($params) ;
68 case 'scm_admin_page':
69 $this->getAdminPage ($params) ;
72 $this->getStats ($params) ;
74 case 'scm_createrepo':
75 $this->createOrUpdateRepo ($params) ;
78 $scm_plugins=& $params['scm_plugins'];
79 $scm_plugins[]=$this->name;
86 function getPage ($group_id) {
89 $project =& group_get_object($group_id);
90 if (!$project || !is_object($project)) {
92 } elseif ($project->isError()) {
96 if ($project->usesPlugin($this->name)) {
98 print _('Some CVS documentation is available <a href="http://www.nongnu.org/cvs/">Here</a>');
100 $cvsrootend=$project->getSCMBox().':/cvsroot/'.$project->getUnixName();
101 $cvsrootend = $project->getSCMBox().':'.$this->cvs_root.'/'.$project->getUnixName();
103 // CVS browser links must be displayed if
104 // project enables anon CVS or if logged-in
105 // user is a member of the group
106 $displayCvsBrowser = $project->enableAnonSCM();
107 if(session_loggedin()) {
108 $perm =& $project->getPermission(session_get_user());
109 if ($perm && is_object($perm) && !$perm->isError() && $perm->isMember()) {
110 $displayCvsBrowser = true;
114 // Table for summary info
115 print '<table width="100%"><tr valign="top"><td width="65%">' ;
117 // Anonymous CVS Instructions
118 if ($project->enableAnonSCM()){
119 echo _('<p><b>Anonymous CVS Access</b></p><p>This project\'s CVS repository can be checked out through anonymous (pserver) CVS with the following instruction set. The module you wish to check out must be specified as the <i>modulename</i>. When prompted for a password for <i>anonymous</i>, simply press the Enter key.</p>');
122 <tt>cvs -d :pserver:anonymous@' . $cvsrootend.' login</tt><br/>
123 <tt>cvs -d :pserver:anonymous@' . $cvsrootend.' checkout <em>'._('modulename').'</em></tt>
128 echo _('<p><b>Developer CVS Access via SSH</b></p><p>Only project developers can access the CVS tree via this method. SSH must be installed on your client machine. Substitute <i>modulename</i> and <i>developername</i> with the proper values. Enter your site password when prompted.</p>');
131 <tt>export CVS_RSH=ssh</tt><br/>
132 <tt>cvs -d :ext:<em>'._('developername').'</em>@'.$cvsrootend.' checkout <em>'._('modulename').'</em></tt>
136 if ($displayCvsBrowser) {
138 print util_make_link ("/snapshots.php?group_id=$group_id",
139 _('Download The Nightly CVS Tree Snapshot')
143 print '</td><td width="35%" valign="top">' ;
146 echo $HTML->boxTop(_('Repository History'));
147 echo $this->getDetailedStats(array('group_id'=>$group_id)).'<p>';
148 if ($displayCvsBrowser){
149 echo _('<b>Browse the CVS Tree</b><p>Browsing the CVS 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>');
151 echo util_make_link ("/scm/viewvc.php/?root=".$project->getUnixName(),
152 _('Browse CVS Repository')
155 $hook_params['project_name'] = $project->getUnixName();
156 plugin_hook ("cvs_stats", $hook_params) ;
158 echo $HTML->boxBottom();
159 print '</td></tr></table>' ;
163 function adminUpdate ($params) {
164 $group =& group_get_object($params['group_id']);
165 if (!$group || !is_object($group)) {
167 } elseif ($group->isError()) {
170 if ($group->usesPlugin($this->name)) {
171 if ($params['scmcvs_enable_anoncvs']) {
172 $group->SetUsesAnonSCM(true);
174 $group->SetUsesAnonSCM(false);
176 if ($params['scmcvs_enable_pserver']) {
177 $group->SetUsesPserver(true);
179 $group->SetUsesPserver(false);
184 // This function is used to render checkboxes below
187 return 'checked="checked"';
193 function getAdminPage ($params) {
194 $group =& group_get_object($params['group_id']);
196 if ($group->usesPlugin($this->name)) {
198 <input type="checkbox" name="scmcvs_enable_anoncvs" value="1" '.$this->c($group->enableAnonSCM()).' /><strong>'._('Enable Anonymous Access').'</strong><br />
199 <input type="checkbox" name="scmcvs_enable_pserver" value="1" '.$this->c($group->enablePserver()).' /><strong>'._('Enable pserver').'</strong></p>' ;
203 function getStats ($params) {
204 $group_id = $params['group_id'] ;
205 $project =& group_get_object($group_id);
206 if (!$project || !is_object($project)) {
208 } elseif ($project->isError()) {
212 if ($project->usesPlugin($this->name)) {
214 SELECT sum(commits) AS commits, sum(adds) AS adds
216 WHERE group_id='$group_id'");
217 $commit_num = db_result($result,0,'commits');
218 $add_num = db_result($result,0,'adds');
225 echo ' (CVS: '.sprintf(_('<strong>%1$s</strong> commits, <strong>%2$s</strong> adds'), number_format($commit_num, 0), number_format($add_num, 0)).")";
229 function getDetailedStats ($params) {
231 $group_id = $params['group_id'] ;
234 SELECT u.realname, u.user_name, u.user_id, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined
235 FROM stats_cvs_user s, users u
236 WHERE group_id=\''.$group_id.'\' AND s.user_id=u.user_id AND (commits>0 OR adds >0)
237 GROUP BY group_id, realname, user_name
238 ORDER BY combined DESC, realname;
241 if (db_numrows($result) > 0) {
242 $tableHeaders = array(
247 echo $HTML->listTableTop($tableHeaders);
250 $total = array('adds' => 0, 'commits' => 0);
252 while($data = db_fetch_array($result)) {
253 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
254 echo '<td width="50%">' ;
255 echo util_make_link_u ($data['user_name'], $data['user_id'], $data['realname']) ;
256 echo '</td><td width="25%" align="right">'.$data['adds']. '</td>'.
257 '<td width="25%" align="right">'.$data['commits'].'</td></tr>';
258 $total['adds'] += $data['adds'];
259 $total['commits'] += $data['commits'];
262 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
263 echo '<td width="50%"><strong>'._('Total').':</strong></td>'.
264 '<td width="25%" align="right"><strong>'.$total['adds']. '</strong></td>'.
265 '<td width="25%" align="right"><strong>'.$total['commits'].'</strong></td>';
267 echo $HTML->listTableBottom();
268 echo '<hr size="1" />';
272 function createOrUpdateRepo ($params) {
273 return true ; // Disabled for now
275 $group_id = $params['group_id'] ;
277 $project =& group_get_object($group_id);
278 if (!$project || !is_object($project)) {
280 } elseif ($project->isError()) {
284 if (! $project->usesPlugin ($this->name)) {
288 $repo = $this->cvs_root . '/' . $project->getUnixName() ;
289 $unix_group = 'scm_' . $project->getUnixName() ;
291 $repo_exists = false ;
292 if (is_dir ($repo) && is_dir ("$repo/CVSROOT")) {
293 $repo_exists = true ;
297 system ("cvs -d$repo init") ;
300 system ("chgrp -R $unix_group $repo") ;
301 if ($project->enableAnonSCM()) {
302 system ("chmod -R g+wXs,o+rX-w $repo") ;
304 system ("chmod -R g+wXs,o-rwx $repo") ;
311 // c-file-style: "bsd"