Simplified plugin management logic, switched default manage plugins switch state to positive; finalized for merging into develop

This commit is contained in:
Luke Towers 2018-02-01 20:40:04 -06:00
parent 61914666f8
commit e64a280cee
8 changed files with 73 additions and 136 deletions

View File

@ -735,28 +735,6 @@ class Updates extends Controller
}
}
/**
* Rollback and remove plugins from the system.
* @return void
*/
public function onRemovePlugins()
{
if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
foreach ($checkedIds as $objectId) {
if (!$object = PluginVersion::find($objectId)) {
continue;
}
PluginManager::instance()->deletePlugin($object->code);
}
Flash::success(Lang::get('system::lang.plugins.remove_success'));
}
return $this->listRefresh('manage');
}
/**
* Rollback and remove a single plugin from the system.
* @return void
@ -764,9 +742,7 @@ class Updates extends Controller
public function onRemovePlugin()
{
if ($pluginCode = post('code')) {
PluginManager::instance()->deletePlugin($pluginCode);
Flash::success(Lang::get('system::lang.plugins.remove_success'));
}
@ -774,114 +750,67 @@ class Updates extends Controller
}
/**
* Rebuilds plugin database migrations.
* Perform a bulk action on the provided plugins
* @return void
*/
public function onRefreshPlugins()
{
if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
foreach ($checkedIds as $objectId) {
if (!$object = PluginVersion::find($objectId)) {
continue;
}
PluginManager::instance()->refreshPlugin($object->code);
}
Flash::success(Lang::get('system::lang.plugins.refresh_success'));
}
return $this->listRefresh('manage');
}
public function onBulkAction()
{
if (($bulkAction = post('action')) && ($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
if (($bulkAction = post('action')) &&
($checkedIds = post('checked')) &&
is_array($checkedIds) &&
count($checkedIds)
) {
$manager = PluginManager::instance();
foreach ($checkedIds as $pluginId) {
if (!$plugin = PluginVersion::find($pluginId)) {
continue;
}
$savePlugin = true;
switch ($bulkAction) {
// Enables plugin's updates.
case 'freeze':
$plugin->is_frozen = 1;
Flash::success(Lang::get('system::lang.plugins.freeze_success'));
break;
// Disables plugin's updates.
case 'unfreeze':
$plugin->is_frozen = 0;
Flash::success(Lang::get('system::lang.plugins.unfreeze_success'));
break;
// Disables plugin on the system.
case 'disable':
$plugin->is_disabled = 1;
$manager->disablePlugin($plugin->code, true);
Flash::success(Lang::get('system::lang.plugins.disable_success'));
break;
// Enables plugin on the system.
case 'enable':
$plugin->is_disabled = 0;
$manager->enablePlugin($plugin->code, true);
Flash::success(Lang::get('system::lang.plugins.enable_success'));
break;
// Rebuilds plugin database migrations.
case 'refresh':
$savePlugin = false;
$manager->refreshPlugin($plugin->code);
break;
// Rollback and remove plugins from the system.
case 'remove':
$savePlugin = false;
$manager->deletePlugin($plugin->code);
break;
}
if ($savePlugin) {
$plugin->save();
}
}
return $this->listRefresh('manage');
}
public function onToggleFreeze()
{
$plugin = PluginVersion::find(post('plugin_id'));
$freeze = post('freeze_' . $plugin->id);
$plugin->is_frozen = $freeze;
$plugin->save();
if($freeze) {
Flash::success(Lang::get('system::lang.plugins.freeze_success'));
} else {
Flash::success(Lang::get('system::lang.plugins.unfreeze_success'));
}
return $this->listRefresh('manage');
}
public function onToggleDisable()
{
$manager = PluginManager::instance();
$plugin = PluginVersion::find(post('plugin_id'));
$disable = post('disable_' . $plugin->id);
if ($disable) {
$manager->disablePlugin($plugin->code, true);
}
else {
$manager->enablePlugin($plugin->code, true);
}
$plugin->is_disabled = $disable;
$plugin->save();
if ($disable) {
Flash::success(Lang::get('system::lang.plugins.disable_success'));
}
else{
Flash::success(Lang::get('system::lang.plugins.enable_success'));
}
}
}
Flash::success(Lang::get("system::lang.plugins.{$bulkAction}_success"));
return $this->listRefresh('manage');
}

View File

@ -1,15 +0,0 @@
<label class="custom-switch" data-check="oc-disable-<?= $record->id ?>" style="margin-bottom:0">
<input data-request="onToggleDisable"
data-request-data="plugin_id: <?= $record->id ?>"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
type="checkbox"
name="disable_<?= $record->id ?>"
value="<?= $record->is_disabled ?>"
<?php if($record->is_disabled): ?>checked=checked<?php endif ?>>
<span>
<span><?= e(trans('system::lang.plugins.check_yes')) ?></span>
<span><?= e(trans('system::lang.plugins.check_no')) ?></span>
</span>
<a class="slide-button"></a>
</label>

View File

@ -0,0 +1,18 @@
<?php $action = $record->is_disabled ? 'enable' : 'disable'; ?>
<label class="custom-switch" data-check="oc-disable-<?= $record->id ?>" style="margin-bottom:0">
<input data-request="onBulkAction"
data-request-data="action: '<?= $action ?>', checked: [<?= $record->id ?>]"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
type="checkbox"
name="disable_<?= $record->id ?>"
value="<?= !$record->is_disabled ?>"
<?php if (!$record->is_disabled) : ?>checked=checked<?php endif; ?>
data-stripe-load-indicator
>
<span>
<span><?= e(trans('system::lang.plugins.check_yes')) ?></span>
<span><?= e(trans('system::lang.plugins.check_no')) ?></span>
</span>
<a class="slide-button"></a>
</label>

View File

@ -1,15 +0,0 @@
<label class="custom-switch" data-check="oc-freeze-<?= $record->id ?>" style="margin-bottom:0">
<input data-request="onToggleFreeze"
data-request-data="plugin_id: <?= $record->id ?>"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
type="checkbox"
name="freeze_<?= $record->id ?>"
value="<?= $record->is_frozen ?>"
<?php if($record->is_frozen): ?>checked=checked<?php endif ?>>
<span>
<span><?= e(trans('system::lang.plugins.check_yes')) ?></span>
<span><?= e(trans('system::lang.plugins.check_no')) ?></span>
</span>
<a class="slide-button"></a>
</label>

View File

@ -0,0 +1,18 @@
<?php $action = $record->is_frozen ? 'unfreeze' : 'freeze'; ?>
<label class="custom-switch" data-check="oc-freeze-<?= $record->id ?>" style="margin-bottom:0">
<input data-request="onBulkAction"
data-request-data="action: '<?= $action ?>', checked: [<?= $record->id ?>]"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
type="checkbox"
name="freeze_<?= $record->id ?>"
value="<?= !$record->is_frozen ?>"
<?php if (!$record->is_frozen) : ?>checked=checked<?php endif; ?>
data-stripe-load-indicator
>
<span>
<span><?= e(trans('system::lang.plugins.check_yes')) ?></span>
<span><?= e(trans('system::lang.plugins.check_no')) ?></span>
</span>
<a class="slide-button"></a>
</label>

View File

@ -76,8 +76,8 @@
<button
class="btn btn-danger oc-icon-trash-o"
disabled="disabled"
data-request="onRemovePlugins"
data-request-data="checked: $('.control-list').listWidget('getChecked')"
data-request="onBulkAction"
data-request-data="action: 'remove', checked: $('.control-list').listWidget('getChecked')"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
data-request-confirm="<?= e(trans('system::lang.plugins.remove_confirm')) ?>"
data-trigger-action="enable"

View File

@ -110,6 +110,8 @@ return [
'select_label' => 'Select Action...',
'check_yes' => 'Yes',
'check_no' => 'No',
'unfrozen' => 'Updates Enabled',
'enabled' => 'Plugin Enabled',
'freeze' => 'disable updates for',
'unfreeze' => 'enable updates for',
'enable' => 'enable',

View File

@ -14,14 +14,14 @@ columns:
label: system::lang.updates.plugin_version
sortable: false
is_frozen:
label: system::lang.plugins.freeze_label
is_unfrozen:
label: system::lang.plugins.unfrozen
type: partial
path: is_frozen
path: is_unfrozen
sortable: false
is_disabled:
label: system::lang.plugins.disable_label
is_enabled:
label: system::lang.plugins.enabled
type: partial
path: is_disabled
path: is_enabled
sortable: false