Changed console URL handling (#6673)

* Changed console URL handling

* Update Application.php

* Use console url manager for SafeBaseUrl

* Use console url manager in tests

* Fix tests for console url script file name

* Update CHANGELOG.md

---------

Co-authored-by: Yuriy Bakhtin <yurybakh@gmail.com>
This commit is contained in:
Lucas Bartholemy 2023-11-23 21:32:49 +01:00 committed by GitHub
parent 5a026939a5
commit ebe45bacfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 34 deletions

View File

@ -10,6 +10,7 @@ HumHub Changelog
- Fix #6656: Fix people and space filters
- Fix #6652: Fix profile update on welcome page
- Fix #6660: Fix memory usage on integrity check
- Fix #6653: URL in email notification removes the sub-folder of the Base URL
- Fix #6674: Fix visibility of draft and scheduled content on dashboard

View File

@ -53,17 +53,6 @@ class Application extends \yii\console\Application implements ApplicationInterfa
if (Yii::getAlias('@webroot-static', false) === false) {
Yii::setAlias('@webroot-static', '@webroot/static');
}
$this->urlManager->scriptUrl = '';
$this->urlManager->baseUrl = '';
// Set hostInfo based on given baseUrl
$urlParts = parse_url($baseUrl);
$hostInfo = $urlParts['scheme'] . '://' . $urlParts['host'];
if (isset($urlParts['port'])) {
$hostInfo .= ':' . $urlParts['port'];
}
$this->urlManager->hostInfo = $hostInfo;
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\components\console;
use humhub\libs\BaseSettingsManager;
use Yii;
/**
* @inheritdoc
*/
class UrlManager extends \humhub\components\UrlManager
{
/**
* @inheritdoc
*/
public function init()
{
$urlParts = parse_url($this->getConfiguredBaseUrl());
$this->setBaseUrl($urlParts['path'] ?? '');
$hostInfo = $urlParts['scheme'] . '://' . $urlParts['host'];
if (isset($urlParts['port'])) {
$hostInfo .= ':' . $urlParts['port'];
}
$this->setHostInfo($hostInfo);
$this->setScriptUrl($this->getBaseUrl() . ($this->getScriptUrl() ?: '/index.php'));
parent::init();
}
private function getConfiguredBaseUrl()
{
if (BaseSettingsManager::isDatabaseInstalled()) {
$baseUrl = Yii::$app->settings->get('baseUrl');
if (!empty($baseUrl)) {
return $baseUrl;
}
}
return 'http://localhost';
}
}

View File

@ -19,6 +19,10 @@ return [
'enableSession' => false,
'loginUrl' => ['/user/auth/login']
],
'urlManager' => [
'class' => \humhub\components\console\UrlManager::class,
'scriptUrl' => '/index.php',
],
'runtimeCache' => [
'class' => \yii\caching\DummyCache::class
],

View File

@ -7,7 +7,7 @@
namespace humhub\libs;
use Yii;
use humhub\components\console\UrlManager;
use yii\helpers\BaseUrl;
/**
@ -23,26 +23,6 @@ class SafeBaseUrl extends BaseUrl
*/
protected static function getUrlManager()
{
$urlManager = clone parent::getUrlManager();
$urlManager->setHostInfo(static::getHostInfoFromSetting());
return $urlManager;
return static::$urlManager ?: new UrlManager();
}
/**
* Get host info from general setting "Base URL"
*
* @return string|null
*/
public static function getHostInfoFromSetting(): ?string
{
$baseUrl = Yii::$app->settings->get('baseUrl');
if (empty($baseUrl)) {
return null;
}
$data = parse_url($baseUrl);
return $data['scheme'] . '://' . $data['host'] . (isset($data['port']) ? ':' . $data['port'] : '');
}
}
}

View File

@ -21,6 +21,9 @@ return [
'queue' => [
'class' => 'humhub\modules\queue\driver\Instant',
],
'urlManager' => [
'class' => \humhub\components\console\UrlManager::class,
],
],
'params' => [
'installed' => true,