luke-nehemedia / craft-emailobfuscator

A simple email obfuscate plugin (using rot13) for CraftCMS3
MIT License
3 stars 1 forks source link

Plugin breaks craft terminal #5

Closed kaspar-allenbach closed 3 years ago

kaspar-allenbach commented 5 years ago

When I have emailobfuscator installed the craft terminal no longer works.

Stuff like ./craft setup or ./craft project-config/sync result in the following error:

kasparal@s053 [~/public_html/atelier6]# ./craft setup
Exception 'yii\base\InvalidConfigException' with message 'The directory does not exist: /path_to_repo/assets'

in /path_to_repo/vendor/yiisoft/yii2/web/AssetManager.php:213

Stack trace:
#0 /path_to_repo/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\web\AssetManager->init()
#1 [internal function]: yii\base\BaseObject->__construct(Array)
#2 /path_to_repo/vendor/yiisoft/yii2/di/Container.php(376): ReflectionClass->newInstanceArgs(Array)
#3 /path_to_repo/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('yii\\web\\AssetMa...', Array, Array)
#4 /path_to_repo/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->get('yii\\web\\AssetMa...', Array, Array)
#5 /path_to_repo/vendor/yiisoft/yii2/di/ServiceLocator.php(137): yii\BaseYii::createObject(Array)
#6 /path_to_repo/vendor/yiisoft/yii2/base/Module.php(742): yii\di\ServiceLocator->get('assetManager', true)
#7 /path_to_repo/vendor/craftcms/cms/src/console/Application.php(162): yii\base\Module->get('assetManager', true)
#8 /path_to_repo/vendor/yiisoft/yii2/base/Application.php(608): craft\console\Application->get('assetManager')
#9 /path_to_repo/vendor/yiisoft/yii2/web/View.php(225): yii\base\Application->getAssetManager()
#10 /path_to_repo/vendor/yiisoft/yii2/web/View.php(285): yii\web\View->getAssetManager()
#11 /path_to_repo/vendor/lucasbares/craft-emailobfuscator/src/CraftEmailobfuscator.php(59): yii\web\View->registerAssetBundle('lucasbares\\craf...')
#12 /path_to_repo/vendor/yiisoft/yii2/base/BaseObject.php(109): lucasbares\craftemailobfuscator\CraftEmailobfuscator->init()
#13 /path_to_repo/vendor/yiisoft/yii2/base/Module.php(158): yii\base\BaseObject->__construct(Array)
#14 /path_to_repo/vendor/craftcms/cms/src/base/Plugin.php(127): yii\base\Module->__construct('craft-emailobfu...', Object(craft\console\Application), Array)
#15 [internal function]: craft\base\Plugin->__construct('craft-emailobfu...', Object(craft\console\Application), Array)
#16 /path_to_repo/vendor/yiisoft/yii2/di/Container.php(384): ReflectionClass->newInstanceArgs(Array)
#17 /path_to_repo/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('lucasbares\\craf...', Array, Array)
#18 /path_to_repo/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->get('lucasbares\\craf...', Array, Array)
#19 /path_to_repo/vendor/craftcms/cms/src/services/Plugins.php(897): yii\BaseYii::createObject(Array, Array)
#20 /path_to_repo/vendor/craftcms/cms/src/services/Plugins.php(230): craft\services\Plugins->createPlugin('craft-emailobfu...', Array)
#21 /path_to_repo/vendor/craftcms/cms/src/base/ApplicationTrait.php(1323): craft\services\Plugins->loadPlugins()
#22 /path_to_repo/vendor/craftcms/cms/src/console/Application.php(65): craft\console\Application->_postInit()
#23 /path_to_repo/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\console\Application->init()
#24 /path_to_repo/vendor/yiisoft/yii2/base/Application.php(206): yii\base\BaseObject->__construct(Array)
#25 /path_to_repo/vendor/yiisoft/yii2/console/Application.php(89): yii\base\Application->__construct(Array)
#26 /path_to_repo/vendor/craftcms/cms/src/console/Application.php(54): yii\console\Application->__construct(Array)
#27 [internal function]: craft\console\Application->__construct(Array)
#28 /path_to_repo/vendor/yiisoft/yii2/di/Container.php(384): ReflectionClass->newInstanceArgs(Array)
#29 /path_to_repo/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('craft\\console\\A...', Array, Array)
#30 /path_to_repo/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->get('craft\\console\\A...', Array, Array)
#31 /path_to_repo/vendor/craftcms/cms/bootstrap/bootstrap.php(248): yii\BaseYii::createObject(Array)
#32 /path_to_repo/vendor/craftcms/cms/bootstrap/console.php(34): require('/home/kasparal/...')
#33 /path_to_repo/craft(21): require('/home/kasparal/...')
#34 {main}

As you can see your plugin is mentioned in the stacktrace. If I deactivate it all is running well.

I I create a asset folder in the root it is working agin as well. Craft support assumes that:

To me, it looks like none of this line gets parsed and you end up with this odd assets error.

luke-nehemedia commented 5 years ago

Hello kaspar,

thank you for reporting this.

Unfortunately I cannot confirm this error.

I tried it on a test system running Craft Pro 3.2.5.1 (PHP 7.1.30) and everything works fine. No problem running ./craft setup.

Can you assure that /vendor/propaganistas/email-obfuscator/assets exists and that CRAFT_VENDOR_PATH is defined in your installation?

kaspar-allenbach commented 5 years ago

/vendor/propaganistas/email-obfuscator/assets is present How can I check for CRAFT_VENDOR_PATH ?

luke-nehemedia commented 5 years ago

Just use Craft::info(CRAFT_VENDOR_PATH, 'test'); for the moment and take a look into the console.log

kaspar-allenbach commented 5 years ago

Where do I have to place this? In the index.php?

luke-nehemedia commented 5 years ago

I have done some testing.

I don't get why the AssetBundle is initiated correctly when activating the plugin within the browser, but fails to do so via the console. I could not find the differences in the source code.

Can you check whether this workaround works?

 // replace those 3 lines
if( $this->settings->includeJS) {
        $this->view->registerAssetBundle(CraftEmailobfuscatorPropaganistasAssets::class);
 }

 // with these
 if( $this->settings->includeJS && $this->request instanceof Craft\web\request) {
        $this->view->registerAssetBundle(CraftEmailobfuscatorPropaganistasAssets::class);
}

Changes relate to the file: CraftEmailobfuscator.php

kaspar-allenbach commented 5 years ago

I'l test it as soon as I can. I had also extensive emails with the craft support. Oli suggested this:

Could you try to add: use lucasbares\craftemailobfuscator\CraftEmailobfuscatorPropaganistasAssets; At the top (below the namespace declaration) of: /vendor/lucasbares/craft-emailobfuscator/src/CraftEmailobfuscator.php Re-enable the plugin and try running a command again please?

-Oli

But this had no effect.

luke-nehemedia commented 5 years ago

I tried this, too.

I also moved the Asset to resources/ and renamed it to CraftEmailobfuscatorPropaganistas and CraftEmailobfuscatorPropaganistasAssetBundle. No effect.

My workaround just disables this part of the code, which is not necessary for installation. During a normal page call, $this->request will be an instance of Craft\web\request, otherwise Craft\console\request. I did not found an easier way to check whether it is a console request. However, I do not like this solution and I think there has to be a better way of doing it.

Maybe it is just the wrong place to put this code, but I don't know where else to put this line. I would love to somehow "hook" it to the Twig filter, but since the filter is developed by someone else (a separate package I reference to) I cannot modify it.

janhenckens commented 3 years ago

Hey @luke-nehemedia, I added a PR that should fix this issue. Can you have a look? Thanks!

janhenckens commented 3 years ago

@luke-nehemedia Could you have a look at this please? Waiting on this plugin for a Craft 2 > 3 upgrade.

luke-nehemedia commented 3 years ago

Hello jan! Thank's a lot! I will have a look this week!

janhenckens commented 3 years ago

Hey @luke-nehemedia, any updates on this?

luke-nehemedia commented 3 years ago

Yes, I have an exam this Thursday and plan to look into it afterwards. I am very sorry for the delay.

luke-nehemedia commented 3 years ago

Just published an update to the plugin. I hope this solves the issue.