-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[Bug]: Every time you save a version is created, even though no changes have been made to the data. #16997
Comments
We added a workaround by extending the object save method to dispatch an event (in a try catch block) before the parent save method is called. Then a a listener to check if anything is changed and throw a "skip version save exception" and just skip save at all |
Right now, this is by design. We need to think about if and how we can change that. |
Yes please. It makes no sense to create a new version when nothing changed. |
It gets even worse when https://pimcore.com/docs/platform/Pimcore/Tools_and_Features/Versioning#settings when "Store version history for X steps" is enabled.. |
@Fahl-Design would you share your event listener solution or is it tied to specific fields and classes? |
@Cruiser13 it's a mix of both. Some fields can just be checked with a look into "getDirtyFields" others (relation fields) musst be compared against the previos version. Since we use a lot of CLI and workflows. It was a pain and is to specific to share. in general:
trait TriggerPreSaveEventOnSaveTrait
{
public function save(array $parameters = []): static
{
try {
$eventData = new DataObjectEvent($this);
Pimcore::getEventDispatcher()->dispatch($eventData, ObjectSaveEvent::OBJECT_PRE_SAVE);
} catch (\OegBundle\Exception\ElementVersionSavedSkippedException $e) {
// valid case: skipped save to prevent useless versions
// hacky trick - disable output message in other wrapped processes
$requestStack = Pimcore::getContainer()?->get('request_stack');
if ($requestStack instanceof RequestStack) {
if (RouteHelper::staticIsDataObjectWorkflowTransitionContext($requestStack)) {
// needed - otherwise publishing via workflow not working correct!
return parent::save($parameters);
}
if (RouteHelper::staticIsDataObjectGridBatchContext($requestStack)) {
// batch in grid avoid any error output
return $this;
}
}
if (PHP_SAPI !== 'cli') {
// do not run in cli / worker etc, sanity check will fail
throw new Pimcore\Model\Element\ValidationException('No Change was made - save was skipped');
}
// return $this;
} catch (ElementVersionSavedException $e) {
// valid case: we saved as "version"
return $this;
}
return parent::save($parameters);
}
} (this may change in pimcore 11.2 or 11.3, but we stuck at 11.1 because every time a new "minor" is out, the list of remarkable crazy issues gets longer with issues like: (random pick) #16965 ☮️ |
Pimcore version
11.1.5 - 11.2.3
Steps to reproduce
https://demo.pimcore.com/admin/login/deeplink?object_260_object
Actual Behavior
Each time a new version is created with the same data set
Expected Behavior
No new version should be created if no data has changed
The text was updated successfully, but these errors were encountered: