mirror of
https://github.com/humhub/humhub.git
synced 2025-01-29 12:28:06 +01:00
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:
parent
5a026939a5
commit
ebe45bacfc
@ -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
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
48
protected/humhub/components/console/UrlManager.php
Normal file
48
protected/humhub/components/console/UrlManager.php
Normal 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';
|
||||
}
|
||||
}
|
@ -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
|
||||
],
|
||||
|
@ -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'] : '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,9 @@ return [
|
||||
'queue' => [
|
||||
'class' => 'humhub\modules\queue\driver\Instant',
|
||||
],
|
||||
'urlManager' => [
|
||||
'class' => \humhub\components\console\UrlManager::class,
|
||||
],
|
||||
],
|
||||
'params' => [
|
||||
'installed' => true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user