4 * svntracker -> scmhook commitTracker 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';
28 $pm = plugin_manager_get_object();
31 $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',
35 if (db_numrows($groupnames) > 0) {
41 if (!is_readable($gfplugins.'scmhook/library/scmsvn/cronjobs/updateScmRepo.php')) {
42 echo "FAILED: scmhook is missing. Please install scmhook plugin and rerun the migration script\n";
45 require_once $gfplugins.'scmhook/library/scmsvn/cronjobs/updateScmRepo.php';
46 // is scmhook activated ?
47 // no ... -> activate the plugin
48 if (!$pm->PluginIsInstalled('scmhook')) {
49 $pm->activate('scmhook');
52 $pm->LoadPlugin('scmhook');
53 $pluginScmHook = $pm->GetPluginObject('scmhook');
54 $scmsvncronjob = new ScmSvnUpdateScmRepo();
56 while ($arrGroupNames = db_fetch_array($groupnames)) {
57 // -> register scmhook for these groups
58 $projectObject = group_get_object_by_publicname($arrGroupNames['group_name']);
59 if (!$projectObject->usesTracker()) {
60 $projectObject->setUseTracker(true);
62 $projectId = $projectObject->getID();
63 if (!$projectObject->usesPlugin('scmhook')) {
64 $projectObject->setPluginUse('scmhook');
65 $pluginScmHook->add($projectId);
67 $group = $projectObject; // need to be set due to use of global vars in commitEmail class
68 $enabledHooks = $pluginScmHook->getEnabledHooks($projectId);
69 // -> add committracker hook
71 $params['group_id'] = $projectId;
72 $params['scmsvn_commitTracker'] = 1;
73 foreach ($enabledHooks as $enableHook) {
74 $params[$enableHook] = 1;
76 $pluginScmHook->update($params);
77 $hooksArray = $pluginScmHook->getEnabledHooks($projectId);
78 unset($pluginScmHook);
79 $params['hooksString'] = implode('|',$hooksArray);
80 $params['scm_root'] = forge_get_config('repos_path', 'scmsvn') . '/' . $projectObject->getUnixName();
81 if ($scmsvncronjob->updateScmRepo($params)) {
82 db_query_params('UPDATE plugin_scmhook set need_update = $1 where id_group = $2', array(0, $projectId));
84 $projectObject->setPluginUse('svntracker', false);
86 // -> retrieve old data if any
87 $res = db_query_params('insert into plugin_scmhook_scmsvn_committracker_data_artifact (kind, group_artifact_id, project_task_id)
88 select kind, group_artifact_id, project_task_id FROM plugin_svntracker_data_artifact', array());
89 $res = db_query_params('insert into plugin_scmhook_scmsvn_committracker_data_master (holder_id, svn_date, log_text, file, prev_version, actual_version, author)
90 select holder_id, svn_date, log_text, file, prev_version, actual_version, author FROM plugin_svntracker_data_master', array());
93 $pm->deactivate('svntracker');
94 // Remove the symbolic link made if plugin has a www.
95 if (is_dir(forge_get_config('plugins_path') . '/svntracker/www')) { // if the plugin has a www dir delete the link to it
96 if (file_exists('../www/plugins/svntracker')) {
97 $result = unlink('../www/plugins/svntracker');
99 $feedback .= "\n"._('Soft link wasn\'t removed in www/plugins folder, please do so manually.');
104 // Remove the symbolic link made if plugin has a config.
105 if (file_exists(forge_get_config('config_path'). '/plugins/svntracker')) {
106 $result = unlink(forge_get_config('config_path'). '/plugins/svntracker'); // the apache group or user should have write perms in forge_get_config('config_path')/plugins folder...
108 $feedback .= _('Soft link wasn\'t removed in config folder, please do so manually.');