Giter Club home page Giter Club logo

Comments (9)

rabol avatar rabol commented on September 26, 2024

same here

from laravel-activitylog.

rabol avatar rabol commented on September 26, 2024

Depend on how you look at it, the issue is either in the trait LogsAtivity line 84, where tapActivity is called if it exists and then on line 88 the $logger->log() is called.
Or in ActivityLogger->log() method, the tapActivity is also called on line 170

from laravel-activitylog.

krembo avatar krembo commented on September 26, 2024

Same here.
It's a result of a feature introduced in this PR - #1031
There was a try to suggest a removal here - #1170 - which was blocked by the maintainers...

The solution in #1170 was good as tapActivity is called in log() method anyway.

from laravel-activitylog.

xdubois avatar xdubois commented on September 26, 2024

I'm facing the samee issue, it's kind of weird it is called a feature

from laravel-activitylog.

renky avatar renky commented on September 26, 2024

I faced the same issue. I try to log all activities on related sub-models on the parent-model. Therefor I use the tapActivity method on the submodel and rewrite it to the parent and add the properties to "sub-arrays"
(if there is a better way to get this result - I'm open for suggestions).

Finally my method looks like that:

    public function tapActivity(Activity $activity, string $eventName): void
    {
        $activity->subject_type = $this->parent::class;
        $activity->subject_id = $this->parent->id;

        $activity->properties = $activity->properties->
            map(fn($attributes) => ['relationName' => $attributes]);
    }

I expected to get an entry like this:

     App\Models\Activity {
        ...
        properties: "{"attributes":{"relationName":{"value":"oldvalue"}},"old":{"relationName":{"value":"newvalue",
        ...
      },

But indeed I get this:
I expected to get an entry like this:

     App\Models\Activity {
        ...
        properties: "{"attributes":{"relationName":{"relationName":{"value":"oldvalue"}}},"old":{"relationName":{"relationName":{"value":"newvalue"}}}}",
        ...
      },

So it is indeed called twice in the same request with the same activity model.

Unfortunatelly this is open since several months now - Why was the PR #1170 blocked? It was never clarified, what feature would be removed since tapActivity is called anyway from the log method?!

from laravel-activitylog.

renky avatar renky commented on September 26, 2024

Btw: I use a very crazy workaround for it now:

    public function tapActivity(Activity $activity, string $eventName): void
    {
        if ($activity->alreadyCalled) {
            unset ($activity->alreadyCalled);
            return;
        }
        $activity->alreadyCalled = true;

         // do what you want to do herer....
    }

maybe it helps somebody - sure, it will fail with a "alreadyCalled is no column in database" as soon as this problem is fixed, but I can live with that... finally it helps me removing this workarround as soon as it is not needed any more... every other workarround like detecting if the change was already there, would survive forever and never be removed....

from laravel-activitylog.

darkphoenixff4 avatar darkphoenixff4 commented on September 26, 2024

In my case, it's getting called four times, and creating three event records: updated, updated (Model) and changed (attribute). Is there a way to set it so that it only creates one event per update, rather than three?

from laravel-activitylog.

spatie-bot avatar spatie-bot commented on September 26, 2024

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

from laravel-activitylog.

horices avatar horices commented on September 26, 2024

How can I fix this problem? Does this actually qualify as a bug, and why hasn't this problem been fixed?

from laravel-activitylog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.