laravel-enso / activity-log

Easy to configure and beautiful to look at activity logger for your models' events
https://docs.laravel-enso.com/packages/activity-log.html
MIT License
2 stars 7 forks source link

readRalation property missing when addresses table has nullable country_id set. #5

Closed stotes closed 5 years ago

stotes commented 5 years ago

This is a bug.

Prerequisites

Description

I've modified the addresses table to allow for nullable country_id in the event an addressable object does not provide country information. Activity logger fails on the readRelation function

$this->before[$key] = $class::find($this->before[$key])->{$attribute};
$this->after[$key] = $class::find($this->after[$key])->{$attribute};

Steps to Reproduce

Make addresses.country_id nullable, have address information stored without country_id set. Perform action that triggers Logger class readRelation function.

Expected behavior

Handle nullable attributes in the activity logger.

Proposed fix

$this->before[$key] = $class::find($this->before[$key])->{$attribute} ?? null;
$this->after[$key] = $class::find($this->after[$key])->{$attribute} ?? null;

Actual behavior

ErrorException {#2023
  #message: "Trying to get property 'name' of non-object"
  #code: 0
  #file: "/home/vagrant/code/enso/vendor/laravel-enso/activitylog/src/app/Classes/Logger.php"
  #line: 101
  #severity: E_NOTICE
  trace: {
    /home/vagrant/code/enso/vendor/laravel-enso/activitylog/src/app/Classes/Logger.php:101 {}
    /home/vagrant/code/enso/vendor/sentry/sentry/src/ErrorHandler.php:194 {}
    /home/vagrant/code/enso/vendor/laravel-enso/activitylog/src/app/Classes/Logger.php:101 {}
    /home/vagrant/code/enso/vendor/laravel-enso/activitylog/src/app/Classes/Logger.php:79 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Support/Collection.php:419 {}
    /home/vagrant/code/enso/vendor/laravel-enso/activitylog/src/app/Classes/Logger.php:91 {}
    /home/vagrant/code/enso/vendor/laravel-enso/activitylog/src/app/Classes/Logger.php:37 {}
    /home/vagrant/code/enso/vendor/laravel-enso/activitylog/src/app/Traits/LogsActivity.php:32 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:347 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:196 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php:188 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:745 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:656 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:434 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Support/helpers.php:1123 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:435 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:23 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1616 {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1628 {}
    /home/vagrant/code/enso/vendor/adamsto/presto-integrations/src/app/Classes/App.php:99 {}
    /home/vagrant/code/enso/vendor/adamsto/presto-integrations/src/app/Classes/App.php:268 {}
    /home/vagrant/code/enso/vendor/adamsto/presto-integrations/src/app/Http/Controllers/OntraportController.php:122 {}
    App\Integration\App\Http\Controllers\OntraportController->updateOrCreateContact() {}
    /home/vagrant/code/enso/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54 {}
aocneanu commented 5 years ago

I guess theres no reason to be monitored by the activity log in the first place..