From 1c98a849d80d748dc435f5a23264a79f1bb4488c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Farr=C3=A9?= Date: Tue, 21 May 2024 18:14:30 +0200 Subject: [PATCH 1/2] Fix: Old URLs don't work since version 2.3.0 --- components/WikiPageUrlRule.php | 15 +++++++++++---- controllers/PageController.php | 3 +-- docs/CHANGELOG.md | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/components/WikiPageUrlRule.php b/components/WikiPageUrlRule.php index c3c0025..eaefcf4 100644 --- a/components/WikiPageUrlRule.php +++ b/components/WikiPageUrlRule.php @@ -11,6 +11,7 @@ use humhub\components\ContentContainerUrlRuleInterface; use humhub\modules\content\components\ContentContainerActiveRecord; use humhub\modules\wiki\models\WikiPage; +use Yii; use yii\base\Component; use yii\base\Exception; use yii\web\UrlManager; @@ -42,10 +43,16 @@ public function parseContentContainerRequest(ContentContainerActiveRecord $conta if ((string)$id === $parts[1]) { // the value after wiki/ doesn't contain other char than numbers $wikiPage = $query->andWhere(['wiki_page.id' => $id])->one(); - } elseif (count($parts) === 2) { // Fallback for old URLs (without ID) - $title = $parts[1]; - /* @var $wikiPage WikiPage */ - $wikiPage = $query->andWhere(['wiki_page.title' => $title])->one(); + } else { + if (count($parts) === 2) { // Fallback for old URLs without ID + $title = $parts[1]; + } else { // Fallback for old URLs with `/page/view?title=` + $title = Yii::$app->request->get('title'); + } + if ($title) { + /* @var $wikiPage WikiPage */ + $wikiPage = $query->andWhere(['wiki_page.title' => $title])->one(); + } } if ($wikiPage !== null) { diff --git a/controllers/PageController.php b/controllers/PageController.php index 142ed82..aec0379 100644 --- a/controllers/PageController.php +++ b/controllers/PageController.php @@ -18,7 +18,6 @@ use Throwable; use Yii; use yii\base\Exception; -use yii\base\InvalidArgumentException; use yii\base\InvalidConfigException; use yii\db\StaleObjectException; use yii\web\HttpException; @@ -96,7 +95,7 @@ public function actionView(int $id = null, $revisionId = null) private function getWikiPage($id): ?WikiPage { if (!is_int($id)) { - throw new InvalidArgumentException('Invalid $id parameter given!'); + return null; } /** @var WikiPage $wikiPage */ diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b23a921..63e9b96 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog Unreleased --------------------- - Fix #328: Type error when viewing a pending delete page +- Fix: Old URLs don't work since version 2.3.0 2.3.0 (April 22, 2024) --------------------- From 7343cf861f74488025d682fc73f5d05a4fa697d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Farr=C3=A9?= Date: Tue, 21 May 2024 18:16:07 +0200 Subject: [PATCH 2/2] Add PR ID in changelog --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 63e9b96..c56201b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,7 +4,7 @@ Changelog Unreleased --------------------- - Fix #328: Type error when viewing a pending delete page -- Fix: Old URLs don't work since version 2.3.0 +- Fix #329: Old URLs don't work since version 2.3.0 2.3.0 (April 22, 2024) ---------------------