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

Breaking Craft console #36

Closed
tigerchick opened this issue Aug 12, 2024 · 2 comments
Closed

Breaking Craft console #36

tigerchick opened this issue Aug 12, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@tigerchick
Copy link

tigerchick commented Aug 12, 2024

Description

After having used generator to scaffold a plugin (within which everything appears to work as intended) I then needed to build another new plugin; leading me to notice that craft console is broken.

It throws the following exception when I try to run any craft command (eg php craft)

Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: craft\console\Request::isPost'

in /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/base/Component.php:154

Stack trace:
#0 /srv/users/dev-something/apps/dev-something/plugins/passwordy/src/Plugin.php(102): yii\base\Component->__get('isPost')
#1 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/base/BaseObject.php(109): tigerchick\craftpasswordy\Plugin->init()
#2 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/base/Module.php(161): yii\base\BaseObject->__construct(Array)
#3 /srv/users/dev-something/apps/dev-something/vendor/craftcms/cms/src/base/Plugin.php(122): yii\base\Module->__construct('_passwordy', Object(craft\console\Application), Array)
#4 [internal function]: craft\base\Plugin->__construct('_passwordy', Object(craft\console\Application), Array)
#5 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#6 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('tigerchick\\craf...', Array, Array)
#7 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('tigerchick\\craf...', Array, Array)
#8 /srv/users/dev-something/apps/dev-something/vendor/craftcms/cms/src/Craft.php(59): yii\BaseYii::createObject(Array, Array)
#9 /srv/users/dev-something/apps/dev-something/vendor/craftcms/cms/src/services/Plugins.php(948): Craft::createObject(Array, Array)
#10 /srv/users/dev-something/apps/dev-something/vendor/craftcms/cms/src/services/Plugins.php(233): craft\services\Plugins->createPlugin('_passwordy', Array)
#11 /srv/users/dev-something/apps/dev-something/vendor/craftcms/cms/src/base/ApplicationTrait.php(1601): craft\services\Plugins->loadPlugins()
#12 /srv/users/dev-something/apps/dev-something/vendor/craftcms/cms/src/console/Application.php(53): craft\console\Application->_postInit()
#13 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\console\Application->init()
#14 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct(Array)
#15 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/console/Application.php(89): yii\base\Application->__construct(Array)
#16 [internal function]: yii\console\Application->__construct(Array)
#17 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#18 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\console\\A...', Array, Array)
#19 /srv/users/dev-something/apps/dev-something/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\console\\A...', Array, Array)
#20 /srv/users/dev-something/apps/dev-something/vendor/craftcms/cms/src/Craft.php(59): yii\BaseYii::createObject(Array, Array)
#21 /srv/users/dev-something/apps/dev-something/vendor/craftcms/cms/bootstrap/bootstrap.php(260): Craft::createObject(Array)
#22 /srv/users/dev-something/apps/dev-something/vendor/craftcms/cms/bootstrap/console.php(42): require('/srv/users/dev-...')
#23 /srv/users/dev-something/apps/dev-something/craft(12): require('/srv/users/dev-...')
#24 {main}

I have no idea how to start fixing this so any help appreciated!

Edit:
I tried running: composer dump-autoload
It hasn't fixed it though.

Additional info

  • Craft version:4.11.1
  • PHP version:8.1.29
  • Database driver & version:MySQL 5.7.42
@tigerchick tigerchick added the bug Something isn't working label Aug 12, 2024
@brandonkelly
Copy link
Member

The error message + stack trace is showing that plugins/passwordy/src/Plugin.php is attempting to call Craft::$app->request->isPost on line 102. However isPost is only available for web requests, when Craft::$app->request is an instance of craft\web\Request. On console requests, it will be an instance of craft\console\Request.

Not sure what your code looks like exactly there, but you can fix by first making sure it’s not a console request by calling Craft::$app->request->isConsoleRequest.

@tigerchick
Copy link
Author

Thanks @brandonkelly for showing me the right direction! Much appreciated.

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

2 participants