luyadev / luya-module-cms

The LUYA CMS module provides a full functional CMS for adding contents based on blocks.
https://luya.io
MIT License
33 stars 46 forks source link

single language 404 error #372

Closed Taroxx closed 2 years ago

Taroxx commented 2 years ago

I have the same problem https://github.com/luyadev/luya-module-cms/issues/183 Site is not multilang. Table admin_lang have one row. en is default. composition is disabled. custom 404 page created as module (like in tutorial); I tried online/offline 404 custom page, but result is the same. But in prod I have An internal server error occurred. Moreover, with empty layout (white page) I have the same error. By adding lang to table I dont have this error, but custom 404 page does not work and I have 404 page like in your screenshot above. (see https://github.com/luyadev/luya-module-cms/issues/183) This is stack trace

An Error occurred while handling another error:
yii\web\NotFoundHttpException: The requested language 'xx' does not exist in language table in /site/vendor/luyadev/luya-module-cms/src/Menu.php:709
Stack trace:
#0 /site/vendor/luyadev/luya-module-cms/src/Menu.php(322): luya\cms\Menu->loadLanguageContainer('xx')
#1 /site/vendor/luyadev/luya-module-cms/src/Menu.php(213): luya\cms\Menu->getLanguageContainer('xx')
#2 /site/vendor/luyadev/luya-module-cms/src/menu/Query.php(399): luya\cms\Menu->offsetGet('xx')
#3 /site/vendor/luyadev/luya-module-cms/src/frontend/Bootstrap.php(56): luya\cms\menu\Query->one()
#4 [internal function]: luya\cms\frontend\Bootstrap->luya\cms\frontend\{closure}(Object(luya\web\ErrorHandlerExceptionRenderEvent))
#5 /site/vendor/yiisoft/yii2/base/Component.php(628): call_user_func(Object(Closure), Object(luya\web\ErrorHandlerExceptionRenderEvent))
#6 /site/vendor/luyadev/luya-core/web/ErrorHandler.php(31): yii\base\Component->trigger('onBeforeExcepti...', Object(luya\web\ErrorHandlerExceptionRenderEvent))
#7 /site/vendor/yiisoft/yii2/base/ErrorHandler.php(135): luya\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#8 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
#9 {main}
Previous exception:
yii\web\NotFoundHttpException: The requested language 'xx' does not exist in language table in /site/vendor/luyadev/luya-module-cms/src/frontend/controllers/DefaultController.php:125
Stack trace:
#0 [internal function]: luya\cms\frontend\controllers\DefaultController->actionIndex()
#1 /site/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#2 /site/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#3 /site/vendor/yiisoft/yii2/base/Module.php(534): yii\base\Controller->runAction('index', Array)
#4 /site/vendor/yiisoft/yii2/web/Application.php(104): yii\base\Module->runAction('cms/default/ind...', Array)
#5 /site/vendor/luyadev/luya-core/web/Application.php(48): yii\web\Application->handleRequest(Object(luya\web\Request))
#6 /site/vendor/yiisoft/yii2/base/Application.php(392): luya\web\Application->handleRequest(Object(luya\web\Request))
#7 /site/vendor/luyadev/luya-core/base/Boot.php(268): yii\base\Application->run()
#8 /site/vendor/luyadev/luya-core/base/Boot.php(208): luya\base\Boot->applicationWeb()
#9 /site/public_html/index.php(13): luya\base\Boot->run()
#10 {main}

Originally posted by @Taroxx in https://github.com/luyadev/luya-module-cms/issues/183#issuecomment-976752796

nadar commented 2 years ago

i will do a research, but the exception which is thrown seems clear to me: The requested language 'xx' does not exist in language table in /site/vendor/luyadev/luya-module-cms/src/Menu.php:709 - so you where trying to open an url yourwebsite.com/xx?

Taroxx commented 2 years ago

i will do a research, but the exception which is thrown seems clear to me: The requested language 'xx' does not exist in language table in /site/vendor/luyadev/luya-module-cms/src/Menu.php:709 - so you where trying to open an url yourwebsite.com/xx?

Yes, Im trying to open yourwebsite.com/xx and yourwebsite.com/xx/servisec and etc... And in prod i have this (yii2 default) error page or this stack trace (without css styles) in local mode

Taroxx commented 2 years ago

Withal app log has the same error stack trace.

Taroxx commented 2 years ago

Yii version 2.0.43 php 7.3.31 nginx 1.20.1 mariaDB part of composer "require": { "luyadev/luya-core" : "^1.0", "luyadev/luya-module-admin" : "^3.0", "luyadev/luya-module-cms" : "^3.0", "luyadev/luya-bootstrap3" : "^1.0", "luyadev/luya-generic" : "^1.0", "yiisoft/yii2-smarty": "^2.0", "luyadev/luya-module-news": "~2.0", "yiisoft/yii2-httpclient": "^2.0", "cebe/luya-module-sitemap": "^1.2", "thadafinser/user-agent-parser": "^2.0", "rmrevin/yii2-minify-view": "^2.0", "alexandernst/yii2-device-detect": "0.0.12" },

nadar commented 2 years ago

Yes, Im trying to open yourwebsite.com/xx and yourwebsite.com/xx/servisec

But what is xx in this case? Is this a page which slug xx? Or is it a language you have not created yet?

Pages with a slug of only 2 chars does not work, because it try to resolve those as language.

"luyadev/luya-core" : "^1.0", "luyadev/luya-module-admin" : "^3.0", "luyadev/luya-module-cms" : "^3.0",

I am very sure it won't fix the problem, but please upgrade to latest versions. Core is not required, but instead add ^4.0 for cms and admin, see: https://github.com/luyadev/luya-kickstarter-bootstrap4/blob/master/composer.json#L6-L8

Taroxx commented 2 years ago

But what is xx in this case? Is this a page which slug xx? Or is it a language you have not created yet?

This is a language, it can be any two characters, except "en".

I am very sure it won't fix the problem, but please upgrade to latest versions. Core is not required, but instead add ^4.0 for cms and admin, see: https://github.com/luyadev/luya-kickstarter-bootstrap4/blob/master/composer.json#L6-L8

ok

nadar commented 2 years ago

Ok, but have you added the language xx to your languages tables in the admin UI?

Taroxx commented 2 years ago

No. According to this logic, should I to add all combinations of letters (like aa, ab, ac, ad ... nm, nz, jy and etc) to the table? Аt least it's weird

nadar commented 2 years ago

You have to, this language is bound to the cms. We only provide a translation solution for language which are exists in the table and afterwards you can edit those languages also in the CMS.

I think you are talking about a "frontend" translation solution according to https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n

But this has "nothing" to do with the CMS. The CMS and its language are bound to the LUYA language table at its all about providing the content for different languages from within the CMS!

Taroxx commented 2 years ago

Only I want - is 404 page on yourwebsite.com/xx yourwebsite.com/xx/serb/saf yourwebsite.com/zz yourwebsite.com/aa/serb/saf and etc I dont need to translate my site. My site is single language. My site is EN only!

Moreover, I want to see 404 page on yourwebsite.com/en page. This case I did with on beforeAction in configuration by throw NotFoundHttpException() on any page, that containt /en/.

Composition is hide by hidden => true!

nadar commented 2 years ago

no need for !!! here. Yes its about the error page indeed, i forgot that. thought you have those languages but can't resolve them in your website.

Maybe:

'composition' => [
'expectedValues' => ['en']
]

could do the trick, but i need to verify this first.

Taroxx commented 2 years ago

And what about aa,ab,ac,ad ... zx,zy,zz ?

Taroxx commented 2 years ago

I am very sure it won't fix the problem, but please upgrade to latest versions. Core is not required, but instead add ^4.0 for cms and admin, see: https://github.com/luyadev/luya-kickstarter-bootstrap4/blob/master/composer.json#L6-L8

 Problem 1
    - luyadev/luya-module-admin 4.1.0 requires luyadev/luya-core ^2.0 -> satisfiable by luyadev/luya-core[2.0.0, 2.0.1] but these conflict with your requirements or minimum-stability.
    - luyadev/luya-module-admin 4.0.0 requires luyadev/luya-core ^2.0 -> satisfiable by luyadev/luya-core[2.0.0, 2.0.1] but these conflict with your requirements or minimum-stability.
    - Installation request for luyadev/luya-module-admin ^4.0 -> satisfiable by luyadev/luya-module-admin[4.0.0, 4.1.0].
nadar commented 2 years ago

What does your composer.json look like?

Taroxx commented 2 years ago
{
    "name": "luyadev/luya-kickstarter",
    "description": "The kickstarter project for a new LUYA application.",
    "type": "luya-kickstarter",
    "license":"MIT",
    "require": {
        "luyadev/luya-core" : "^1.0",
        "luyadev/luya-module-admin" : "^4.0",
        "luyadev/luya-module-cms" : "^4.0",
        "luyadev/luya-bootstrap3" : "^1.0",
        "luyadev/luya-generic" : "^1.0",
        "yiisoft/yii2-smarty": "^2.0",
        "luyadev/luya-module-news": "~2.0",
        "yiisoft/yii2-httpclient": "^2.0",
        "cebe/luya-module-sitemap": "^1.2",
        "thadafinser/user-agent-parser": "^2.0",
        "rmrevin/yii2-minify-view": "^2.0",
        "alexandernst/yii2-device-detect": "0.0.12"
    },
    "require-dev": {
        "yiisoft/yii2-gii" : "^2.0",
        "yiisoft/yii2-debug" : "^2.0",
        "luyadev/luya-testsuite" : "^1.0"
    },
    "scripts": {
        "post-create-project-cmd": [
            "yii\\composer\\Installer::postCreateProject"
        ]
    },
    "extra": {
        "yii\\composer\\Installer::postCreateProject": {
            "setPermission": [
                {
                    "public_html/assets": "0777",
                    "public_html/storage": "0777",
                    "runtime" : "0777"
                }
            ]
        },
        "asset-installer-paths": {
            "bower-asset-library": "vendor/bower"
        },
        "branch-alias": {
            "dev-master": "1.0.x-dev"
        }
    },
    "config": {
        "fxp-asset": {
            "enabled": false
        }
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ]
}
nadar commented 2 years ago

I mentioned that already:

Core is not required, but instead add ^4.0 for cms and admin, see: https://github.com/luyadev/luya-kickstarter-bootstrap4/blob/master/composer.json#L6-L8

Maybe also use testsuite version ^3.0 or remove it if you don't need that

Taroxx commented 2 years ago

Stay at 3.0. Update to 4.0 upgrade core to 2.0 automaticaly and dont work to me. Too many errors after this update.

nadar commented 2 years ago

As you wish. The upgrade guides are very ease, not much to upgrade, mainly run migrate and import and ensure no to use Yii::$app->composition->language and check the part with the view files in the your "app blocks" (cms upgrade)

Taroxx commented 2 years ago

Maybe later, thanks.

I am very sure it won't fix the problem, but please upgrade to latest versions. Core is not required, but instead add ^4.0 for cms and admin, see: https://github.com/luyadev/luya-kickstarter-bootstrap4/blob/master/composer.json#L6-L8

Now I need to solve the problem with an error instead of 404.

ensure no to use Yii::$app->composition->language

What do you mean?

Taroxx commented 2 years ago

Maybe later, thanks.

I have updated to last version, but error sill there.

Taroxx commented 2 years ago

Found in logs

[warning][yii\i18n\PhpMessageSource::loadMessages] The message file for category 'yii' does not exist: /site/vendor/yiisoft/yii2/messages/xx/yii.php
in /site/vendor/luyadev/luya-module-cms/src/Menu.php:705
in /site/vendor/luyadev/luya-module-cms/src/Menu.php:325
in /site/vendor/luyadev/luya-module-cms/src/Menu.php:216

With real short code (random lang) this warning has not been

nadar commented 2 years ago

I am currently preparing a vhost for your example, so i try to summary all informations you gave to check wheather i understand correctly or not:

  1. Your Webseite example.com is in english and you have hidden the composition which will generate links like example.com/about-me and so on. :heavy_check_mark:
  2. When a page is requested which is not found, then you like to show the configured 404 page. For example example.com/does-not-exists shows the custom 404 page (this also works, as far as i understood, if the slug is long enought, more then 2 chars) :heavy_check_mark:
  3. When you enter an url like example.com/xx an Exception The requested language 'xx' does not exist in language table is thrown BUT INSTEAD IT SHOULD RETURN THE 404 PAGE? :white_check_mark:
  4. You want to always return the 404 custom page for any slug which does not exists, like above: example.com/xx should show the 404 custom :white_check_mark:
  5. expectedValues' => ['en'] should ensure that only the en language is allowed and any other langue short code will throwns an exception, but this did not work in your case? :question:
Taroxx commented 2 years ago

1-4 yes, thats right

5. expectedValues' => ['en'] should ensure that only the en language is allowed and any other langue short code will throwns an exception, but this did not work in your case? ❓

Table admin_lang have one row - is en and it is default.

image

When I open url like example.com/en or example.com/en/page1 i have seen pages like example.com or example.com/page1 without any errors. This is not good too, but this case I did with hook on beforeAction in configuration by throw NotFoundHttpException() on any page, that containt /en/.

image

You can see, that this is not the best solution. If you mean that expectedValues' => ['en'] at composition section solve this problem, I will try this.

Next. I temporary added random langs to admin_table, to debug this problem, after that urls with this shortcodes (like example.com/de or example.com/de/page1) open 404 page, but not custom, for example

image

Next. I temporary diactiveted custom 404. But there is no result.

Next. When I try to open url with random shortcode, which is not in the table, I have this php error. Stack trace above. I tried to intercept this exception at on beforeAction but there is no Result. But previous exception in stack trace is been like below

Previous exception:
yii\web\NotFoundHttpException in /site/configs/config.php:172
Stack trace:
#0 [internal function]: luya\base\Boot->{closure}(Object(yii\base\ActionEvent))
#1 /site/vendor/yiisoft/yii2/base/Component.php(628): call_user_func(Object(Closure), Object(yii\base\ActionEvent))
#2 /site/vendor/yiisoft/yii2/base/Module.php(706): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#3 /site/vendor/yiisoft/yii2/base/Controller.php(169): yii\base\Module->beforeAction(Object(yii\base\InlineAction))
#4 /site/vendor/yiisoft/yii2/base/Module.php(534): yii\base\Controller->runAction('', Array)
#5 /site/vendor/yiisoft/yii2/web/Application.php(104): yii\base\Module->runAction('', Array)
#6 /site/vendor/luyadev/luya-core/web/Application.php(52): yii\web\Application->handleRequest(Object(luya\web\Request))
#7 /site/vendor/yiisoft/yii2/base/Application.php(392): luya\web\Application->handleRequest(Object(luya\web\Request))
#8 /site/vendor/luyadev/luya-core/base/Boot.php(255): yii\base\Application->run()
#9 /site/vendor/luyadev/luya-core/base/Boot.php(195): luya\base\Boot->applicationWeb()
#10 /site/public_html/index.php(13): luya\base\Boot->run()
#11 {main}
Taroxx commented 2 years ago

I tried this

image

And get error on example.com/en or example.com/en/page1 pages

image

UPDATE This error on all pages

nadar commented 2 years ago

https://github.com/luyadev/luya/blob/master/core/web/Composition.php#L120-L138

you have to configured it like this, i was not aware of that, sorry:

'expectedValues' => ['langShortCode' => ['en']]