2 /** FusionForge Subversion plugin
4 * Copyright 2003-2009, Roland Mas
5 * Copyright 2004, GForge, LLC
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 class SVNPlugin extends SCMPlugin {
26 function SVNPlugin () {
29 $this->name = 'scmsvn';
32 require_once $gfconfig.'plugins/scmsvn/config.php' ;
34 $this->default_svn_server = $default_svn_server ;
35 $this->enabled_by_default = $enabled_by_default ;
36 $this->use_ssh = $use_ssh;
37 $this->use_dav = $use_dav;
38 $this->use_ssl = $use_ssl;
39 $this->svn_root = $svn_root;
44 function getDefaultServer() {
45 return $this->default_svn_server ;
48 function getBlurb () {
49 return _('<p>Documentation for Subversion (sometimes referred to as "SVN") is available <a href="http://svnbook.red-bean.com/">here</a>.</p>') ;
52 function getInstructionsForAnon ($project) {
53 $b = _('<p><b>Anonymous Subversion Access</b></p><p>This project\'s SVN repository can be checked out through anonymous access with the following command(s).</p>');
56 $b .= '<tt>svn checkout svn://'.$project->getSCMBox().'/'.$this->svn_root.'/'.$project->getUnixName().'</tt><br />';
59 $b .= '<tt>svn checkout --username anonsvn http'.(($this->use_ssl) ? 's' : '').'://' . $project->getSCMBox(). '/' . $this->svn_root .'/'. $project->getUnixName() .'</tt><br/><br/>';
60 $b .= _('The password is \'anonsvn\'').'<br/>';
66 function getInstructionsForRW ($project) {
69 $b .= _('<p><b>Developer Subversion Access via SSH</b></p><p>Only project developers can access the SVN tree via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper values. Enter your site password when prompted.</p>');
70 $b .= '<p><tt>svn checkout svn+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . '/'. $this->svn_root .'/'. $project->getUnixName().'</tt></p>' ;
73 $b .= _('<p><b>Developer Subversion Access via DAV</b></p><p>Only project developers can access the SVN tree via this method. Substitute <i>developername</i> with the proper values. Enter your site password when prompted.</p>');
74 $b .= '<p><tt>svn checkout --username <i>'._('developername').'</i> http'.(($this->use_ssl) ? 's' : '').'://'. $project->getSCMBox() .'/'. $this->svn_root .'/'.$project->getUnixName().'</tt></p>' ;
80 function getStats ($params) {
81 $project = $this->checkParams ($params) ;
86 if ($project->usesPlugin ($this->name)) {
87 list($commit_num, $add_num) = $this->getTotalStats($project->getID());
88 echo ' (SVN: '.sprintf(_('<strong>%1$s</strong> updates, <strong>%2$s</strong> adds'), number_format($commit_num, 0), number_format($add_num, 0)).')';
92 // Get the total stats for a group
93 function getTotalStats($group_id) {
94 $result = db_query_params ('
95 SELECT SUM(commits) AS commits, SUM(adds) AS adds
99 $commit_num = db_result($result,0,0);
100 $add_num = db_result($result,0,1);
107 return array($commit_num, $add_num);
110 function getDetailedStats ($params) {
112 $group_id = $params['group_id'] ;
115 SELECT u.realname, u.user_name, u.user_id, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined
116 FROM stats_cvs_user s, users u
117 WHERE group_id=\''.$group_id.'\' AND s.user_id=u.user_id AND (commits>0 OR adds >0)
118 GROUP BY group_id, realname, user_name, u.user_id
119 ORDER BY combined DESC, realname;
122 if (db_numrows($result) > 0) {
123 $tableHeaders = array(
128 echo $HTML->listTableTop($tableHeaders);
131 $total = array('adds' => 0, 'commits' => 0);
133 while($data = db_fetch_array($result)) {
134 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
135 echo '<td width="50%">' ;
136 echo util_make_link_u ($data['user_name'], $data['user_id'], $data['realname']) ;
137 echo '</td><td width="25%" align="right">'.$data['adds']. '</td>'.
138 '<td width="25%" align="right">'.$data['commits'].'</td></tr>';
139 $total['adds'] += $data['adds'];
140 $total['commits'] += $data['commits'];
143 list($commit_num, $add_num) = $this->getTotalStats($group_id);
144 if ($commit_num > $total['commits'] ||
145 $add_num > $total['adds']) {
146 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
147 echo '<td width="50%">' .
149 '</td><td width="25%" align="right">'.
150 ($add_num - $total['adds']) . '</td>'.
151 '<td width="25%" align="right">'.
152 ($commit_num - $total['commits']) .
156 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
157 echo '<td width="50%"><strong>'._('Total').':</strong></td>'.
158 '<td width="25%" align="right"><strong>'.$add_num. '</strong></td>'.
159 '<td width="25%" align="right"><strong>'.$commit_num.'</strong></td>';
161 echo $HTML->listTableBottom();
162 echo '<hr size="1" />';
166 function createOrUpdateRepo ($params) {
167 $project = $this->checkParams ($params) ;
172 if (! $project->usesPlugin ($this->name)) {
176 $repo = $this->svn_root . '/' . $project->getUnixName() ;
177 $unix_group = 'scm_' . $project->getUnixName() ;
179 $repo_exists = false ;
180 if (is_dir ($repo) && is_file ("$repo/format")) {
181 $repo_exists = true ;
185 system ("svnadmin create --fs-type fsfs $repo") ;
188 system ("chgrp -R $unix_group $repo") ;
189 if ($project->enableAnonSCM()) {
190 system ("chmod -R g+wXs,o+rX-w $repo") ;
192 system ("chmod -R g+wXs,o-rwx $repo") ;
199 // c-file-style: "bsd"