verbb / patrol

Easy Maintenance Mode and Smart HTTPS Routing for Craft CMS
MIT License
29 stars 8 forks source link

Avoid ssl routing on console commands #4

Closed tmulry closed 6 years ago

tmulry commented 6 years ago

I have a custom console command that is erroring out on this plugin. Looks like there needs to be a check for a running console. In addition, the getUrl command is deprecated per:

https://github.com/craftcms/docs/blob/79b58c2e3886ccbdbc5eda32cfae4a52d00046a5/en/changes-in-craft-3.md#template-functions

`$ bin/craft.sh somecraftcommand Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: craft\console\Request::getUrl()'

in /usr/share/nginx/craft/vendor/yiisoft/yii2/base/Component.php:294

Stack trace:

0 /usr/share/nginx/craft/vendor/selvinortiz/patrol/src/services/PatrolService.php(47): yii\base\Component->__call('getUrl', Array)

1 /usr/share/nginx/craft/vendor/selvinortiz/patrol/src/services/PatrolService.php(35): selvinortiz\patrol\services\PatrolService->handleSslRouting()

2 /usr/share/nginx/craft/vendor/selvinortiz/patrol/src/Patrol.php(47): selvinortiz\patrol\services\PatrolService->watch()

3 [internal function]: selvinortiz\patrol\Patrol->selvinortiz\patrol{closure}(Object(yii\base\Event))

4 /usr/share/nginx/craft/vendor/yiisoft/yii2/base/Component.php(557): call_user_func(Object(Closure), Object(yii\base\Event))

5 /usr/share/nginx/craft/vendor/craftcms/cms/src/services/Plugins.php(223): yii\base\Component->trigger('afterLoadPlugin...')

6 /usr/share/nginx/craft/vendor/craftcms/cms/src/base/ApplicationTrait.php(1195): craft\services\Plugins->loadPlugins()`

tmulry commented 6 years ago

looks like getUrl is only depcrecated on tempaltes. Also based on some local testing, there is some nuance with getUrl vs. pathInfo that I haven't been able to dig into. So that part can probably stay for now.

selvinortiz commented 6 years ago

Thank you, @tmulry I'll try to get this merged as soon as I get a chance.