Test Failed
Push — master ( 8c47c2...3acf9f )
by Steve
12:37
created

actions/admin/plugins/activate.php (1 issue)

Upgrade to new PHP Analysis Engine

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
 * @package Elgg.Core
11
 * @subpackage Administration.Plugins
12
 */
13
14
$plugin_guids = get_input('plugin_guids');
15
16
if (!is_array($plugin_guids)) {
17
	$plugin_guids = [$plugin_guids];
18
}
19
20
$activated_guids = [];
21
foreach ($plugin_guids as $guid) {
22
	$plugin = get_entity($guid);
23
24
	if (!($plugin instanceof ElggPlugin)) {
25
		register_error(elgg_echo('admin:plugins:activate:no', [$guid]));
26
		continue;
27
	}
28
29
	if ($plugin->activate()) {
30
		$activated_guids[] = $guid;
31
		$ids = [
32
			'cannot_start' . $plugin->getID(),
33
			'invalid_and_deactivated_' . $plugin->getID()
34
		];
35
36
		foreach ($ids as $id) {
37
			elgg_delete_admin_notice($id);
38
		}
39 View Code Duplication
	} else {
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...
40
		$msg = $plugin->getError();
41
		$string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no';
42
		register_error(elgg_echo($string, [$plugin->getDisplayName(), $plugin->getError()]));
43
	}
44
}
45
46
// don't regenerate the simplecache because the plugin won't be
47
// loaded until next run.  Just invalidate and let it regenerate as needed
48
elgg_flush_caches();
49
50
if (count($activated_guids) === 1) {
51
	$url = 'admin/plugins';
52
	$query = (string) parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY);
53
	if ($query) {
54
		$url .= "?$query";
55
	}
56
	$plugin = get_entity($plugin_guids[0]);
57
	$id = $css_id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID());
58
	$url = "$url#id";
59
	return elgg_ok_response('', '', $url);
60
} else {
61
	// forward to top of page with a failure so remove any #foo
62
	$url = $_SERVER['HTTP_REFERER'];
63
	if (strpos($url, '#')) {
64
		$url = substr(0, strpos($url, '#'));
65
	}
66
	forward($url);
67
}
68