luyadev / luya-themes

A collection of Themes for LUYA.
https://luya.io
MIT License
5 stars 2 forks source link

Can't import themes from composer package #8

Open lbucche opened 3 years ago

lbucche commented 3 years ago

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 commented 3 years ago

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

nadar commented 3 years ago

@boehsermoe @lbucche maybe something with DIRECTORY_SEPERATOR

nadar commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

nadar commented 3 years ago

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