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';
29 $pm = plugin_manager_get_object();
32 $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',
33 array('svncommitemail'));
36 if (db_numrows($groupnames) > 0) {
42 if (!is_readable($gfplugins.'scmhook/library/scmsvn/cronjobs/updateScmRepo.php')) {
43 echo "FAILED: scmhook plugin is missing. Please install scmhook plugin and rerun the migration script.\n";
46 require_once $gfplugins.'scmhook/library/scmsvn/cronjobs/updateScmRepo.php';
47 // is scmhook activated ?
48 // no ... -> activate the plugin
49 if (!$pm->PluginIsInstalled('scmhook')) {
50 $pm->activate('scmhook');
53 $pm->LoadPlugin('scmhook');
54 $pluginScmHook = $pm->GetPluginObject('scmhook');
55 $scmsvncronjob = new ScmSvnUpdateScmRepo();
57 while ($arrGroupNames = db_fetch_array($groupnames)) {
58 // -> register scmhook for these groups
59 $projectObject = group_get_object_by_publicname($arrGroupNames['group_name']);
60 if (!$projectObject->usesMail()) {
61 $projectObject->setUseMail(true);
63 $projectId = $projectObject->getID();
64 if (!$projectObject->usesPlugin('scmhook')) {
65 $projectObject->setPluginUse('scmhook');
66 $pluginScmHook->add($projectId);
68 $group = $projectObject; // need to be set due to use of global vars in commitEmail class
69 $enabledHooks = $pluginScmHook->getEnabledHooks($projectId);
70 // -> add commitEmail hook
72 $params['group_id'] = $projectId;
73 $params['scmsvn_commitEmail'] = 1;
74 foreach ($enabledHooks as $enableHook) {
75 $params[$enableHook] = 1;
77 $pluginScmHook->update($params);
78 $hooksArray = $pluginScmHook->getEnabledHooks($projectId);
79 unset($pluginScmHook);
80 $params['hooksString'] = implode('|',$hooksArray);
81 $params['scm_root'] = forge_get_config('repos_path', 'scmsvn') . '/' . $projectObject->getUnixName();
82 if ($scmsvncronjob->updateScmRepo($params)) {
83 db_query_params('UPDATE plugin_scmhook set need_update = $1 where id_group = $2', array(0, $projectId));
85 $projectObject->setPluginUse('svncommitemail', false);
89 $pm->deactivate('svncommitemail');
90 // Remove the symbolic link made if plugin has a www.
91 if (is_dir(forge_get_config('plugins_path') . '/svncommitemail/www')) { // if the plugin has a www dir delete the link to it
92 if (file_exists('../www/plugins/svncommitemail')) {
93 $result = unlink('../www/plugins/svncommitemail');
95 $feedback .= "\n"._('Soft link wasn\'t removed in www/plugins folder, please do so manually.');
100 // Remove the symbolic link made if plugin has a config.
101 if (file_exists(forge_get_config('config_path'). '/plugins/svncommitemail')) {
102 $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...
104 $feedback .= _('Soft link wasn\'t removed in config folder, please do so manually.');