Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order activity timeline blank entries #1317

Merged

Conversation

wychoong
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Oct 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 12, 2024 1:29pm

@alecritson
Copy link
Collaborator

@wychoong Apparently this might not be needed anymore? is that the case?

@wychoong
Copy link
Contributor Author

wychoong commented Nov 1, 2023

@wychoong Apparently this might not be needed anymore? is that the case?

no, this is required for a complete fix

->logExcept(array_merge(['updated_at'], static::$logExcept ?? [])) 
// this to support exclude additional fields, 
// for example Order have additional activity log for `status` so this exclude avoid 2 entries
->logOnlyDirty() 
// without this, if a record is updated without changes, it is still logged, 
// can test with `$taggable->parent->touch()`

@alecritson
Copy link
Collaborator

@wychoong Apparently this might not be needed anymore? is that the case?

no, this is required for a complete fix

->logExcept(array_merge(['updated_at'], static::$logExcept ?? [])) 
// this to support exclude additional fields, 
// for example Order have additional activity log for `status` so this exclude avoid 2 entries
->logOnlyDirty() 
// without this, if a record is updated without changes, it is still logged, 
// can test with `$taggable->parent->touch()`

I think my confusion is why we need to exclude the status column. Are we performing a manual log of the change and spatie is also logging the status change automatically? If so would it make more sense to move the manual logging and let Spatie do it's thing?

@wychoong
Copy link
Contributor Author

wychoong commented Nov 2, 2023

Are we performing a manual log of the change and spatie is also logging the status change automatically?

yes, correct
https://github.com/lunarphp/lunar/blob/0.6/packages/core/src/Observers/OrderObserver.php

for Order model there is a trait and observer to log for changes

would it make more sense to move the manual logging and let Spatie do it's thing

Not really. I think the confusion probably is in lunar context, this logging is for activity, not auditing the record values.
So a generic create/update can be just "Created"/"Updated" entry in activity feed. While certain changes can be logged seperately.

for example Order status
image

without excluding the status in this case, it will have 2 entries
image

@@ -17,7 +17,8 @@ public function getActivitylogOptions(): LogOptions
return LogOptions::defaults()
->useLogName('lunar')
->logAll()
->dontSubmitEmptyLogs()
->logExcept(['updated_at']);
->logExcept(array_merge(['updated_at'], static::$logExcept ?? [])) /** @phpstan-ignore-line */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be better a method call, just thinking then it will likely appease the phpstan warning and be a bit more flexible in the long run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you foreseeing a setter in register? Since it’s a static I don’t think it matters.

How would you like to see the implementation? A method to return an array or setter and getter with property?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just a method to return an array should be enough, at least if it's on the trait it's easy to override.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the implementation to use a getter and setter approach so that:

  • lunar core can define default excluded field
  • user can add their own fields with
        Order::addActivitylogExcept('another_field');

this gives the flexibility to user add their own exclusion so that they can register their own logging and log feed renderer

@glennjacobs
Copy link
Contributor

@wychoong assuming this is still needed, could you target 0.7 branch please?

@glennjacobs glennjacobs added the bug Something isn't working label Dec 18, 2023
@glennjacobs glennjacobs added this to the v0.7 milestone Dec 18, 2023
@wychoong wychoong changed the base branch from 0.6 to 0.7 December 20, 2023 03:31
@wychoong
Copy link
Contributor Author

@wychoong assuming this is still needed, could you target 0.7 branch please?

done

@alecritson
Copy link
Collaborator

I realise this has been hanging around for a while but it looks like there are some PHPStan issues to sort

@alecritson alecritson merged commit faeb6db into lunarphp:0.7 Jan 12, 2024
13 checks passed
@wychoong
Copy link
Contributor Author

I realise this has been hanging around for a while but it looks like there are some PHPStan issues to sort

Thanks for sorting it out. Been busy lately

@wychoong wychoong deleted the fix-order-activity-timeline-blank-entries branch January 12, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

9 participants