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

Migration error if cookieValidationKey is set in config #1772

Closed
JDL747 opened this issue Feb 23, 2018 · 7 comments · Fixed by #1952
Closed

Migration error if cookieValidationKey is set in config #1772

JDL747 opened this issue Feb 23, 2018 · 7 comments · Fixed by #1952
Assignees
Labels

Comments

@JDL747
Copy link
Contributor

JDL747 commented Feb 23, 2018

What steps will reproduce the problem?

Set the cookieValidationKey parameter in component request and create or execute migration

What is the expected result?

Successful execution of migration

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

yii\base\UnknownPropertyException: Setting unknown property: yii\console\Response::isSent in vendor/yiisoft/yii2/base/Component.php:209
Stack trace:
#0 vendor/yiisoft/yii2/BaseYii.php(546): yii\base\Component->__set('cookieValidatio...', 'me9M5KPGpji_WjU...')

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

1: [in_array('mod_rewrite', apache_get_modules())] true
2: [ini_get('short_open_tag')] '1'
3: [ini_get('error_reporting')] '22519'
4: [phpversion()] '7.0.10'
5: [php_ini_loaded_file()] '/Applications/AMPPS/php/etc/php.ini'
6: [php_sapi_name()] 'apache2handler'

Additional infos

Q A
LUYA Version 1.0.3
PHP Version 7
Platform Apache
Operating system OSX
@nadar nadar self-assigned this Feb 25, 2018
@nadar nadar added the bug label Feb 25, 2018
@nadar
Copy link
Contributor

nadar commented Feb 25, 2018

Yes this is bug and maybe also a "design" problem from luya console commands. As we don't want people to copy past two configs just to run console commands, we merge those into one, therefore the cookieValidationKey is only existing in the luya\web\Request component and not luya\console\Request.

Not sure how to consistent fix this "splitting" behavior.

@nadar
Copy link
Contributor

nadar commented Mar 10, 2018

Same example

An Error occurred while handling another error:
yii\base\UnknownPropertyException: Setting unknown property: yii\console\Response::formatters in .../vendor/yiisoft/yii2/base/Component.php:209

@nick-denry
Copy link

As we don't want people to copy past two configs just to run console commands, we merge those into one

Maybe it is not about duplication, but overriding? Like if env-local-console.php exists it has priority over default config for console commands?

I have a problem with migration command when I've tryed to inject menu item via config bootstrap.

I have this code at bootstrapped module

Yii::$app->menu->injectItem($newItem);

It works fine for frontend, but when I've try to run migration I've got

php vendor/bin/luya migrate
Exception 'yii\base\InvalidConfigException' with message 'Unknown component ID: composition'

in /var/www/stends62/vendor/yiisoft/yii2/di/ServiceLocator.php:139

Btw basic yii2 template has standalone console config. I think cause it needs different bootstrap section and other modules.

https://github.com/yiisoft/yii2-app-basic/blob/master/config/console.php

@baqianxin
Copy link
Contributor

baqianxin commented Apr 13, 2018

hi, @nadar @nick-denry ;
the env-console.php is the most original and succinct:

<?php
    /**
    * [env-console.php]
    */

`
第一种:我修改了env.php:

    $config_file = $this->isCli()? require 'env-console.php': require'env-local.php';
    return $config_file;

第二种:我希望以Luya的方式修改\luya\base\Boot:

    /**
     * @var string The path to the config file, which returns an array containing you configuration.
     */
    public $configFile = '../configs/env.php';

    /**
     * @var string Maybe it should be modified in Luya's way
     */
    public $configFileConsole = '../configs/env-console.php';

    /**
     * Get the config array from the configFile path with the predefined values.
     *
     * @throws \luya\Exception Throws exception if the config file does not exists.
     * @return array The array which will be injected into the Application Constructor.
     */
    public function getConfigArray(){
    ...
        $config_file = $this->isCli()? require $this->configFileConsole: $this->configFile;
    ...
    }

@nick-denry
Copy link

nick-denry commented Apr 13, 2018

Therefore it could have names as env-console and env-web instead of env-local to represent different app parts.

The idea seems ok to me. Is there a technical reason why console should have the same config?

nadar added a commit that referenced this issue Jun 16, 2018
@nadar nadar mentioned this issue Aug 27, 2019
@nadar
Copy link
Contributor

nadar commented Aug 27, 2019

This issue is still not resolved and i totally agree with everyone we need a solution for that which must support the handling of console and web application. I have made a pull request proposal, if someone likes to take a view, feel free to comment:

@baqianxin @nick-denry
#1952

@nadar
Copy link
Contributor

nadar commented Aug 27, 2019

$config = new Config('myapp', dirname(__DIR__), [
    'siteTitle' => 'My LUYA Project',
    'defaultRoute' => 'cms',
    // other application level configurations
]);

// define global components which works either for console or web runtime

$config->component('mail', [
    'host' => 'xyz',
    'from' => '[email protected]',
]);

$config->component('db', [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=prod_db',
    'username' => 'foo',
    'password' => 'bar',
]);

// define components which are only for web or console runtime:

$config->webComponent('request', [
    'cookieValidationKey' => 'xyz',
]);

// which is equals to, but the above is better to read and structure in the config file

$config->component('request', [
    'cookieValidationKey' => 'xyz',
])->webRuntime();

// adding modules

$config->module('admin', [
    'class' => 'luya\admin\Module',
    'secureLogin' => true,
]);

$config->module('cms', 'luya\cms\frontend\Module'); // which is equals to $config->module('cms', ['class' => 'luya\cms\frontend\Module']);

// export and generate the config for a given enviroment or environment independent.

return $config->toArray(); // returns the config not taking care of enviroment variables like prod, env

return $config->toArray(Config::ENV_PROD);

Switching between envs can be usefull if certain configurations should only apply on a certain environment. Therefore you can add env() behind componenets, applications and modules.

$config->component('db', [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=prod_db',
    'username' => 'foo',
    'password' => 'bar',
])->env(Config::ENV_LOCAL);

$config->component('db', [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=prod_db',
    'username' => 'foo',
    'password' => 'bar',
])->env(Config::ENV_DEV);

$config->component('db', [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=prod_db',
    'username' => 'foo',
    'password' => 'bar',
])->env(Config::ENV_PROD);

return $config->toArray(Config::ENV_PROD); // would only return the prod env db component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants