mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 16:23:16 +08:00
Extension state exceptions
This commit is contained in:
parent
e19c9ea67c
commit
77f0dca47e
|
@ -13,6 +13,8 @@ use SychO\PackageManager\Exception\ComposerCommandFailedException;
|
|||
use SychO\PackageManager\Exception\ComposerCommandFailedExceptionHandler;
|
||||
use SychO\PackageManager\Exception\ComposerRequireFailedException;
|
||||
use SychO\PackageManager\Exception\ComposerUpdateFailedException;
|
||||
use SychO\PackageManager\Exception\ExtensionAlreadyInstalledException;
|
||||
use SychO\PackageManager\Exception\ExtensionNotInstalledException;
|
||||
|
||||
return [
|
||||
(new Extend\Routes('api'))
|
||||
|
@ -44,5 +46,9 @@ return [
|
|||
(new Extend\ErrorHandling)
|
||||
->handler(ComposerCommandFailedException::class, ComposerCommandFailedExceptionHandler::class)
|
||||
->handler(ComposerRequireFailedException::class, ComposerCommandFailedExceptionHandler::class)
|
||||
->handler(ComposerUpdateFailedException::class, ComposerCommandFailedExceptionHandler::class),
|
||||
->handler(ComposerUpdateFailedException::class, ComposerCommandFailedExceptionHandler::class)
|
||||
->type(ExtensionAlreadyInstalledException::class, 'extension_already_installed')
|
||||
->status('extension_already_installed', 409)
|
||||
->type(ExtensionNotInstalledException::class, 'extension_not_installed')
|
||||
->status('extension_not_installed', 409),
|
||||
];
|
||||
|
|
25
extensions/package-manager/js/dist/admin.js
vendored
25
extensions/package-manager/js/dist/admin.js
vendored
|
@ -646,13 +646,30 @@ __webpack_require__.r(__webpack_exports__);
|
|||
/* harmony default export */ __webpack_exports__["default"] = (function (e) {
|
||||
var error = e.response.errors[0];
|
||||
|
||||
if (error.code !== 'composer_command_failure') {
|
||||
if (!['composer_command_failure', 'extension_already_installed', 'extension_not_installed'].includes(error.code)) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
flarum_admin_app__WEBPACK_IMPORTED_MODULE_0___default.a.modal.show(_components_ComposerFailureModal__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
||||
error: error
|
||||
});
|
||||
switch (error.code) {
|
||||
case 'composer_command_failure':
|
||||
flarum_admin_app__WEBPACK_IMPORTED_MODULE_0___default.a.modal.show(_components_ComposerFailureModal__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
||||
error: error
|
||||
});
|
||||
break;
|
||||
|
||||
case 'extension_already_installed':
|
||||
flarum_admin_app__WEBPACK_IMPORTED_MODULE_0___default.a.alerts.show({
|
||||
type: 'error'
|
||||
}, flarum_admin_app__WEBPACK_IMPORTED_MODULE_0___default.a.translator.trans('sycho-package-manager.admin.exceptions.extension_already_installed'));
|
||||
flarum_admin_app__WEBPACK_IMPORTED_MODULE_0___default.a.modal.close();
|
||||
break;
|
||||
|
||||
case 'extension_not_installed':
|
||||
flarum_admin_app__WEBPACK_IMPORTED_MODULE_0___default.a.alerts.show({
|
||||
type: 'error'
|
||||
}, flarum_admin_app__WEBPACK_IMPORTED_MODULE_0___default.a.translator.trans('sycho-package-manager.admin.exceptions.extension_not_installed'));
|
||||
flarum_admin_app__WEBPACK_IMPORTED_MODULE_0___default.a.modal.close();
|
||||
}
|
||||
});
|
||||
|
||||
/***/ }),
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,9 +4,22 @@ import ComposerFailureModal from "../components/ComposerFailureModal";
|
|||
export default function (e: any) {
|
||||
const error = e.response.errors[0];
|
||||
|
||||
if (error.code !== 'composer_command_failure') {
|
||||
if (!['composer_command_failure', 'extension_already_installed', 'extension_not_installed'].includes(error.code)) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.modal.show(ComposerFailureModal, { error });
|
||||
switch (error.code) {
|
||||
case 'composer_command_failure':
|
||||
app.modal.show(ComposerFailureModal, { error });
|
||||
break;
|
||||
|
||||
case 'extension_already_installed':
|
||||
app.alerts.show({ type: 'error' }, app.translator.trans('sycho-package-manager.admin.exceptions.extension_already_installed'));
|
||||
app.modal.close();
|
||||
break;
|
||||
|
||||
case 'extension_not_installed':
|
||||
app.alerts.show({ type: 'error' }, app.translator.trans('sycho-package-manager.admin.exceptions.extension_not_installed'));
|
||||
app.modal.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
sycho-package-manager:
|
||||
admin:
|
||||
exceptions:
|
||||
extension_already_installed: Extension is already installed.
|
||||
extension_not_installed: Extension not found.
|
||||
|
||||
extensions:
|
||||
install: Install a new extension
|
||||
install_help: Fill in the extension package name to proceed. Visit {extiverse} to browse extensions.
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace SychO\PackageManager\Command;
|
|||
use Composer\Console\Application;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use SychO\PackageManager\Exception\ExtensionNotInstalledException;
|
||||
use SychO\PackageManager\Extension\Event\Removed;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
|
@ -48,7 +49,7 @@ class RemoveExtensionHandler
|
|||
$extension = $this->extensions->getExtension($command->extensionId);
|
||||
|
||||
if (empty($extension)) {
|
||||
// ... exception
|
||||
throw new ExtensionNotInstalledException($command->extensionId);
|
||||
}
|
||||
|
||||
$output = new BufferedOutput();
|
||||
|
|
|
@ -10,6 +10,7 @@ use Composer\Console\Application;
|
|||
use Flarum\Extension\ExtensionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use SychO\PackageManager\Exception\ComposerRequireFailedException;
|
||||
use SychO\PackageManager\Exception\ExtensionAlreadyInstalledException;
|
||||
use SychO\PackageManager\Extension\Event\Installed;
|
||||
use SychO\PackageManager\Extension\ExtensionUtils;
|
||||
use SychO\PackageManager\RequirePackageValidator;
|
||||
|
@ -60,7 +61,7 @@ class RequireExtensionHandler
|
|||
$extension = $this->extensions->getExtension($extensionId);
|
||||
|
||||
if (! empty($extension)) {
|
||||
// ... exception
|
||||
throw new ExtensionAlreadyInstalledException($extension);
|
||||
}
|
||||
|
||||
$output = new BufferedOutput();
|
||||
|
|
|
@ -11,6 +11,7 @@ use Flarum\Extension\ExtensionManager;
|
|||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use SychO\PackageManager\Exception\ComposerUpdateFailedException;
|
||||
use SychO\PackageManager\Exception\ExtensionNotInstalledException;
|
||||
use SychO\PackageManager\Extension\Event\Updated;
|
||||
use SychO\PackageManager\UpdateExtensionValidator;
|
||||
use SychO\PackageManager\LastUpdateCheck;
|
||||
|
@ -66,7 +67,7 @@ class UpdateExtensionHandler
|
|||
$extension = $this->extensions->getExtension($command->extensionId);
|
||||
|
||||
if (empty($extension)) {
|
||||
// ... exception
|
||||
throw new ExtensionNotInstalledException($command->extensionId);
|
||||
}
|
||||
|
||||
$output = new BufferedOutput();
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace SychO\PackageManager\Exception;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Foundation\KnownError;
|
||||
|
||||
class ExtensionAlreadyInstalledException extends Exception implements KnownError
|
||||
{
|
||||
public function __construct(Extension $extension)
|
||||
{
|
||||
parent::__construct("Extension {$extension->getTitle()} is already installed.");
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return 'extension_already_installed';
|
||||
}
|
||||
}
|
23
extensions/package-manager/src/Exception/ExtensionNotInstalledException.php
Executable file
23
extensions/package-manager/src/Exception/ExtensionNotInstalledException.php
Executable file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace SychO\PackageManager\Exception;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Foundation\KnownError;
|
||||
|
||||
class ExtensionNotInstalledException extends Exception implements KnownError
|
||||
{
|
||||
public function __construct(string $extensionId)
|
||||
{
|
||||
parent::__construct("Extension {$extensionId} is not installed.");
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return 'extension_not_installed';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user