Add ability to uninstall an extension

This commit is contained in:
Toby Zerner 2015-08-14 12:48:29 +09:30
parent 7bd1cb8513
commit b0c17c8a60
6 changed files with 72 additions and 6 deletions

View File

@ -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());

View 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();
}
}

View File

@ -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',

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -9,4 +9,6 @@ interface SettingsRepository
public function get($key, $default = null);
public function set($key, $value);
public function delete($key);
}