Permalink
Browse files

feature(plugins): (de)activate_all action defaults to (in)active plugins

When omitting guids to these actions, the actions will retrieve all the
plugins that need to be (de)activated.

Supplied guids to these actions are now also validated as ElggPlugins.
  • Loading branch information...
jdalsem committed Jun 30, 2015
1 parent ce2a0e3 commit 0ea152f0ec1ba45702cf0fd3450a683cca0589e1
Showing with 59 additions and 31 deletions.
  1. +35 −20 actions/admin/plugins/activate_all.php
  2. +24 −11 actions/admin/plugins/deactivate_all.php
@@ -10,45 +10,60 @@
*/
$guids = get_input('guids');
$guids = explode(',', $guids);
$plugins = array();
foreach ($guids as $guid) {
$plugin = get_entity($guid);
if (!$plugin->isActive()) {
$plugins[$plugin->getId()] = $plugin;
}
if (empty($guids)) {
$plugins = elgg_get_plugins('inactive');
} else {
$plugins = elgg_get_entities([
'type' => 'object',
'subtype' => 'plugin',
'guids' => explode(',', $guids),
'limit' => false
]);
}
if (empty($plugins)) {
forward(REFERER);
}
do {
$additional_plugins_activated = false;
foreach ($plugins as $key => $plugin) {
if ($plugin->activate()) {
$ids = array(
'cannot_start' . $plugin->getID(),
'invalid_and_deactivated_' . $plugin->getID()
);
if ($plugin->isActive()) {
unset($plugins[$key]);
continue;
}
if (!$plugin->activate()) {
// plugin could not be activated in this loop, maybe in the next loop
continue;
}
foreach ($ids as $id) {
elgg_delete_admin_notice($id);
}
$ids = array(
'cannot_start' . $plugin->getID(),
'invalid_and_deactivated_' . $plugin->getID()
);
$additional_plugins_activated = true;
unset($plugins[$key]);
foreach ($ids as $id) {
elgg_delete_admin_notice($id);
}
// mark that something has changed in this loop
$additional_plugins_activated = true;
unset($plugins[$key]);
}
if (!$additional_plugins_activated) {
// no updates in this pass, break the loop
break;
}
} while (count($plugins) > 0);
if (count($plugins) > 0) {
foreach ($plugins as $key => $plugin) {
foreach ($plugins as $plugin) {
$msg = $plugin->getError();
$string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no';
register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError())));
register_error(elgg_echo($string, array($plugin->getFriendlyName(), $msg)));
}
}
@@ -10,18 +10,31 @@
*/
$guids = get_input('guids');
$guids = explode(',', $guids);
foreach ($guids as $guid) {
$plugin = get_entity($guid);
if ($plugin->isActive()) {
if ($plugin->deactivate()) {
//system_message(elgg_echo('admin:plugins:activate:yes', array($plugin->getManifest()->getName())));
} else {
$msg = $plugin->getError();
$string = ($msg) ? 'admin:plugins:deactivate:no_with_msg' : 'admin:plugins:deactivate:no';
register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError())));
}
if (empty($guids)) {
$plugins = elgg_get_plugins('active');
} else {
$plugins = elgg_get_entities([
'type' => 'object',
'subtype' => 'plugin',
'guids' => explode(',', $guids),
'limit' => false
]);
}
if (empty($plugins)) {
forward(REFERER);
}
foreach ($plugins as $plugin) {
if (!$plugin->isActive()) {
continue;
}
if (!$plugin->deactivate()) {
$msg = $plugin->getError();
$string = ($msg) ? 'admin:plugins:deactivate:no_with_msg' : 'admin:plugins:deactivate:no';
register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError())));
}
}

0 comments on commit 0ea152f

Please sign in to comment.