michnhokn / kirby-logger

Add a logger to your Kirby3 website
MIT License
21 stars 5 forks source link

Error when logging out #2

Open S1SYPHOS opened 2 years ago

S1SYPHOS commented 2 years ago

Hey there, when logging out, I get this message: Call to a member function email() on null. Commenting out Line 159 inside classes/Logger.php makes this error go away, see https://github.com/michnhokn/kirby3-logger/blob/main/classes/Logger.php#L159

Cheers, S1SYPHOS

S1SYPHOS commented 2 years ago

// Update:

Since $event stores the current user, I'm able to mitigate the problem like so:

# Lines 156 - 161
$log = new Log([
    'type' => $event->type(),
    'action' => $event->action(),
    'user' => $event->user()->email(),
    'language' => kirby()->languageCode(),
]);

Let me know if you'd be willing to merge a PR and I'll whip one up right away!

michnhokn commented 2 years ago

Go for it 👌 Thank you

S1SYPHOS commented 2 years ago

I'll open up a PR and let you know 🦊

dwd0tcom commented 2 years ago

I get the same error, even when I try to reorder images for example.

S1SYPHOS commented 2 years ago

I should really send this PR 😀

WA-MB commented 1 year ago

my solution

/**
     * @param  Event  $event
     */
    public static function log(Event $event): void
    {
        if (!in_array($event->type(), self::TYPES) || $event->action() === 'render') {
            return;
        }

        $log = self::getLog($event);
        self::$connection->table('logs')->insert($log->toArray());
    }