laravel-enso/core

2.13 upgrade command throws on empty menu (has_children true)

jlsjonas opened this issue · 6 comments

This is a bug.

Prerequisites

  • Are you running the latest version? (upgrade issue)
  • Are you reporting to the correct repository?
  • Did you check the documentation?
  • Did you perform a cursory search?

Description

λ php artisan enso:upgrade
The upgrade process has started
Renaming vue datatable routes
Renaming was successfully performed
Upgrading the menu structure
Permission menu issue:{"id":21,"parent_id":null,"permission_id":null,"name":"<redacted>","icon":"<redacted>","order_index":200,"link":"","has_children":true,"created_at":"2018-10-25 11:09:04","updated_at":"2018-10-25 11:09:04"}

   ErrorException  : Trying to get property of non-object

  at C:\<redacted>\vendor\laravel-enso\core\src\app\Commands\Upgrade.php:75
    71|         Menu::all()->each(function ($menu) {
    72|             if (! is_null($menu->link)) {
    73|                 try {
    74|                     $menu->update([
  > 75|                         'permission_id' => Permission::whereName($menu->link)->first()->id,
    76|                     ]);
    77|                 } catch (\ErrorException $exception){
    78|                     $this->error('Permission menu issue:'. $menu->toJson());
    79|                     throw $exception;

  Exception trace:

  1   Raven_Breadcrumbs_ErrorHandler::handleError("Trying to get property of non-object", "C:\<redacted>\vendor\laravel-enso\core\src\app\Commands\Upgrade.php", [Object(LaravelEnso\MenuManager\app\Models\Menu)])
      C:\<redacted>\vendor\laravel-enso\core\src\app\Commands\Upgrade.php:75

  2   LaravelEnso\Core\app\Commands\Upgrade::LaravelEnso\Core\app\Commands\{closure}(Object(LaravelEnso\MenuManager\app\Models\Menu))
      C:\<redacted>\vendor\laravel\framework\src\Illuminate\Support\Collection.php:405

Note: I added a try/catch to be able to detect the source of the issue; they are not the cause but a debugging step.

Steps to Reproduce

  1. execute 2.13.0 upgrade steps with a structure-manager generated has_children=true menu item

Expected behavior

upgrade to happen

Actual behavior

above errors thrown

wrapping the update in an if checking for $menu->link should likely do the trick (will report in here if I encounter more likely related issues; keeping the issue open as the code will need a change either way)

it's not clear, $menu->link is not null in your case?

No, it's was an empty string...

🤦‍♂️ I just saw the ! is_null check 😅 completely looked over it during debugging 😅

so yeh... I guess changing line 72 from if (! is_null($menu->link)) { to if (! is_null($menu->link) && ! empty($menu->link)) { should 100% do the trick (the rest of the upgrade went smoothly 😎 )

It still is something related to your setup, because a parent menu is supposed to have null in the link column, not an empty string. This is what ConvertEmptyStringsToNull middleware does.. or maybe you commented/removed it ?!

Nope, that middleware is still in there; strange 🤔
it was from the menu created while dealing with the validation issues in structure manager though; might've been related to that? From what I see it's a http-side middleware though; so might've not affected the SM? (but your recent laravel-enso/cli@41a8706 should've mitigated that in the future. would still add the extra check to the upgrade command or add a note in readme in case others are dealing with the same before closing this)

The problem was caused by the issue addressed in the above commit.

SM was creating parent menus with empty string instead of nulls