Skip to content

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

Open
lwekuiper wants to merge 2 commits intostatamic:6.xfrom
lwekuiper:feat/asset-move-unique
Open

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

Conversation

@lwekuiper
Copy link
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
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
Contributor Author

Thanks for the feedback! I've updated the PR to use a dedicated moveUnique() method instead of adding a parameter to move(), so there's no breaking change. rename() now delegates to moveUnique() when $unique = true.

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