verbb / cp-nav

Control Panel Nav is a Craft CMS plugin to help manage your Control Panel navigation.
MIT License
130 stars 11 forks source link

Resetting navigation layouts through content migration #85

Closed jamesmacwhite closed 3 years ago

jamesmacwhite commented 3 years ago

Description

I've found from a Craft 2 site the CP nav layouts become messed up like icons being repeated everywhere and items missing. Using the reset layout action resolves this, however I was looking at doing this in a content migration to automate it.

I can't call the controller directly as it's intended to use POST and this is from console, but I was able to use the similar code within the NavigationController.php with the CpNav::$plugin calls to replicate the delete layout and reset logic in a content migration. However, when calling from a migration, things break when hitting this line:

https://github.com/verbb/cp-nav/blob/craft-3/src/services/Service.php#L192

Calling unknown method: craft\console\Request::getPathInfo()

This is because it's assumed it's a web request, but calling from console, this isn't the case. There is a potentially simple solution, wrap it with:

if(!Craft::$app->getRequest()->getIsConsoleRequest()) {
    (new Cp())->nav();
}

Would you consider allowing this change? I'm aware this is a very specific requirement but in theory shouldn't hurt the existing purpose. Maybe there is a fixable reason why CP layouts are messed up, but resetting them does seem to resolve it, so I figured that should be the solution.

engram-design commented 3 years ago

Happy to accommodate your needs. Migrating from a Craft 2 to 3 site can be tricky in a number of ways (not just for CP Nav), so the recommended approach would actually be to reset the layouts for peace-of-mind.

If you want to add a PR, happy to accept it, or I can add this in the next release.

jamesmacwhite commented 3 years ago

@engram-design Thank you! That is most helpful. I have made a PR and referenced this issue in the comments.

jamesmacwhite commented 3 years ago

Resolved by #86.

engram-design commented 3 years ago

Added in 3.0.15