diff --git a/protected/humhub/components/ModuleManager.php b/protected/humhub/components/ModuleManager.php index 39d0707ff2..ddcf71ccc1 100644 --- a/protected/humhub/components/ModuleManager.php +++ b/protected/humhub/components/ModuleManager.php @@ -9,6 +9,7 @@ namespace humhub\components; use humhub\components\bootstrap\ModuleAutoLoader; +use humhub\components\console\Application as ConsoleApplication; use humhub\libs\BaseSettingsManager; use humhub\models\ModuleEnabled; use Yii; @@ -99,10 +100,10 @@ class ModuleManager extends Component /** * Registers a module to the manager * This is usually done by config.php in modules root folder. - * @see \humhub\components\bootstrap\ModuleAutoLoader::bootstrap - * * @param array $configs * @throws InvalidConfigException + * @see \humhub\components\bootstrap\ModuleAutoLoader::bootstrap + * */ public function registerBulk(array $configs) { @@ -127,7 +128,7 @@ class ModuleManager extends Component // Check mandatory config options if (!isset($config['class']) || !isset($config['id'])) { - throw new InvalidConfigException('Module configuration requires an id and class attribute: '.$basePath); + throw new InvalidConfigException('Module configuration requires an id and class attribute: ' . $basePath); } $isCoreModule = (isset($config['isCoreModule']) && $config['isCoreModule']); @@ -196,6 +197,11 @@ class ModuleManager extends Component } } } + + // Register Console ControllerMap + if (Yii::$app instanceof ConsoleApplication && !(empty($config['consoleControllerMap']))) { + Yii::$app->controllerMap = ArrayHelper::merge(Yii::$app->controllerMap, $config['consoleControllerMap']); + } } /** @@ -228,7 +234,7 @@ class ModuleManager extends Component if (isset($options['enabled']) && $options['enabled'] === true) { - if(!in_array($class, $this->coreModules) && !in_array($id, $this->enabledModules)) { + if (!in_array($class, $this->coreModules) && !in_array($id, $this->enabledModules)) { continue; } } @@ -275,12 +281,12 @@ class ModuleManager extends Component * Returns weather or not the given module id belongs to an core module. * * @return bool - * @since 1.3.8 * @throws Exception + * @since 1.3.8 */ public function isCoreModule($id) { - if(!$this->hasModule($id)) { + if (!$this->hasModule($id)) { return false; } diff --git a/protected/humhub/modules/ldap/Events.php b/protected/humhub/modules/ldap/Events.php index 7361637527..c48a1dfb43 100644 --- a/protected/humhub/modules/ldap/Events.php +++ b/protected/humhub/modules/ldap/Events.php @@ -51,13 +51,4 @@ class Events extends BaseObject } } - /** - * @param $event \yii\base\Event - */ - public static function onConsoleApplicationInit($event) - { - $application = $event->sender; - $application->controllerMap['ldap'] = commands\LdapController::class; - } - } diff --git a/protected/humhub/modules/ldap/config.php b/protected/humhub/modules/ldap/config.php index 2abfa81969..e33dd95c06 100644 --- a/protected/humhub/modules/ldap/config.php +++ b/protected/humhub/modules/ldap/config.php @@ -15,10 +15,12 @@ return [ 'id' => 'ldap', 'class' => \humhub\modules\ldap\Module::class, 'isCoreModule' => true, + 'consoleControllerMap' => [ + 'ldap' => 'humhub\modules\ldap\commands\LdapController' + ], 'events' => [ [AuthenticationMenu::class, AuthenticationMenu::EVENT_INIT, [Events::class, 'onAuthenticationMenu']], [Collection::class, Collection::EVENT_BEFORE_CLIENTS_SET, [Events::class, 'onAuthClientCollectionSet']], - [Application::class, Application::EVENT_ON_INIT, [Events::class, 'onConsoleApplicationInit']], ] ]; ?> diff --git a/protected/humhub/modules/marketplace/commands/MarketplaceController.php b/protected/humhub/modules/marketplace/commands/MarketplaceController.php index bf7553ef1f..b7fd58fc86 100644 --- a/protected/humhub/modules/marketplace/commands/MarketplaceController.php +++ b/protected/humhub/modules/marketplace/commands/MarketplaceController.php @@ -19,12 +19,28 @@ use yii\helpers\Console; * HumHub Module Managament * * @property \humhub\modules\marketplace\Module $module - * @package humhub.modules_core.admin.console * @since 0.5 */ class MarketplaceController extends Controller { + /** + * @inerhitdoc + */ + public function beforeAction($action) + { + /** @var \humhub\modules\marketplace\Module $module */ + $module = Yii::$app->getModule('marketplace'); + + if ($module === null || !$module->enabled) { + print "Fatal: The module marketplace is disabled by configuration!\n\n"; + return false; + } + + return parent::beforeAction($action); + } + + /** * Lists all installed and enabled modules. * diff --git a/protected/humhub/modules/marketplace/config.php b/protected/humhub/modules/marketplace/config.php index 70792196b0..ec5631b63a 100644 --- a/protected/humhub/modules/marketplace/config.php +++ b/protected/humhub/modules/marketplace/config.php @@ -16,8 +16,10 @@ return [ 'id' => 'marketplace', 'class' => Module::class, 'isCoreModule' => true, + 'consoleControllerMap' => [ + 'module' => 'humhub\modules\marketplace\commands\MarketplaceController' + ], 'events' => [ - ['humhub\components\console\Application', 'onInit', [Events::class, 'onConsoleApplicationInit']], [ModuleMenu::class, ModuleMenu::EVENT_INIT, [Events::class, 'onAdminModuleMenuInit']], [CronController::class, CronController::EVENT_ON_HOURLY_RUN, [Events::class, 'onHourlyCron']], ] diff --git a/protected/humhub/modules/search/Events.php b/protected/humhub/modules/search/Events.php index 5e682a2d83..03fa414cf8 100644 --- a/protected/humhub/modules/search/Events.php +++ b/protected/humhub/modules/search/Events.php @@ -20,7 +20,6 @@ use yii\helpers\Console; */ class Events extends BaseObject { - public static function onTopMenuRightInit($event) { $event->sender->addWidget(widgets\SearchMenu::class); @@ -35,11 +34,4 @@ class Events extends BaseObject Yii::$app->search->optimize(); $controller->stdout('done.' . PHP_EOL, Console::FG_GREEN); } - - public static function onConsoleApplicationInit($event) - { - $application = $event->sender; - $application->controllerMap['search'] = commands\SearchController::class; - } - } diff --git a/protected/humhub/modules/search/config.php b/protected/humhub/modules/search/config.php index 1616ab7b2d..24f63785ad 100644 --- a/protected/humhub/modules/search/config.php +++ b/protected/humhub/modules/search/config.php @@ -11,10 +11,12 @@ return [ 'class' => \humhub\modules\search\Module::class, 'events' => [ ['class' => TopMenuRightStack::class, 'event' => TopMenuRightStack::EVENT_INIT, 'callback' => [Events::class, 'onTopMenuRightInit']], - ['class' => Application::class, 'event' => Application::EVENT_ON_INIT, 'callback' => [Events::class, 'onConsoleApplicationInit']], ['class' => CronController::class, 'event' => CronController::EVENT_ON_HOURLY_RUN, 'callback' => [Events::class, 'onHourlyCron']], ], + 'consoleControllerMap' => [ + 'search' => '\humhub\modules\search\commands\SearchController' + ], 'urlManagerRules' => [ 'search' => 'search/search/index', - ] + ] ]; diff --git a/protected/humhub/modules/space/Events.php b/protected/humhub/modules/space/Events.php index b623aea761..591705d742 100644 --- a/protected/humhub/modules/space/Events.php +++ b/protected/humhub/modules/space/Events.php @@ -14,7 +14,7 @@ use humhub\modules\space\models\Membership; use humhub\modules\space\helpers\MembershipHelper; use Yii; use yii\base\BaseObject; -use yii\web\HttpException; +use humhub\components\Event; /** * Events provides callbacks for all defined module events. @@ -27,7 +27,7 @@ class Events extends BaseObject /** * On rebuild of the search index, rebuild all space records * - * @param type $event + * @param Event $event */ public static function onSearchRebuild($event) { @@ -63,12 +63,6 @@ class Events extends BaseObject } } - public static function onConsoleApplicationInit($event) - { - $application = $event->sender; - $application->controllerMap['space'] = commands\SpaceController::class; - } - /** * Callback to validate module database records. * diff --git a/protected/humhub/modules/space/config.php b/protected/humhub/modules/space/config.php index eed21c556b..a89cb3f41c 100644 --- a/protected/humhub/modules/space/config.php +++ b/protected/humhub/modules/space/config.php @@ -19,10 +19,12 @@ return [ 'class' => 'humhub\modules\space\modules\manage\Module' ], ], + 'consoleControllerMap' => [ + 'space' => 'humhub\modules\space\commands\SpaceController' + ], 'events' => [ [User::class, User::EVENT_BEFORE_SOFT_DELETE, [Events::class, 'onUserSoftDelete']], [Search::class, Search::EVENT_ON_REBUILD, [Events::class, 'onSearchRebuild']], - [Application::class, Application::EVENT_ON_INIT, [Events::class, 'onConsoleApplicationInit']], [IntegrityController::class, IntegrityController::EVENT_ON_RUN, [Events::class, 'onIntegrityCheck']], ], ]; diff --git a/protected/humhub/modules/ui/Events.php b/protected/humhub/modules/ui/Events.php index 119c79bab3..3b4e0cc4aa 100644 --- a/protected/humhub/modules/ui/Events.php +++ b/protected/humhub/modules/ui/Events.php @@ -15,10 +15,5 @@ namespace humhub\modules\ui; */ class Events { - public static function onConsoleApplicationInit($event) - { - $application = $event->sender; - $application->controllerMap['theme'] = commands\ThemeController::class; - } } diff --git a/protected/humhub/modules/ui/config.php b/protected/humhub/modules/ui/config.php index 332f979cca..cff9047355 100644 --- a/protected/humhub/modules/ui/config.php +++ b/protected/humhub/modules/ui/config.php @@ -6,8 +6,8 @@ use humhub\components\console\Application; return [ 'id' => 'ui', 'class' => \humhub\modules\ui\Module::class, - 'isCoreModule' => true, - 'events' => [ - [Application::class, Application::EVENT_ON_INIT, ['humhub\modules\ui\Events', 'onConsoleApplicationInit']], - ] + 'consoleControllerMap' => [ + 'theme' => '\humhub\modules\ui\commands\ThemeController' + ], + 'isCoreModule' => true ];