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 * Copyright (C) 2011, 2012 Alain Peyrat - Alcatel-Lucent
10 * Copyright 2013, Franck Villaume - TrivialDev
11 * http://fusionforge.org/
13 * This file is part of FusionForge. FusionForge is free software;
14 * you can redistribute it and/or modify it under the terms of the
15 * GNU General Public License as published by the Free Software
16 * Foundation; either version 2 of the Licence, or (at your option)
19 * FusionForge is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 require_once '../env.inc.php';
30 require_once $gfcommon.'include/pre.php';
31 require_once $gfwww.'admin/admin_utils.php';
33 session_require_global_perm('forge_admin');
35 // Skip non compatible plugins.
36 $plugins_disabled = array('scmccase');
38 // Skip non actionable plugins due to general configuration
39 if (!forge_get_config('use_scm')) {
40 array_push($plugins_disabled, 'scmarch', 'scmbzr', 'scmcpold', 'scmcvs', 'scmdarcs', 'scmgit', 'scmhg', 'scmsvn');
43 $pm = plugin_manager_get_object();
45 if (getStringFromRequest('update')) {
46 $pluginname = getStringFromRequest('update');
48 if ((getStringFromRequest('action') == 'deactivate')) {
50 $res = db_query_params('DELETE FROM user_plugin WHERE plugin_id = (SELECT plugin_id FROM plugins WHERE plugin_name = $1)',
53 exit_error(db_error(), 'admin');
55 $feedback .= sprintf(ngettext('%d user detached from plugin.', '%d users detached from plugin.', db_affected_rows($res)), db_affected_rows($res));
58 $res = db_query_params('DELETE FROM group_plugin WHERE plugin_id = (SELECT plugin_id FROM plugins WHERE plugin_name = $1)',
61 exit_error(db_error(),'admin');
63 $feedback .= sprintf(ngettext('%d project detached from plugin.', '%d projects detached from plugin.', db_affected_rows($res)), db_affected_rows($res));
66 $res = $pm->deactivate($pluginname);
68 exit_error(db_error(), 'admin');
70 $feedback = sprintf(_('Plugin %s updated Successfully'), $pluginname);
72 // Load the plugin and now get information from it.
73 $plugin = $pm->GetPluginObject($pluginname);
74 if (!$plugin || $plugin->isError()) {
75 exit_error(_("Could not get plugin object"), 'admin');
77 $installdir = $plugin->getInstallDir();
79 // Remove the symbolic link made if plugin has a www.
80 if (is_dir(forge_get_config('plugins_path') . '/' . $pluginname . '/www')) { // if the plugin has a www dir delete the link to it
81 if (file_exists('../'.$installdir)) {
82 $result = unlink('../'.$installdir);
84 $feedback .= '<br />'._("Soft link wasn't removed in www/plugins folder, please do so manually.");
91 // Remove the symbolic link made if plugin has a config.
92 if (file_exists(forge_get_config('config_path'). '/plugins/'.$pluginname)) {
93 $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...
95 $feedback .= _('Success, config not deleted');
101 $res = $pm->activate($pluginname);
103 exit_error(db_error(), 'admin');
105 // Load the plugin and now get information from it.
106 $pm = plugin_manager_get_object();
107 $pm->LoadPlugin($pluginname);
109 $plugin = $pm->GetPluginObject($pluginname);
110 if (!$plugin || $plugin->isError()) {
111 exit_error(_("Could not get plugin object"), 'admin');
113 if (method_exists($plugin, 'install')) {
117 if ($plugin->isError()) {
118 $error_msg = $plugin->getErrorMessage();
120 $feedback = sprintf(_('Plugin %1$s updated Successfully'), $pluginname);
126 site_admin_header(array('title'=>_('Plugin Manager')));
129 <form name="theform" action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="get">
132 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.');
134 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>';
136 $title_arr = array( _('Plugin Name'),
140 _('Projects Using it'),
141 _('Global Administration View'));
142 echo $HTML->listTableTop($title_arr);
144 // Get the activated plugins.
145 $pm = plugin_manager_get_object();
147 // Simple hack to disable dependent plugins.
148 if (!$pm->PluginIsInstalled('scmcvs')) {
149 $plugins_disabled[] = 'cvssyncmail';
150 $plugins_disabled[] = 'cvstracker';
153 // [#411] Prevent admin from desactivating the last auth plugin.
154 $plugins = $pm->GetPlugins();
155 $auth_plugins = array();
156 foreach($plugins as $p) {
157 if (preg_match('/^auth/', $p)) {
158 $auth_plugins[] = $p;
161 if (count($auth_plugins) == 1) {
162 $plugin = $auth_plugins[0];
163 $action[$plugin]['deactivate'] = false;
166 //get the directories from the plugins dir
169 if($handle = opendir(forge_get_config('plugins_path'))) {
170 while (($filename = readdir($handle)) !== false) {
171 if ($filename != '..' && $filename != '.' && $filename != ".svn" && $filename != "CVS" &&
172 is_dir(forge_get_config('plugins_path').'/'.$filename) &&
173 !in_array($filename, $plugins_disabled)) {
175 if (forge_get_config('plugin_status', $filename) !== 'valid') {
179 $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',
182 if (db_numrows($res)>0) {
186 $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',
189 if (db_numrows($res1) > 0) {
193 if (forge_get_config('installation_environment') === 'development' || $used) {
197 $filelist[] = $filename;
207 foreach ($filelist as $filename) {
208 $pluginObject = $pm->GetPluginObject($filename);
209 if ($pm->PluginIsInstalled($filename)) {
212 $next = 'deactivate';
213 $link = util_make_link("/admin/pluginman.php?update=$filename&action=deactivate", _('Deactivate'));
215 $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',
218 if (db_numrows($res)>0) {
220 $nb_users = db_numrows($res);
221 for($i=0;$i<$nb_users;$i++) {
222 $users .= db_result($res,$i,0) . " | ";
224 $users = substr($users,0,strlen($users) - 3); //remove the last |
225 // If there are too many users, replace the list with number of users
226 if ($nb_users > 100) {
227 $users = util_make_link("/admin/userlist.php?usingplugin=$filename", '<b>'.sprintf(_("%d users"), $nb_users).'</b>');
234 $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',
237 if (db_numrows($res)>0) {
239 $nb_groups = db_numrows($res);
240 for($i=0;$i<$nb_groups;$i++) {
241 $groups .= db_result($res,$i,0) . " | ";
243 $groups = substr($groups,0,strlen($groups) - 3); //remove the last |
244 // If there are too many projects, replace the list with number of projects
245 if ($nb_groups > 100) {
246 $groups = util_make_link("/admin/grouplist.php?usingplugin=$filename", '<b>'.sprintf(_("%d projects"), $nb_groups).'</b>');
253 if (method_exists($pluginObject, 'getAdminOptionLink')) {
254 $adminlink = $pluginObject->getAdminOptionLink();
257 $msg = _('Inactive');
258 $status = "inactive";
260 $link = util_make_link("/admin/pluginman.php?update=$filename&action=activate", _('Activate'));
266 if (method_exists($pluginObject, 'getPluginDescription')) {
267 $description = $pluginObject->getPluginDescription();
269 // Disable link to action if action is not possible.
270 if (isset($action[$filename][$next]) && $action[$filename][$next] === false) {
274 // Disable link to action if action is not possible.
275 if (isset($action[$filename][$next]) && $action[$filename][$next] === false) {
279 $title = _('Current plugin status is'). ' ' .forge_get_config('plugin_status', $filename);
280 echo '<tr '. $HTML->boxGetAltRowStyle($j+1) .'>'.
281 '<td title="'. $description.' '.$title .'">'. $filename.'</td>'.
282 '<td class="'.$status.'" class="align-center">'. $msg .'</td>'.
283 '<td class="align-center">'. $link .'</td>'.
284 '<td class="align-left">'. $users .'</td>'.
285 '<td class="align-left">'. $groups .'</td>'.
286 '<td class="align-left">'. $adminlink .'</td></tr>'."\n";
290 echo $HTML->listTableBottom();
298 site_admin_footer(array());
302 // c-file-style: "bsd"