Skip to content

Commit

Permalink
Dev: Fix plugin deactivate
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 29, 2018
1 parent 78ef361 commit 9e07dbd
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 47 deletions.
46 changes: 23 additions & 23 deletions application/controllers/admin/PluginManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,40 +177,40 @@ private function activate($id)
}

/**
* Deactivate plugin with $id
*
* @param int $id
* Deactivate plugin.
* @return void
*/
private function deactivate($id)
public function deactivate()
{
if (!Permission::model()->hasGlobalPermission('settings', 'update')) {
Yii::app()->setFlashMessage(gT("No permission"), 'error');
$this->getController()->redirect(array('/admin/pluginmanager/sa/index'));
}
$oPlugin = Plugin::model()->findByPk($id);
if (!is_null($oPlugin)) {
$iStatus = $oPlugin->active;
if ($iStatus == 1) {
$result = App()->getPluginManager()->dispatchEvent(new PluginEvent('beforeDeactivate', $this), $oPlugin->name);
if ($result->get('success', true)) {
$iStatus = 0;
$pluginId = Yii::app()->request->getPost('pluginId');
$plugin = Plugin::model()->findByPk($pluginId);
if ($plugin && $plugin->active) {
$result = App()->getPluginManager()->dispatchEvent(
new PluginEvent('beforeDeactivate', $this),
$plugin->name
);
if ($result->get('success', true)) {
$plugin->active = 0;
$plugin->save();
Yii::app()->user->setFlash('success', gT('Plugin was deactivated.'));
} else {
$customMessage = $result->get('message');
if ($customMessage) {
Yii::app()->user->setFlash('error', $customMessage);
} else {
$customMessage = $result->get('message');
if ($customMessage) {
Yii::app()->user->setFlash('error', $customMessage);
} else {
Yii::app()->user->setFlash('error', gT('Failed to activate the plugin.'));
}

$this->getController()->redirect(array('admin/pluginmanager/sa/index/'));
Yii::app()->user->setFlash('error', gT('Failed to deactivate the plugin.'));
}
$this->getController()->redirect($this->getPluginManagerUrl());
}
$oPlugin->active = $iStatus;
$oPlugin->save();
Yii::app()->user->setFlash('success', gT('Plugin was deactivated.'));
} else {
Yii::app()->user->setFlash('error', gT('Found no plugin, or plugin not active.'));
}
$this->getController()->redirect(array('admin/pluginmanager/sa/index/'));

$this->getController()->redirect($this->getPluginManagerUrl());
}

/**
Expand Down
83 changes: 59 additions & 24 deletions application/models/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,39 +151,74 @@ public function getActionButtons()
. "<span class='fa fa-power-off'></span>"
."</a>";
} else {
$output = "<a data-toggle='tooltip' title='" . gT('Deactivate') . "' href='#deactivate' data-action='deactivate' data-id='".$this->id."' class='ls_action_changestate btn btn-warning btn-xs btntooltip'>"
. "<span class='fa fa-power-off'></span>"
."</a>";
$output = $this->getDeactivateButton();
}

// TODO: Don't use JS native confirm.
if ($this->active == 0) {
$uninstallUrl = App()->getController()->createUrl(
'/admin/pluginmanager',
[
'sa' => 'uninstallPlugin'
]
);
$output .= '&nbsp;' . CHtml::beginForm(
$uninstallUrl,
'post',
[
'style' => 'display: inline-block'
]
);
$output .= "
<input type='hidden' name='pluginId' value='" . $this->id . "' />
<button data-toggle='tooltip' onclick='return confirm(\"" . gT('Are you sure you want to uninstall this plugin?') . "\");' title='" . gT('Uninstall plugin') . "' class='btntooltip btn btn-danger btn-xs'>
<i class='fa fa-times-circle'></i>
</button>
</form>
";
$output .= $this->getUninstallButton();
}
}

return $output;
}

/**
* @return string HTML
*/
protected function getDeactivateButton()
{
$deactivateUrl = App()->getController()->createUrl(
'/admin/pluginmanager',
[
'sa' => 'deactivate'
]
);
$output = '&nbsp;' . CHtml::beginForm(
$deactivateUrl,
'post',
[
'style' => 'display: inline-block'
]
);
$output .= "
<input type='hidden' name='pluginId' value='" . $this->id . "' />
<button data-toggle='tooltip' onclick='return confirm(\"" . gT('Are you sure you want to deactivate this plugin?') . "\");' title='" . gT('Deactivate plugin') . "' class='btntooltip btn btn-warning btn-xs'>
<i class='fa fa-power-off'></i>
</button>
</form>
";
return $output;
}

/**
* @todo: Don't use JS native confirm.
* @return string HTML
*/
protected function getUninstallButton()
{
$uninstallUrl = App()->getController()->createUrl(
'/admin/pluginmanager',
[
'sa' => 'uninstallPlugin'
]
);
$output = '&nbsp;' . CHtml::beginForm(
$uninstallUrl,
'post',
[
'style' => 'display: inline-block'
]
);
$output .= "
<input type='hidden' name='pluginId' value='" . $this->id . "' />
<button data-toggle='tooltip' onclick='return confirm(\"" . gT('Are you sure you want to uninstall this plugin?') . "\");' title='" . gT('Uninstall plugin') . "' class='btntooltip btn btn-danger btn-xs'>
<i class='fa fa-times-circle'></i>
</button>
</form>
";
return $output;
}

/**
* @param Plugin|null $plugin
* @param string $pluginName
Expand Down

0 comments on commit 9e07dbd

Please sign in to comment.