Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import themes from composer package #8

Open
lbucche opened this issue Sep 17, 2020 · 9 comments
Open

Can't import themes from composer package #8

lbucche opened this issue Sep 17, 2020 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@lbucche
Copy link

lbucche commented Sep 17, 2020

What steps will reproduce the problem?

composer create-project luyadev/luya-kickstarter:^1.0
changed the composer.json to get new releases and added package with themes in this way:
[...]
"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",
"luyadev/luya-themes": "*@dev"
},
composer update
luya migrate
luya import

LUYA import command (based on LUYA 1.7.0)

luya\cms\admin\importers\ThemeImporter:
╔═════╤════════════════════════════════════════╗
║ Key │ Value ║
╟─────┼────────────────────────────────────────╢
║ 0 │ Theme importer finished with 0 themes. ║
╚═════╧════════════════════════════════════════╝

What is the expected result?

new themes added to cms and listed in admin

What do you get instead? (A Screenshot can help us a lot!)

No new themes added

If you manually create a new theme in the app contest it works perfectly (luya theme/create)
If you create a new composer package/module-theme, you add it in the config file, and then you create the theme using the wizard, it creates correctly the new theme in package folder, but when you import theme, it isn't present.

So it seems the the ThemeImporter can't find themes that are in "external" packages.

Any idea?

LUYA Check ouput (run this script and post the result: luyacheck.php)

importer

Additional infos

Q A
LUYA Version
PHP Version 7.2.5
Platform Apache\XAMPP
Operating system Windows10
@lbucche
Copy link
Author

lbucche commented Sep 17, 2020

I've tried on linux system it works. So probably something related to the windows\Xampp platform.

@nadar
Copy link
Member

nadar commented Sep 17, 2020

@boehsermoe @lbucche maybe something with DIRECTORY_SEPERATOR

@nadar nadar added the bug Something isn't working label Sep 17, 2020
@nadar
Copy link
Member

nadar commented Sep 22, 2020

So the theme folder is not even recognized? So it might me a problem here https://github.com/luyadev/luya-module-cms/blob/master/src/admin/importers/ThemeImporter.php - as there something known regarding windows @boehsermoe ?

@boehsermoe
Copy link
Member

@lbucche please try it again with v1.7.1 fix (https://github.com/luyadev/luya/releases/tag/1.7.1)
Does it fixed your problem?

@nadar
Copy link
Member

nadar commented Sep 30, 2020

@boehsermoe i think this (https://github.com/luyadev/luya/pull/2058/files) will not fix the problem. this just fixes the problem when you use the theme create command on a windows computer i would say.

@lbucche
Copy link
Author

lbucche commented Sep 30, 2020

No with v.1.7.1 fix I get this.

luya theme/create

Enter the name (lower case) of the theme you like to generate: mytheme
Enter the theme location where to generate (as path alias e.g. app, ): [app]
Exception 'yii\base\InvalidArgumentException' with message 'Invalid path alias: @app\themes\mytheme'

in C:\MyGitProject\testthemes\vendor\yiisoft\yii2\BaseYii.php:154

Stack trace:
#0 C:\MyGitProject\testthemes\vendor\luyadev\luya-core\console\commands\ThemeController.php(63): yii\BaseYii::getAlias('@app\themes\myt...')
#1 [internal function]: luya\console\commands\ThemeController->actionCreate('mytheme')
#2 C:\MyGitProject\testthemes\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#3 C:\MyGitProject\testthemes\vendor\yiisoft\yii2\base\Controller.php(180): yii\base\InlineAction->runWithParams(Array)
#4 C:\MyGitProject\testthemes\vendor\yiisoft\yii2\console\Controller.php(179): yii\base\Controller->runAction('create', Array)
#5 C:\MyGitProject\testthemes\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('create', Array)
#6 C:\MyGitProject\testthemes\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('theme/create', Array)
#7 C:\MyGitProject\testthemes\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('theme/create', Array)
#8 C:\MyGitProject\testthemes\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#9 C:\MyGitProject\testthemes\vendor\luyadev\luya-core\base\Boot.php(251): yii\base\Application->run()
#10 C:\MyGitProject\testthemes\vendor\luyadev\luya-core\bin\luya(36): luya\base\Boot->applicationConsole()
#11 {main}

@lbucche
Copy link
Author

lbucche commented Sep 30, 2020

Reverting to previous version the "luya theme/create" command works again as normal, and I managed to create a theme in app contest as usual.
Investigating the issue deeper I found that the problem on wndows platform is in the ThemeImporter in the getThemeDefinitions function.
On windows if you var_dump the themes config at row 182 in luya-core\theme\ThemManager.php you find this
paths:

string(48) "vendor\luyadev/luya-themes\themes\escapeVelocity"
string(39) "vendor\luyadev/luya-themes\themes\forty"
string(40) "vendor\luyadev/luya-themes\themes\strata"

So there's a simple slash/backslash problem.
I tried this simple workaround and I successfully import the themes.

protected function getThemeDefinitions()
{
$themeDefinitions = [];

    if (file_exists(Yii::getAlias('@app/themes'))) {
        foreach (glob(Yii::getAlias('@app/themes/*')) as $dirPath) {
            $themeDefinitions[] = "@app/themes/" . basename($dirPath);
        }
    }
    
    foreach (Yii::$app->getPackageInstaller()->getConfigs() as $config) {

        /** @var PackageConfig $config */
        foreach ($config->themes as $theme) {
            
            //-- simple patch -----
            $normalization["\\"]="/";
            $theme = strtr($theme,$normalization);
            //-- simple patch -----
            
            if (strpos($theme, '@') === 0 || strpos($theme, '/') === 0) {
                $themeDefinitions[] = $theme;
            } else {
                $themeDefinitions[] = preg_replace('#^vendor/#', '@vendor/', $theme);
            }
        }
    }
    
    return $themeDefinitions;
}

Hope this helps.

@nadar
Copy link
Member

nadar commented Sep 30, 2020

Thank you @lbucche. Yes that was my guess as well as the importer handles the paths wrong.

@nadar
Copy link
Member

nadar commented Jul 22, 2021

@boehsermoe should we move that problem into the LUYA core issue tracker?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants