These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Deactivate a plugin or plugins. |
||
4 | * |
||
5 | * Plugins to be deactivated are passed via $_REQUEST['plugin_guids'] as GUIDs. |
||
6 | * After deactivating the plugin(s), the views cache and simplecache are invalidated. |
||
7 | * |
||
8 | * @uses mixed $_GET['plugin_guids'] The GUIDs of the plugin to deactivate. Can be an array. |
||
9 | */ |
||
10 | |||
11 | $plugin_guids = get_input('plugin_guids'); |
||
12 | |||
13 | if (!is_array($plugin_guids)) { |
||
14 | $plugin_guids = [$plugin_guids]; |
||
15 | } |
||
16 | |||
17 | $deactivated_plugins = []; |
||
18 | foreach ($plugin_guids as $guid) { |
||
19 | $plugin = get_entity($guid); |
||
20 | |||
21 | if (!($plugin instanceof ElggPlugin)) { |
||
22 | register_error(elgg_echo('admin:plugins:deactivate:no', [$guid])); |
||
23 | continue; |
||
24 | } |
||
25 | |||
26 | View Code Duplication | if (!$plugin->deactivate()) { |
|
1 ignored issue
–
show
|
|||
27 | $msg = $plugin->getError(); |
||
28 | $string = ($msg) ? 'admin:plugins:deactivate:no_with_msg' : 'admin:plugins:deactivate:no'; |
||
29 | register_error(elgg_echo($string, [$plugin->getDisplayName(), $msg])); |
||
30 | continue; |
||
31 | } |
||
32 | |||
33 | $deactivated_plugins[] = $plugin; |
||
34 | } |
||
35 | |||
36 | if (empty($deactivated_plugins)) { |
||
37 | return elgg_error_response(); |
||
38 | } |
||
39 | |||
40 | View Code Duplication | if (count($deactivated_plugins) == 1) { |
|
1 ignored issue
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
41 | $plugin = $deactivated_plugins[0]; |
||
42 | |||
43 | $url = elgg_http_build_url([ |
||
44 | 'path' => 'admin/plugins', |
||
45 | 'query' => parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), |
||
46 | 'fragment' => preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID()), |
||
47 | ]); |
||
48 | |||
49 | return elgg_ok_response('', '', $url); |
||
50 | } |
||
51 | |||
52 | return elgg_ok_response(); |
||
53 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.