craftcms / generator

Scaffold new Craft CMS plugins, modules, and system components from the CLI
MIT License
83 stars 8 forks source link

Breaking Craft console #36

Closed tigerchick closed 1 month ago

tigerchick commented 1 month ago

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

brandonkelly commented 1 month ago

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 commented 1 month ago

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