From b0c17c8a601ef99faea8690851b6b928fd892729 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 14 Aug 2015 12:48:29 +0930 Subject: [PATCH] Add ability to uninstall an extension --- .../js/admin/src/components/ExtensionsPage.js | 20 +++++++--- .../Api/Actions/Extensions/DeleteAction.php | 37 +++++++++++++++++++ framework/core/src/Api/ApiServiceProvider.php | 7 ++++ .../Settings/DatabaseSettingsRepository.php | 5 +++ .../MemoryCacheSettingsRepository.php | 7 ++++ .../src/Core/Settings/SettingsRepository.php | 2 + 6 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 framework/core/src/Api/Actions/Extensions/DeleteAction.php diff --git a/framework/core/js/admin/src/components/ExtensionsPage.js b/framework/core/js/admin/src/components/ExtensionsPage.js index e23e1e95b..21f32bc6a 100644 --- a/framework/core/js/admin/src/components/ExtensionsPage.js +++ b/framework/core/js/admin/src/components/ExtensionsPage.js @@ -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()); diff --git a/framework/core/src/Api/Actions/Extensions/DeleteAction.php b/framework/core/src/Api/Actions/Extensions/DeleteAction.php new file mode 100644 index 000000000..72c06e33a --- /dev/null +++ b/framework/core/src/Api/Actions/Extensions/DeleteAction.php @@ -0,0 +1,37 @@ +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(); + } +} diff --git a/framework/core/src/Api/ApiServiceProvider.php b/framework/core/src/Api/ApiServiceProvider.php index 911f32948..c4b0b4f61 100644 --- a/framework/core/src/Api/ApiServiceProvider.php +++ b/framework/core/src/Api/ApiServiceProvider.php @@ -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', diff --git a/framework/core/src/Core/Settings/DatabaseSettingsRepository.php b/framework/core/src/Core/Settings/DatabaseSettingsRepository.php index dd45a008c..f3dac86b4 100644 --- a/framework/core/src/Core/Settings/DatabaseSettingsRepository.php +++ b/framework/core/src/Core/Settings/DatabaseSettingsRepository.php @@ -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(); + } } diff --git a/framework/core/src/Core/Settings/MemoryCacheSettingsRepository.php b/framework/core/src/Core/Settings/MemoryCacheSettingsRepository.php index 777a7f5c7..52a403582 100644 --- a/framework/core/src/Core/Settings/MemoryCacheSettingsRepository.php +++ b/framework/core/src/Core/Settings/MemoryCacheSettingsRepository.php @@ -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); + } } diff --git a/framework/core/src/Core/Settings/SettingsRepository.php b/framework/core/src/Core/Settings/SettingsRepository.php index 1b226236e..3c5045cf1 100644 --- a/framework/core/src/Core/Settings/SettingsRepository.php +++ b/framework/core/src/Core/Settings/SettingsRepository.php @@ -9,4 +9,6 @@ interface SettingsRepository public function get($key, $default = null); public function set($key, $value); + + public function delete($key); }