These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Activate a plugin or plugins. |
||
4 | * |
||
5 | * Plugins to be activated are passed via $_REQUEST['plugin_guids'] as GUIDs. |
||
6 | * After activating the plugin(s), the views cache and simplecache are invalidated. |
||
7 | * |
||
8 | * @uses mixed $_GET['plugin_guids'] The GUIDs of the plugin to activate. 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 | $activated_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:activate:no', [$guid])); |
||
23 | continue; |
||
24 | } |
||
25 | |||
26 | if (!$plugin->activate()) { |
||
27 | $msg = $plugin->getError(); |
||
28 | $string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no'; |
||
29 | register_error(elgg_echo($string, [$plugin->getDisplayName(), $plugin->getError()])); |
||
30 | continue; |
||
31 | } |
||
32 | |||
33 | $ids = [ |
||
34 | 'cannot_start' . $plugin->getID(), |
||
35 | 'invalid_and_deactivated_' . $plugin->getID() |
||
36 | ]; |
||
37 | |||
38 | foreach ($ids as $id) { |
||
39 | elgg_delete_admin_notice($id); |
||
40 | } |
||
41 | |||
42 | $activated_plugins[] = $plugin; |
||
43 | } |
||
44 | |||
45 | if (empty($activated_plugins)) { |
||
46 | return elgg_error_response(); |
||
47 | } |
||
48 | |||
49 | View Code Duplication | if (count($activated_plugins) === 1) { |
|
1 ignored issue
–
show
|
|||
50 | $plugin = $activated_plugins[0]; |
||
51 | |||
52 | $url = elgg_http_build_url([ |
||
53 | 'path' => 'admin/plugins', |
||
54 | 'query' => parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), |
||
55 | 'fragment' => preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID()), |
||
56 | ]); |
||
57 | |||
58 | return elgg_ok_response('', '', $url); |
||
59 | } |
||
60 | |||
61 | return elgg_ok_response(); |
||
62 |
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.