Skip to content

Commit

Permalink
Merge pull request #329 from humhub/fix/261-old-urls
Browse files Browse the repository at this point in the history
Fix: Old URLs don't work since version 2.3.0
  • Loading branch information
luke- committed May 21, 2024
2 parents 6245f96 + 7343cf8 commit 5ea68d1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions components/WikiPageUrlRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
Unreleased
---------------------
- Fix #328: Type error when viewing a pending delete page
- Fix #329: Old URLs don't work since version 2.3.0

2.3.0 (April 22, 2024)
---------------------
Expand Down

0 comments on commit 5ea68d1

Please sign in to comment.