1 | <?php |
||
2 | /** |
||
3 | * Activates all specified installed and inactive plugins. |
||
4 | * |
||
5 | * All specified plugins in the mod/ directory that aren't active are activated and the views |
||
6 | * cache and simplecache are invalidated. |
||
7 | */ |
||
8 | |||
9 | $guids = get_input('guids'); |
||
10 | |||
11 | if (empty($guids)) { |
||
12 | $plugins = elgg_get_plugins('inactive'); |
||
13 | } else { |
||
14 | $plugins = elgg_get_entities([ |
||
15 | 'type' => 'object', |
||
16 | 'subtype' => 'plugin', |
||
17 | 'guids' => explode(',', $guids), |
||
18 | 'limit' => false, |
||
19 | ]); |
||
20 | } |
||
21 | |||
22 | if (empty($plugins)) { |
||
23 | return elgg_ok_response(); |
||
24 | } |
||
25 | |||
26 | do { |
||
27 | $additional_plugins_activated = false; |
||
28 | foreach ($plugins as $key => $plugin) { |
||
29 | if ($plugin->isActive()) { |
||
30 | unset($plugins[$key]); |
||
31 | continue; |
||
32 | } |
||
33 | |||
34 | if (!$plugin->activate()) { |
||
35 | // plugin could not be activated in this loop, maybe in the next loop |
||
36 | continue; |
||
37 | } |
||
38 | |||
39 | $ids = [ |
||
40 | 'cannot_start' . $plugin->getID(), |
||
41 | 'invalid_and_deactivated_' . $plugin->getID() |
||
42 | ]; |
||
43 | |||
44 | foreach ($ids as $id) { |
||
45 | elgg_delete_admin_notice($id); |
||
46 | } |
||
47 | |||
48 | // mark that something has changed in this loop |
||
49 | $additional_plugins_activated = true; |
||
50 | unset($plugins[$key]); |
||
51 | } |
||
52 | |||
53 | if (!$additional_plugins_activated) { |
||
54 | // no updates in this pass, break the loop |
||
55 | break; |
||
56 | } |
||
57 | } while (count($plugins) > 0); |
||
58 | |||
59 | if (count($plugins) > 0) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
60 | foreach ($plugins as $plugin) { |
||
61 | $msg = $plugin->getError(); |
||
62 | $string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no'; |
||
63 | |||
64 | return elgg_error_response(elgg_echo($string, [$plugin->getDisplayName(), $msg])); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | return elgg_ok_response(); |
||
69 |