Merge pull request #567 from TonisOrmisson/fixed-console-pretty-urls-v1

v1: fixed pretty-urls not working from console apps
This commit is contained in:
Lorenzo Milesi
2024-10-10 11:25:33 +02:00
committed by GitHub
2 changed files with 11 additions and 4 deletions

View File

@ -8,6 +8,7 @@
- Fix #546: The profile/show page must not be visible by default, implement configurable policy (TonisOrmisson) - Fix #546: The profile/show page must not be visible by default, implement configurable policy (TonisOrmisson)
- Fix #397: No more fatal Exceptions when connecting to already taken Social Network (edegaudenzi) - Fix #397: No more fatal Exceptions when connecting to already taken Social Network (edegaudenzi)
- Ehh: Added option to pre-fill recovery email via url parameter (TonisOrmisson) - Ehh: Added option to pre-fill recovery email via url parameter (TonisOrmisson)
- Ehh: Fixed pretty-url rules not initialized for console apps (TonisOrmisson)
## 1.6.3 Mar 18th, 2024 ## 1.6.3 Mar 18th, 2024

View File

@ -30,6 +30,7 @@ use yii\console\Application as ConsoleApplication;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\i18n\PhpMessageSource; use yii\i18n\PhpMessageSource;
use yii\web\Application as WebApplication; use yii\web\Application as WebApplication;
use yii\web\UrlManager;
/** /**
* Bootstrap class of the yii2-usuario extension. Configures container services, initializes translations, * Bootstrap class of the yii2-usuario extension. Configures container services, initializes translations,
@ -49,10 +50,10 @@ class Bootstrap implements BootstrapInterface
$this->initTranslations($app); $this->initTranslations($app);
$this->initContainer($app, $map); $this->initContainer($app, $map);
$this->initMailServiceConfiguration($app, $app->getModule('user')); $this->initMailServiceConfiguration($app, $app->getModule('user'));
$this->initUrlRoutes($app);
if ($app instanceof WebApplication) { if ($app instanceof WebApplication) {
$this->initControllerNamespace($app); $this->initControllerNamespace($app);
$this->initUrlRoutes($app);
$this->initUrlRestRoutes($app); $this->initUrlRestRoutes($app);
$this->initAuthCollection($app); $this->initAuthCollection($app);
$this->initAuthManager($app); $this->initAuthManager($app);
@ -256,11 +257,11 @@ class Bootstrap implements BootstrapInterface
/** /**
* Initializes web url routes (rules in Yii2). * Initializes web url routes (rules in Yii2).
* *
* @param WebApplication $app * @param Application $app
* *
* @throws InvalidConfigException * @throws InvalidConfigException
*/ */
protected function initUrlRoutes(WebApplication $app) protected function initUrlRoutes(Application $app)
{ {
/** @var $module Module */ /** @var $module Module */
$module = $app->getModule('user'); $module = $app->getModule('user');
@ -274,8 +275,13 @@ class Bootstrap implements BootstrapInterface
$config['routePrefix'] = 'user'; $config['routePrefix'] = 'user';
} }
$urlManager = $app->getUrlManager();
if(!($urlManager instanceof UrlManager)) {
return;
}
$rule = Yii::createObject($config); $rule = Yii::createObject($config);
$app->getUrlManager()->addRules([$rule], false); $urlManager->addRules([$rule], false);
} }
/** /**