Console

Add controller to the console application

To add a custom controller to the console application, you need to catch the humhub\components\console\Application::EVENT_ON_INIT.

Example event:

<?php
use humhub\components\console\Application;
return [
'id' => 'translation',
'class' => 'humhub\modules\translation\Module',
'namespace' => 'humhub\modules\translation',
'events' => [
//...
[
'class' => Application::class, 'event' => Application::EVENT_ON_INIT,
'callback' => ['humhub\modules\translation\Module', 'onConsoleApplicationInit']
],
//...
],
];
?>

Example callback:

public static function onConsoleApplicationInit($event) {
$application = $event->sender;
$application->controllerMap['translation'] = commands\TranslationController::className();
}

Integrity Checker

The integrity checker is a command which validates and if necessary repairs the application database.

If you want to add own checking methods for your module to it, you can intercept the humhub\commands\IntegrityController::EVENT_ON_RUN event.

Example callback implementation:

public static function onIntegrityCheck($event)
{
$integrityController = $event->sender;
$integrityController->showTestHeadline("Polls Module - Answers (" . PollAnswer::find()->count() . " entries)");
foreach (PollAnswer::find()->joinWith('poll')->all() as $answer) {
if ($answer->poll === null) {
if ($integrityController->showFix("Deleting poll answer id " . $answer->id . " without existing poll!")) {
$answer->delete();
}
}
}
}