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

Set Data.php to support dirty detection on simple data fields #16293

Open
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

IronSean
Copy link
Contributor

This PR enables the dirty detection for simple data fields in the DataObject. Use cases would be for any custom event listener or processing on a DataObject Pre-Save event might want to know which fields have been modified to reduce duplicate work.

I however am not positive of the downstream affects this would have or why this was disabled by default. Would this be something that needs other fixes to make sense, or could be controlled with configuration instead?

Changes in this pull request

Resolves #5689

Additional info

@CLAassistant
Copy link

CLAassistant commented Nov 23, 2023

CLA assistant check
All committers have signed the CLA.

Copy link

Review Checklist

  • Target branch (11.1 for bug fixes, others 11.x)
  • Tests (if it's testable code, there should be a test for it - get help)
  • Docs (every functionality needs to be documented, see here)
  • Migration incl. install.sql (e.g. if the database schema changes, ...)
  • Upgrade notes (deprecations, important information, migration hints, ...)
  • Label
  • Milestone

Copy link

sonarcloud bot commented Nov 23, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@brusch
Copy link
Member

brusch commented Feb 12, 2024

To me it seems quite safe to change that.
The only thing I've seen is that we might need some additional work here, as it assumes that only relational data-types are support dirty detection.

if ($fd instanceof LazyLoadingSupportInterface && $fd->getLazyLoading()) {

I'll create a PR for that, as I'd classify this as a bug anyway 😉

@brusch
Copy link
Member

brusch commented Feb 12, 2024

Just one more thing ... if we set the default to true, we might remove the existing method overrides for supportsDirtyDetection().
Also we need to consider more sophisticated data-types that (might) not be compatible with supportsDirtyDetection(), such as field collections, object bricks, block, calculated value, encrypted field and some more - for them I'd implement supportsDirtyDetection() for them and return false.

Just for reference: this is the PR about the topic before: #16598

@brusch
Copy link
Member

brusch commented Feb 12, 2024

Additionally it seems that also the code generation for setters/getters in \Pimcore\Model\DataObject\ClassDefinition\Data need to be optimized, because there's quite some code which wouldn't be necessary for simple data-types in case they support dirty detection, e.g. the following code block:

if ($this->supportsDirtyDetection()) {
$code .= "\t" . '$hideUnpublished = \\Pimcore\\Model\\DataObject\\Concrete::getHideUnpublished();' . "\n";
$code .= "\t" . '\\Pimcore\\Model\\DataObject\\Concrete::setHideUnpublished(false);' . "\n";
if ($class instanceof DataObject\ClassDefinition && $class->getAllowInherit()) {
$code .= "\t" . '$currentData = \\Pimcore\\Model\\DataObject\\Service::useInheritedValues(false, function() {' . "\n";
$code .= "\t\t" . 'return $this->get' . ucfirst($this->getName()) . '();' . "\n";
$code .= "\t" . '});' . "\n";
} else {
$code .= "\t" . '$currentData = $this->get' . ucfirst($this->getName()) . '();' . "\n";
}
$code .= "\t" . '\\Pimcore\\Model\\DataObject\\Concrete::setHideUnpublished($hideUnpublished);' . "\n";

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

Successfully merging this pull request may close these issues.

[DataObjects] Check possibility to extend dirty detection for additional (simple) datatypes
5 participants