Skip to content

[6.x] Add Asset::moveUnique() method#14236

Merged
jasonvarga merged 2 commits intostatamic:6.xfrom
lwekuiper:feat/asset-move-unique
Mar 16, 2026
Merged

[6.x] Add Asset::moveUnique() method#14236
jasonvarga merged 2 commits intostatamic:6.xfrom
lwekuiper:feat/asset-move-unique

Conversation

@lwekuiper
Copy link
Copy Markdown
Contributor

@lwekuiper lwekuiper commented Mar 12, 2026

Asset::rename($filename, $unique = false) supports automatic unique filename generation via ensureUniqueFilename(), but there is no equivalent for Asset::move(). When moving an asset to a folder where a filename collision exists, developers must implement their own uniqueness logic.

This PR adds a dedicated moveUnique() method as a non-breaking addition, and updates rename() to delegate to it when $unique = true.

Changes

  • Asset::moveUnique($folder, $filename) — new method that calls ensureUniqueFilename() before delegating to move().
  • Asset::rename() — updated to delegate to moveUnique() when $unique = true, instead of handling uniqueness directly.
  • Asset::move() — signature unchanged, no breaking change.
  • Tests — three new test cases covering moveUnique (conflict, no conflict, and default move behavior).

Add $unique parameter to move() for parity with rename(). When true,
ensureUniqueFilename() generates a collision-free name in the target
folder. Simplify rename() to delegate uniqueness logic to move().
Copy link
Copy Markdown
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a new argument is a breaking change.

Either target master so this will be in v7 (but there is no planned release for a while).

Or, make this change in a non-breaking way. Maybe you could create a moveUnique method that checks uniqueness then calls move. It could be marked as deprecated with the intention of making the breaking change in v7.

…r on move()

Replace the breaking $unique parameter on move() with a dedicated
moveUnique() method. Update rename() to delegate to moveUnique() when
unique filenames are needed.
@lwekuiper lwekuiper changed the title [6.x] Add $unique parameter to Asset::move() [6.x] Add Asset::moveUnique() method Mar 13, 2026
@lwekuiper
Copy link
Copy Markdown
Contributor Author

lwekuiper commented Mar 13, 2026

Thanks for the feedback! Didn't know that adding a new argument is a breaking change. PR is reworked.

@jasonvarga jasonvarga merged commit 113798b into statamic:6.x Mar 16, 2026
18 checks passed
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.

2 participants