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 SCMPlugin {
25 function CVSPlugin () {
28 require_once $GLOBALS['gfconfig'].'plugins/scmcvs/config.php' ;
30 $this->name = 'scmcvs';
34 $this->hooks[] = 'scm_snapshots_and_tarballs' ;
37 $this->default_cvs_server = $default_cvs_server ;
39 $this->cvs_root = $cvs_root;
41 $this->cvs_root = "/cvsroot";
43 //$this->default_cvs_server = $default_cvs_server ;
44 //$this->this_server = $this_server ;
45 $this->enabled_by_default = $enabled_by_default ;
48 function getDefaultServer() {
49 return $this->default_cvs_server;
52 function CallHook ($hookname, $params) {
56 case 'scm_snapshots_and_tarballs':
57 $this->generateSnapshots ($params) ;
60 parent::CallHook ($hookname, $params) ;
64 function getPage ($group_id) {
67 $project =& group_get_object($group_id);
68 if (!$project || !is_object($project)) {
70 } elseif ($project->isError()) {
74 if ($project->usesPlugin($this->name)) {
76 print _('Some CVS documentation is available <a href="http://www.nongnu.org/cvs/">Here</a>');
78 $cvsrootend=$project->getSCMBox().':/cvsroot/'.$project->getUnixName();
79 $cvsrootend = $project->getSCMBox().':'.$this->cvs_root.'/'.$project->getUnixName();
81 // Table for summary info
82 print '<table width="100%"><tr valign="top"><td width="65%">' ;
84 // Anonymous CVS Instructions
85 if ($project->enableAnonSCM()){
86 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>');
89 <tt>cvs -d :pserver:anonymous@' . $cvsrootend.' login</tt><br/>
90 <tt>cvs -d :pserver:anonymous@' . $cvsrootend.' checkout <em>'._('modulename').'</em></tt>
95 if (session_loggedin ()) {
96 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> with the proper value. Enter your site password when prompted.</p>');
99 <tt>export CVS_RSH=ssh</tt><br/>
101 $u = session_get_user();
102 print $u->getUnixName();
103 print '@'.$cvsrootend.' checkout <em>'._('modulename').'</em></tt>
106 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>');
109 <tt>export CVS_RSH=ssh</tt><br/>
110 <tt>cvs -d :ext:<em>'._('developername').'</em>@'.$cvsrootend.' checkout <em>'._('modulename').'</em></tt>
115 if ($this->browserDisplayable ($project)) {
117 print util_make_link ("/snapshots.php?group_id=$group_id",
118 _('Download The Nightly CVS Tree Snapshot')
122 print '</td><td width="35%" valign="top">' ;
125 echo $HTML->boxTop(_('Repository History'));
126 echo $this->getDetailedStats(array('group_id'=>$group_id)).'<p>';
127 if ($this->browserDisplayable ($project)) {
128 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>');
130 echo util_make_link ("/scm/viewvc.php/?root=".$project->getUnixName(),
131 _('Browse CVS Repository')
134 $hook_params['project_name'] = $project->getUnixName();
135 plugin_hook ("cvs_stats", $hook_params) ;
137 echo $HTML->boxBottom();
138 print '</td></tr></table>' ;
142 function adminUpdate ($params) {
143 $group =& group_get_object($params['group_id']);
144 if (!$group || !is_object($group)) {
146 } elseif ($group->isError()) {
149 if ($group->usesPlugin($this->name)) {
150 if (array_key_exists('scmcvs_enable_anoncvs', $params)){
151 $group->SetUsesAnonSCM(true);
153 $group->SetUsesAnonSCM(false);
155 if (array_key_exists('scmcvs_enable_pserver', $params)){
156 $group->SetUsesPserver(true);
158 $group->SetUsesPserver(false);
163 // This function is used to render checkboxes below
166 return 'checked="checked"';
172 function getAdminPage ($params) {
173 $group =& group_get_object($params['group_id']);
175 if ($group->usesPlugin($this->name)) {
177 if ($group->isPublic()) {
178 print '<input type="checkbox" name="scmcvs_enable_anoncvs" value="1" '.$this->c($group->enableAnonSCM()).'/><strong>'._('Enable Anonymous Access').'</strong><br />';
180 print '<input type="checkbox" name="scmcvs_enable_anoncvs" value="1" '.$this->c($group->enableAnonSCM()).' DISABLED/>'._('Enable Anonymous Access').' <strong>'._("You project is private and so, you can't turn Anonymous Access on").'</strong><br />';
183 print '<input type="checkbox" name="scmcvs_enable_pserver" value="1" '.$this->c($group->enablePserver()).' /><strong>'._('Enable pserver').'</strong></p>' ;
187 function getStats ($params) {
188 $group_id = $params['group_id'] ;
189 $project =& group_get_object($group_id);
190 if (!$project || !is_object($project)) {
192 } elseif ($project->isError()) {
196 if ($project->usesPlugin($this->name)) {
197 $result = db_query_params ('
198 SELECT sum(commits) AS commits, sum(adds) AS adds
202 $commit_num = db_result($result,0,'commits');
203 $add_num = db_result($result,0,'adds');
210 echo ' (CVS: '.sprintf(_('<strong>%1$s</strong> commits, <strong>%2$s</strong> adds'), number_format($commit_num, 0), number_format($add_num, 0)).")";
214 function getDetailedStats ($params) {
216 $group_id = $params['group_id'] ;
219 SELECT u.realname, u.user_name, u.user_id, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined
220 FROM stats_cvs_user s, users u
221 WHERE group_id=\''.$group_id.'\' AND s.user_id=u.user_id AND (commits>0 OR adds >0)
222 GROUP BY u.user_id, realname, user_name, u.user_id
223 ORDER BY combined DESC, realname;
226 if (db_numrows($result) > 0) {
227 $tableHeaders = array(
232 echo $HTML->listTableTop($tableHeaders);
235 $total = array('adds' => 0, 'commits' => 0);
237 while($data = db_fetch_array($result)) {
238 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
239 echo '<td width="50%">' ;
240 echo util_make_link_u ($data['user_name'], $data['user_id'], $data['realname']) ;
241 echo '</td><td width="25%" align="right">'.$data['adds']. '</td>'.
242 '<td width="25%" align="right">'.$data['commits'].'</td></tr>';
243 $total['adds'] += $data['adds'];
244 $total['commits'] += $data['commits'];
247 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
248 echo '<td width="50%"><strong>'._('Total').':</strong></td>'.
249 '<td width="25%" align="right"><strong>'.$total['adds']. '</strong></td>'.
250 '<td width="25%" align="right"><strong>'.$total['commits'].'</strong></td>';
252 echo $HTML->listTableBottom();
253 echo '<hr size="1" />';
257 function createOrUpdateRepo ($params) {
258 $group_id = $params['group_id'] ;
260 $project =& group_get_object($group_id);
261 if (!$project || !is_object($project)) {
263 } elseif ($project->isError()) {
267 if (! $project->usesPlugin ($this->name)) {
271 $repo = $this->cvs_root . '/' . $project->getUnixName() ;
272 $locks_dir = $this->cvs_root . '/cvs-locks/' . $project->getUnixName() ;
273 $unix_group = 'scm_' . $project->getUnixName() ;
275 $repo_exists = false ;
276 if (is_dir ($repo) && is_dir ("$repo/CVSROOT")) {
277 $repo_exists = true ;
281 system ("cvs -d $repo init") ;
282 system ("mkdir -p $locks_dir") ;
285 system ("chgrp -R $unix_group $repo $locks_dir") ;
286 system ("chmod 3777 $locks_dir") ;
287 if ($project->enableAnonSCM()) {
288 system ("chmod -R g+wXs,o+rX-w $repo") ;
290 system ("chmod -R g+wXs,o-rwx $repo") ;
294 function generateSnapshots ($params) {
295 $group_id = $params['group_id'] ;
297 $project =& group_get_object($group_id);
298 if (!$project || !is_object($project)) {
300 } elseif ($project->isError()) {
304 $group_name = $project->getUnixName();
306 $snapshot = $sys_scm_snapshots_path.'/'.$group_name.'-scm-latest.tar.gz';
307 $tarball = $sys_scm_tarballs_path.'/'.$group_name.'-scmroot.tar.gz';
309 if (! $project->usesPlugin ($this->name)
310 || ! $project->enableAnonSCM()) {
316 $repo = $this->cvs_root . '/' . $project->getUnixName() ;
318 $repo_exists = false ;
319 if (is_dir ($repo) && is_dir ("$repo/CVSROOT")) {
320 $repo_exists = true ;
330 $compression = --gzip
332 Déléguer la suite à un script shell
334 system ("scmcvs-snapshots.sh $repo $group_name $snapshot")
338 $today=$(date +%Y-%m-%d)
339 mkdir -p $group_name-$today
340 cd $group_name-$today
341 cvs -d $repo checkout .
343 tar cf snapshot.tar.compressed $compression $group_name-$today
345 mv snapshot.tar.compressed $snapshot
354 // c-file-style: "bsd"