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

Migration failure - Calling unknown method: craft\console\Request::getSegment() #111

Closed darylknight closed 2 years ago

darylknight commented 2 years ago

Describe the bug

After preparing everything to update to Craft 4, CP Nav fails the migration. Error:

*** applying m220409_000000_craft_4
    > rename column order in table {{%cpnav_navigation}} to sortOrder ... done (time: 0.012s)
    > add column prevLevel smallint AFTER `sortOrder` to table {{%cpnav_navigation}} ... done (time: 0.011s)
    > add column level smallint DEFAULT 1 AFTER `prevLevel` to table {{%cpnav_navigation}} ... done (time: 0.038s)
    > add column prevParentId integer AFTER `level` to table {{%cpnav_navigation}} ... done (time: 0.018s)
    > add column parentId integer AFTER `prevParentId` to table {{%cpnav_navigation}} ... done (time: 0.016s)
    > add column subnavBehaviour string AFTER `newWindow` to table {{%cpnav_navigation}} ... done (time: 0.052s)
    > update in {{%cpnav_navigation}} ... done (time: 0.004s)
    > dropping {{%cpnav_pending_navigations}} if it exists ... done (time: 0.004s)
Exception: Calling unknown method: craft\console\Request::getSegment() (/Users/darylknight/Sites/sitename/vendor/yiisoft/yii2/base/Component.php:300)
#0 /Users/darylknight/Sites/sitename/vendor/nystudio107/craft-seomatic/src/Seomatic.php(388): yii\base\Component->__call('getSegment', Array)
#1 /Users/darylknight/Sites/sitename/vendor/verbb/cp-nav/src/helpers/Permissions.php(73): nystudio107\seomatic\Seomatic->getCpNavItem()
#2 /Users/darylknight/Sites/sitename/vendor/verbb/cp-nav/src/migrations/m220409_000000_craft_4.php(99): verbb\cpnav\helpers\Permissions::getBaseNavItems()
#3 /Users/darylknight/Sites/sitename/vendor/craftcms/cms/src/db/Migration.php(49): verbb\cpnav\migrations\m220409_000000_craft_4->safeUp()
#4 /Users/darylknight/Sites/sitename/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(758): craft\db\Migration->up()
#5 /Users/darylknight/Sites/sitename/vendor/craftcms/cms/src/console/controllers/MigrateController.php(360): yii\console\controllers\BaseMigrateController->migrateUp('m220409_000000_...')
#6 [internal function]: craft\console\controllers\MigrateController->actionAll()
#7 /Users/darylknight/Sites/sitename/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /Users/darylknight/Sites/sitename/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#9 /Users/darylknight/Sites/sitename/vendor/yiisoft/yii2/console/Controller.php(182): yii\base\Controller->runAction('all', Array)
#10 /Users/darylknight/Sites/sitename/vendor/yiisoft/yii2/base/Module.php(552): yii\console\Controller->runAction('all', Array)
#11 /Users/darylknight/Sites/sitename/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#12 /Users/darylknight/Sites/sitename/vendor/craftcms/cms/src/console/Application.php(90): yii\console\Application->runAction('migrate/all', Array)
#13 /Users/darylknight/Sites/sitename/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#14 /Users/darylknight/Sites/sitename/vendor/craftcms/cms/src/console/Application.php(121): yii\console\Application->handleRequest(Object(craft\console\Request))
#15 /Users/darylknight/Sites/sitename/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#16 /Users/darylknight/Sites/sitename/craft(27): yii\base\Application->run()
#17 {main}
*** failed to apply m220409_000000_craft_4 (time: 0.346s)

Steps to reproduce

Craft CMS version

Craft CMS 3.7.51

Plugin version

3.0.17

Multi-site?

Yes

Additional context

No response

engram-design commented 2 years ago

Hmmm, this issue cropped up some time ago and fixed via https://github.com/verbb/cp-nav/commit/97323fe407d715a107e3c3fea507d4e8aa86579e in 4.0.2. This comes down to when trying to re-generate navigations on the command line, and some plugin's getCpNavItem() functions don't work so well in that scenario.

darylknight commented 2 years ago

I'm sorry I don't understand what that means. Is it fixable? I'm currently uninstalling CP Nav before upgrading to Craft 4 and re-installing it again afterwards. It's happened on 3 sites so far.

engram-design commented 2 years ago

What I mean is that it _shouldn't be happening anymore, and the site's I've tested from Craft 3 to 4 don't seem to throw this error (with SEOmatic installed), but I'll keep digging. I can't imagine you're not updating to the latest CP Nav version (4.0.5) which is why I mentioned that, just in case for some reason you're only updating to 4.0.0 or 4.0.1 (unlikely, but you never know!)

darylknight commented 2 years ago

Got it - thanks. Yeah, this is after going through everything on the update tab and adding that version with the ^ symbol, so "verbb/cp-nav": "^4.0.5",

engram-design commented 2 years ago

This is indeed still an issue, you're right. Fixed for the next release. To get this fix early, change your verbb/cp-nav requirement in composer.json to:

"require": {
  "verbb/cp-nav": "dev-craft-4 as 4.0.5",
  "...": "..."
}

Then run composer update.

darylknight commented 2 years ago

Yep, this worked - thank you!

engram-design commented 2 years ago

Fixed in 4.0.6