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

Correct handling of auto save #66

Merged
merged 1 commit into from
Mar 14, 2024
Merged

Correct handling of auto save #66

merged 1 commit into from
Mar 14, 2024

Conversation

rliebi
Copy link
Contributor

@rliebi rliebi commented Mar 14, 2024

Fixes a bug in #62, #61

@rliebi rliebi requested a review from limenet March 14, 2024 09:41
@rliebi rliebi self-assigned this Mar 14, 2024
@limenet
Copy link
Member

limenet commented Mar 14, 2024

Thanks for the bugfix, you're correct. Unfortunately, this change is not backwards compatible (compared to 4.0.0). If I'm not mistaken, the method should read as follows:

    private function shouldHandle(AssetEvent|DataObjectEvent|DocumentEvent $event): bool
    {
        if (!self::$isEnabled) {
            return false;
        }

        $isAutoSave = $event->hasArgument('isAutoSave') && $event->getArgument('isAutoSave') === true;

        if ($event instanceof AssetEvent && (!$isAutoSave || $this->configurationRepository->shouldHandleAssetAutoSave())) {
            return true;
        }

        if ($event instanceof DataObjectEvent && (!$isAutoSave || $this->configurationRepository->shouldHandleDataObjectAutoSave())) {
            return true;
        }

        if ($event instanceof DocumentEvent && (!$isAutoSave || $this->configurationRepository->shouldHandleDocumentAutoSave())) {
            return true;
        }

        return false;
    }

What do you think?

@rliebi
Copy link
Contributor Author

rliebi commented Mar 14, 2024

Your solution does the same thing as what I proposed but mine is slightly more readable, because of the early exit when there is no autosave.
We already assessed, that the event is one of AssetEvent,DataObjectEvent or DocumentEvent so imho there is no need for a check inside the if statements when we could exit early.

@limenet limenet merged commit 9ed777a into main Mar 14, 2024
10 checks passed
@limenet
Copy link
Member

limenet commented Mar 14, 2024

Sorry, my bad.

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.

None yet

2 participants