[6.x] Fix $isNew detection after Asset::move()#14140
Merged
jasonvarga merged 1 commit intostatamic:6.xfrom Mar 5, 2026
Merged
Conversation
When Asset::move() changes the path, the subsequent save() incorrectly
detected the asset as new because the container lookup at the new path
found nothing. This caused AssetCreating/AssetCreated events to fire
for what is actually a move, which could abort the save if any
AssetCreating listener returns false.
Use getOriginal('path') to detect path changes — if the path changed,
it's a move, not a creation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
Asset::move()is called (e.g. by a listener onAssetUploaded), the subsequentsave()incorrectly evaluates$isNew = truewith the Eloquent driver. This causesAssetCreating/AssetCreatedevents to fire for what is actually a move — a semantic bug that can abort the save entirely if anyAssetCreatinglistener returnsfalse.Example: An
AssetUploadedlistener that organizes uploads into date-based folders:This triggers
AssetCreatingon the internalsave(), which can abort the move if any other listener returnsfalse— even though the asset already exists and is simply being relocated.Root cause: The
$isNewcheck creates a fresh lookup at the current (post-move) path:With the Eloquent driver,
exists()checks the DB which still has the old path, returningfalseand making$isNew = true.Solution
Use
getOriginal('path')to detect whether the path has changed since the lastsyncOriginal()call. If it has, the asset was moved — not created.This works because
syncOriginal()is called after everysave(), storing the path at that point. Aftermove()changes the path but before the nextsave(),getOriginal('path')returns the pre-move path — signaling a move.Test
Added a test that verifies after
move():AssetSaving/AssetSavedare dispatchedAssetCreating/AssetCreatedare not dispatched