mirror of
https://github.com/flarum/framework.git
synced 2024-12-11 21:43:38 +08:00
Add ability to uninstall an extension
This commit is contained in:
parent
7bd1cb8513
commit
b0c17c8a60
|
@ -82,12 +82,20 @@ export default class ExtensionsPage extends Component {
|
|||
}
|
||||
}));
|
||||
|
||||
// if (!enabled) {
|
||||
// items.add('uninstall', Button.component({
|
||||
// icon: 'trash-o',
|
||||
// children: 'Uninstall'
|
||||
// }));
|
||||
// }
|
||||
if (!enabled) {
|
||||
items.add('uninstall', Button.component({
|
||||
icon: 'trash-o',
|
||||
children: 'Uninstall',
|
||||
onclick: () => {
|
||||
app.request({
|
||||
url: app.forum.attribute('apiUrl') + '/extensions/' + extension.name,
|
||||
method: 'DELETE',
|
||||
}).then(() => window.location.reload());
|
||||
|
||||
app.modal.show(new LoadingModal());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// items.add('separator2', Separator.component());
|
||||
|
||||
|
|
37
framework/core/src/Api/Actions/Extensions/DeleteAction.php
Normal file
37
framework/core/src/Api/Actions/Extensions/DeleteAction.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php namespace Flarum\Api\Actions\Extensions;
|
||||
|
||||
use Flarum\Api\Actions\DeleteAction as BaseDeleteAction;
|
||||
use Flarum\Api\Request;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Flarum\Core\Exceptions\PermissionDeniedException;
|
||||
use Flarum\Support\ExtensionManager;
|
||||
|
||||
class DeleteAction extends BaseDeleteAction
|
||||
{
|
||||
protected $extensions;
|
||||
|
||||
public function __construct(ExtensionManager $extensions)
|
||||
{
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
protected function delete(Request $request)
|
||||
{
|
||||
if (! $request->actor->isAdmin()) {
|
||||
throw new PermissionDeniedException;
|
||||
}
|
||||
|
||||
$name = $request->get('name');
|
||||
|
||||
$this->extensions->disable($name);
|
||||
$this->extensions->uninstall($name);
|
||||
|
||||
app('flarum.formatter')->flush();
|
||||
|
||||
$forum = app('Flarum\Forum\Actions\ClientAction');
|
||||
$forum->flushAssets();
|
||||
|
||||
$admin = app('Flarum\Admin\Actions\ClientAction');
|
||||
$admin->flushAssets();
|
||||
}
|
||||
}
|
|
@ -306,6 +306,13 @@ class ApiServiceProvider extends ServiceProvider
|
|||
$this->action('Flarum\Api\Actions\Extensions\UpdateAction')
|
||||
);
|
||||
|
||||
// Uninstall an extension
|
||||
$routes->delete(
|
||||
'/extensions/{name}',
|
||||
'flarum.api.extensions.delete',
|
||||
$this->action('Flarum\Api\Actions\Extensions\DeleteAction')
|
||||
);
|
||||
|
||||
// Update config settings
|
||||
$routes->post(
|
||||
'/config',
|
||||
|
|
|
@ -35,4 +35,9 @@ class DatabaseSettingsRepository implements SettingsRepository
|
|||
|
||||
$query->$method(compact('key', 'value'));
|
||||
}
|
||||
|
||||
public function delete($key)
|
||||
{
|
||||
$this->database->table('config')->where('key', $key)->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,4 +42,11 @@ class MemoryCacheSettingsRepository implements SettingsRepository
|
|||
|
||||
$this->inner->set($key, $value);
|
||||
}
|
||||
|
||||
public function delete($key)
|
||||
{
|
||||
unset($this->cache[$key]);
|
||||
|
||||
$this->inner->delete($key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,4 +9,6 @@ interface SettingsRepository
|
|||
public function get($key, $default = null);
|
||||
|
||||
public function set($key, $value);
|
||||
|
||||
public function delete($key);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user