3 * FusionForge Plugin Activate / Deactivate Page
5 * Copyright 2005 GForge, LLC
6 * Copyright 2010 FusionForge Team
7 * Copyright 2011, Franck Villaume - Capgemini
8 * Copyright 2011, Alain Peyrat - Alcatel-Lucent
9 * http://fusionforge.org/
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once('../env.inc.php');
28 require_once $gfcommon.'include/pre.php';
29 require_once $gfwww.'admin/admin_utils.php';
31 // Skip non compatible plugins.
32 $plugins_disabled = array('webcalendar', 'scmccase');
34 // Skip non activable plugins due to general configuration
35 if (!forge_get_config('use_scm')) {
36 array_push($plugins_disabled, 'scmarch', 'scmbzr', 'scmcpold', 'scmcvs', 'scmdarcs', 'scmgit', 'scmhg', 'scmsvn');
39 $pm = plugin_manager_get_object();
41 if (getStringFromRequest('update')) {
42 $pluginname = getStringFromRequest('update');
44 if ((getStringFromRequest('action') == 'deactivate')) {
46 $res = db_query_params('DELETE FROM user_plugin WHERE plugin_id = (SELECT plugin_id FROM plugins WHERE plugin_name = $1)',
49 exit_error(db_error(), 'admin');
51 $feedback .= sprintf(ngettext('%d user detached from plugin.', '%d users detached from plugin.', db_affected_rows($res)), db_affected_rows($res));
54 $res = db_query_params('DELETE FROM group_plugin WHERE plugin_id = (SELECT plugin_id FROM plugins WHERE plugin_name = $1)',
57 exit_error(db_error(),'admin');
59 $feedback .= sprintf(ngettext('%d project detached from plugin.', '%d projects detached from plugin.', db_affected_rows($res)), db_affected_rows($res));
62 $res = $pm->deactivate($pluginname);
64 exit_error(db_error(), 'admin');
66 $feedback = sprintf(_('Plugin %1$s updated Successfully'), $pluginname);
68 // Load the plugin and now get information from it.
69 $plugin = $pm->GetPluginObject($pluginname);
70 if (!$plugin || $plugin->isError()) {
71 exit_error(_("Couldn't get plugin object"), 'admin');
73 $installdir = $plugin->getInstallDir();
75 // Remove the symbolic link made if plugin has a www.
76 if (is_dir(forge_get_config('plugins_path') . '/' . $pluginname . '/www')) { // if the plugin has a www dir delete the link to it
77 if (file_exists('../'.$installdir)) {
78 $result = unlink('../'.$installdir);
80 $feedback .= _('<br />Soft link wasn\'t removed in www/plugins folder, please do so manually.');
87 // Remove the symbolic link made if plugin has a config.
88 if (file_exists(forge_get_config('config_path'). '/plugins/'.$pluginname)) {
89 $result = unlink(forge_get_config('config_path'). '/plugins/'.$pluginname); // the apache group or user should have write perms in forge_get_config('config_path')/plugins folder...
91 $feedback .= _('Success, config not deleted');
97 $res = $pm->activate($pluginname);
99 exit_error(db_error(), 'admin');
101 $feedback = sprintf(_('Plugin %1$s updated Successfully'), $pluginname);
103 // Load the plugin and now get information from it.
104 $pm = plugin_manager_get_object();
105 $pm->LoadPlugin($pluginname);
107 $plugin = $pm->GetPluginObject($pluginname);
108 if (!$plugin || $plugin->isError()) {
109 exit_error(_("Couldn't get plugin object"), 'admin');
111 if (method_exists($plugin, 'install')) {
119 site_admin_header(array('title'=>_('Plugin Manager')));
122 <form name="theform" action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="get">
125 echo _('Here you can activate / deactivate site-wide plugins which are in the plugins/ folder. Then, you should activate them also per project, per user or whatever the plugin specifically applies to.');
127 echo '<p class="important">' . _('Be careful because some projects/users can be using the plugin. Deactivating it will remove the plugin from all users/projects.') . '</p>';
129 $title_arr = array( _('Plugin Name'),
133 _('Projects Using it'),
134 _('Global Administration View'));
135 echo $HTML->listTableTop($title_arr);
137 // Get the activated plugins.
138 $pm = plugin_manager_get_object();
140 // Simple hack to disable dependent plugins.
141 if (!$pm->PluginIsInstalled('scmsvn')) {
142 $plugins_disabled[] = 'svncommitemail';
143 $plugins_disabled[] = 'svntracker';
145 if (!$pm->PluginIsInstalled('scmcvs')) {
146 $plugins_disabled[] = 'cvssyncmail';
147 $plugins_disabled[] = 'cvstracker';
150 // [#411] Prevent admin from desactivating the last auth plugin.
151 $plugins = $pm->GetPlugins();
152 $auth_plugins = array();
153 foreach($plugins as $p) {
154 if (preg_match('/^auth/', $p)) {
155 $auth_plugins[] = $p;
158 if (count($auth_plugins) == 1) {
159 $plugin = $auth_plugins[0];
160 $action[$plugin]['deactivate'] = false;
163 //get the directories from the plugins dir
166 if($handle = opendir(forge_get_config('plugins_path'))) {
167 while (($filename = readdir($handle)) !== false) {
168 if ($filename != '..' && $filename != '.' && $filename != ".svn" && $filename != "CVS" &&
169 is_dir(forge_get_config('plugins_path').'/'.$filename) &&
170 !in_array($filename, $plugins_disabled)) {
172 if (forge_get_config('plugin_status', $filename) !== 'valid') {
176 $res = db_query_params('SELECT u.user_name FROM plugins p, user_plugin up, users u WHERE p.plugin_name = $1 and up.user_id = u.user_id and p.plugin_id = up.plugin_id',
179 if (db_numrows($res)>0) {
183 $res1 = 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',
186 if (db_numrows($res1) > 0) {
190 if (forge_get_config('installation_environment') === 'development' || $used) {
194 $filelist[] = $filename;
204 foreach ($filelist as $filename) {
205 if ($pm->PluginIsInstalled($filename)) {
208 $next = 'deactivate';
209 $link = util_make_link("/admin/pluginman.php?update=$filename&action=deactivate", _('Deactivate'));
211 $res = db_query_params ('SELECT u.user_name FROM plugins p, user_plugin up, users u WHERE p.plugin_name = $1 and up.user_id = u.user_id and p.plugin_id = up.plugin_id',
214 if (db_numrows($res)>0) {
216 $nb_users = db_numrows($res);
217 for($i=0;$i<$nb_users;$i++) {
218 $users .= db_result($res,$i,0) . " | ";
220 $users = substr($users,0,strlen($users) - 3); //remove the last |
221 // If there are too many users, replace the list with number of users
222 if ($nb_users > 100) {
223 $users = util_make_link("/admin/userlist.php?usingplugin=$filename", '<b>'.sprintf(_("%d users"), $nb_users).'</b>');
230 $res = 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',
233 if (db_numrows($res)>0) {
235 $nb_groups = db_numrows($res);
236 for($i=0;$i<$nb_groups;$i++) {
237 $groups .= db_result($res,$i,0) . " | ";
239 $groups = substr($groups,0,strlen($groups) - 3); //remove the last |
240 // If there are too many projects, replace the list with number of projects
241 if ($nb_groups > 100) {
242 $groups = util_make_link("/admin/grouplist.php?usingplugin=$filename", '<b>'.sprintf(_("%d projects"), $nb_groups).'</b>');
249 $pluginObject = plugin_get_object($filename);
250 if (method_exists($pluginObject, 'getAdminOptionLink')) {
251 $adminlink = $pluginObject->getAdminOptionLink();
254 $msg = _('Inactive');
255 $status = "inactive";
257 $link = util_make_link("/admin/pluginman.php?update=$filename&action=activate", _('Activate'));
263 // Disable link to action if action is not possible.
264 if (isset($action[$filename][$next]) && $action[$filename][$next] === false) {
268 $title = _('Current plugin status:'). ' ' .forge_get_config('plugin_status', $filename);
269 echo '<tr '. $HTML->boxGetAltRowStyle($j+1) .'>'.
270 '<td title="'. $title .'" >'. $filename.'</td>'.
271 '<td class="'.$status.'" class="align-center">'. $msg .'</td>'.
272 '<td class="align-center">'. $link .'</td>'.
273 '<td class="align-left">'. $users .'</td>'.
274 '<td class="align-left">'. $groups .'</td>'.
275 '<td class="align-left">'. $adminlink .'</td></tr>'."\n";
279 echo $HTML->listTableBottom();
287 site_admin_footer(array());
291 // c-file-style: "bsd"