3 * Copyright 2011, Franck Villaume - Capgemini
4 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
6 * This file is part of FusionForge. FusionForge is free software;
7 * you can redistribute it and/or modify it under the terms of the
8 * GNU General Public License as published by the Free Software
9 * Foundation; either version 2 of the Licence, or (at your option)
12 * FusionForge is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * you need to implement only function updateScmRepo($params)
24 * $params is an array containing :
25 * $params['group_id'] = $group_id
26 * $params['hooksString'] = list of hooks to be deploy, separator is |
27 * $params['scm_root'] = directory containing the scm repository
31 * scmsvn_updateScmRepo - update the scmrepo with the new hooks
33 * @params Array the complete array description
34 * @return boolean success or not
36 function updateScmRepo($params) {
37 $group_id = $params['group_id'];
38 $hooksString = $params['hooksString'];
39 $svndir_root = $params['scm_root'];
40 $group = group_get_object($group_id);
41 $scmhookPlugin = new scmhookPlugin;
42 $hooksAvailable = $scmhookPlugin->getAvailableHooks($group_id);
43 $unixname = $group->getUnixName();
45 if (is_dir($svndir_root)) {
46 @unlink($svndir_root.'/hooks/pre-commit');
47 @unlink($svndir_root.'/hooks/post-commit');
48 $hooksPreCommit = array();
49 $hooksPreRevPropChange = array();
50 $hooksPostCommit = array();
51 foreach ($hooksAvailable as $hook) {
52 switch ($hook->getHookType()) {
54 $hooksPreCommit[] = $hook;
57 case "pre-revprop-change": {
58 $hooksPreRevPropChange[] = $hook;
62 $hooksPostCommit[] = $hook;
66 //byebye hook.... we do not validate you...
72 foreach($hooksPreCommit as $hookPreCommit) {
73 if ($hookPreCommit->needCopy()) {
74 foreach($hookPreCommit->getFiles() as $hookPreCommitFile) {
75 @unlink($svndir_root.'/hooks/'.basename($hookPreCommitFile));
80 foreach($hooksPreRevPropChange as $hook) {
81 if ($hook->needCopy()) {
82 foreach($hook->getFiles() as $file) {
83 @unlink($svndir_root.'/hooks/'.basename($file));
88 foreach($hooksPostCommit as $hookPostCommit) {
89 if ($hookPostCommit->needCopy()) {
90 foreach($hookPostCommit->getFiles() as $hookPostCommitFile) {
91 @unlink($svndir_root.'/hooks/'.basename($hookPostCommitFile));
96 $newHooks = explode('|', $hooksString);
97 if (count($newHooks)) {
98 $newHooksPreCommit = array();
99 $newHooksPreRevPropChange = array();
100 $newHooksPostCommit = array();
101 foreach($newHooks as $newHook) {
102 foreach($hooksPreCommit as $hookPreCommit) {
103 if ($hookPreCommit->getClassname() == $newHook) {
104 $newHooksPreCommit[] = $hookPreCommit;
107 foreach($hooksPreRevPropChange as $hook) {
108 if ($hook->getClassname() == $newHook) {
109 $newHooksPreRevPropChange[] = $hook;
112 foreach($hooksPostCommit as $hookPostCommit) {
113 if ($hookPostCommit->getClassname() == $newHook) {
114 $newHooksPostCommit[] = $hookPostCommit;
120 foreach($newHooksPreCommit as $newHookPreCommit) {
121 if ($newHookPreCommit->needCopy()) {
122 foreach ($newHookPreCommit->getFiles() as $file) {
123 copy($file, $svndir_root.'/hooks/'.basename($file));
124 chmod($svndir_root.'/hooks/'.basename($file), 0755);
129 foreach($hooksPreRevPropChange as $newHook) {
130 if ($newHook->needCopy()) {
131 foreach ($newHook->getFiles() as $file) {
132 copy($file, $svndir_root.'/hooks/'.basename($file));
133 chmod($svndir_root.'/hooks/'.basename($file), 0755);
138 foreach($newHooksPostCommit as $newHookPostCommit) {
139 if ($newHookPostCommit->needCopy()) {
140 foreach ($newHookPostCommit->getFiles() as $file) {
141 copy($file, $svndir_root.'/hooks/'.basename($file));
142 chmod($svndir_root.'/hooks/'.basename($file), 0755);
147 if (count($newHooksPreCommit)) {
148 // prepare the pre-commit
149 $file = fopen("/tmp/pre-commit-$unixname.tmp", "w");
150 fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/pre-commit/head'));
152 foreach($newHooksPreCommit as $newHookPreCommit) {
153 $string .= $newHookPreCommit->getHookCmd()."\n";
156 fwrite($file, $string);
158 copy('/tmp/pre-commit-'.$unixname.'.tmp', $svndir_root.'/hooks/pre-commit');
159 chmod($svndir_root.'/hooks/pre-commit', 0755);
160 unlink('/tmp/pre-commit-'.$unixname.'.tmp');
162 @unlink($svndir_root.'/hooks/pre-commit');
165 if (count($newHooksPreRevPropChange)) {
166 // prepare the pre-revprop-change
167 $file = fopen("/tmp/pre-revprop-change-$unixname.tmp", "w");
168 fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/pre-revprop-change/head'));
170 foreach($newHooksPreRevPropChange as $hook) {
171 $string .= $hook->getHookCmd()."\n";
174 fwrite($file, $string);
176 copy('/tmp/pre-revprop-change-'.$unixname.'.tmp', $svndir_root.'/hooks/pre-revprop-change');
177 chmod($svndir_root.'/hooks/pre-revprop-change', 0755);
178 unlink('/tmp/pre-revprop-change-'.$unixname.'.tmp');
180 @unlink($svndir_root.'/hooks/pre-revprop-change');
183 if (count($newHooksPostCommit)) {
184 // prepare the post-commit
185 $file = fopen("/tmp/post-commit-$unixname.tmp", "w");
186 fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/post-commit/head'));
188 foreach($newHooksPostCommit as $newHookPostCommit) {
189 $string .= $newHookPostCommit->getHookCmd()."\n";
192 fwrite($file, $string);
194 copy('/tmp/post-commit-'.$unixname.'.tmp', $svndir_root.'/hooks/post-commit');
195 chmod($svndir_root.'/hooks/post-commit', 0755);
196 unlink('/tmp/post-commit-'.$unixname.'.tmp');