4 * svncommitemail -> scmhook commitEmail migration script
6 * Copyright 2013, Franck Villaume - TrivialDev
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once dirname(__FILE__).'/../www/env.inc.php';
26 require_once $gfcommon.'include/pre.php';
27 require_once $gfplugins.'scmhook/library/scmsvn/cronjobs/updateScmRepo.php';
29 $pm = plugin_manager_get_object();
33 $groupnames = db_query_params('SELECT g.group_name FROM plugins p, group_plugin gp, groups g WHERE plugin_name = $1 and gp.group_id = g.group_id and p.plugin_id = gp.plugin_id',
34 array('svncommitemail'));
37 if (db_numrows($groupnames) > 0) {
43 // is scmhook activated ?
44 // no ... -> activate the plugin
45 if (!$pm->PluginIsInstalled('scmhook')) {
46 $pm->activate('scmhook');
49 $pm->LoadPlugin('scmhook');
50 $pluginScmHook = $pm->GetPluginObject('scmhook');
51 $scmsvncronjob = new ScmSvnUpdateScmRepo();
53 while ($arrGroupNames = db_fetch_array($groupnames)) {
54 // -> register scmhook for these groups
55 $projectObject = group_get_object_by_publicname($arrGroupNames['group_name']);
56 if (!$projectObject->usesMail()) {
57 $projectObject->setUseMail(true);
59 $projectId = $projectObject->getID();
60 if (!$projectObject->usesPlugin('scmhook')) {
61 $projectObject->setPluginUse('scmhook');
62 $pluginScmHook->add($projectId);
64 $group = $projectObject; // need to be set due to use of global vars in commitEmail class
65 $enabledHooks = $pluginScmHook->getEnabledHooks($projectId);
66 // -> add commitEmail hook
68 $params['group_id'] = $projectId;
69 $params['scmsvn_commitEmail'] = 1;
70 foreach ($enabledHooks as $enableHook) {
71 $params[$enableHook] = 1;
73 $pluginScmHook->update($params);
74 $hooksArray = $pluginScmHook->getEnabledHooks($projectId);
75 unset($pluginScmHook);
76 $params['hooksString'] = implode('|',$hooksArray);
77 $params['scm_root'] = forge_get_config('repos_path', 'scmsvn') . '/' . $projectObject->getUnixName();
78 if ($scmsvncronjob->updateScmRepo($params)) {
79 db_query_params('UPDATE plugin_scmhook set need_update = $1 where id_group = $2', array(0, $projectId));
81 $projectObject->setPluginUse('svncommitemail', false);
85 $pm->deactivate('svncommitemail');
86 // Remove the symbolic link made if plugin has a www.
87 if (is_dir(forge_get_config('plugins_path') . '/svncommitemail/www')) { // if the plugin has a www dir delete the link to it
88 if (file_exists('../www/plugins/svncommitemail')) {
89 $result = unlink('../www/plugins/svncommitemail');
91 $feedback .= "\n"._('Soft link wasn\'t removed in www/plugins folder, please do so manually.');
96 // Remove the symbolic link made if plugin has a config.
97 if (file_exists(forge_get_config('config_path'). '/plugins/svncommitemail')) {
98 $result = unlink(forge_get_config('config_path'). '/plugins/svncommitemail'); // the apache group or user should have write perms in forge_get_config('config_path')/plugins folder...
100 $feedback .= _('Soft link wasn\'t removed in config folder, please do so manually.');