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

feat: [Entity] add changedValues() function #9095

Conversation

christianberkman
Copy link
Contributor

@christianberkman christianberkman commented Aug 1, 2024

Description
Suggesting to introduce a function Entity::changedValues() that returns an array of original and changed values of new or changed attributes only. I use this for my project logging capability where I desire to only log changed values.

I have implemented this function in my own EntityBase class and have been using it in my live project. Code is not yet optimized and tested but can do if given the go ahead.

Would this be a welcome function to implement in the Entity class?

Sample output

name =>
   original => 'Peter'
   changed => 'John'
date_birth =>
   original => null,
   changed => '2024-08-01'

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@neznaika0
Copy link
Contributor

You should study the framework in more detail. This has already been implemented.
Set $onlyChanged = true you will only get the changed properties.

public function toRawArray(bool $onlyChanged = false, bool $recursive = false): array

public function toArray(bool $onlyChanged = false, bool $cast = true, bool $recursive = false): array

@christianberkman
Copy link
Contributor Author

I did come across that, however that would only give the actual (updated) value and would not include the original value? If the use case is too little, I understand.

@kenjis
Copy link
Member

kenjis commented Aug 20, 2024

@christianberkman Thank you for trying to improve CI4!
This seems to be useful for logging/auditing, but it seems the need is too little to implement it in the framework.

@neznaika0
Copy link
Contributor

neznaika0 commented Aug 20, 2024

A good solution is to extend the Entity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants