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

BUG Ensure that file replacement checks for clashes with existing files #370

Merged

Conversation

tractorcow
Copy link
Contributor

@tractorcow tractorcow commented Jan 17, 2017

Fixes #369

Requires silverstripe/silverstripe-framework#6527

Note: Updated so that existing files are detected to avoid duplication, as per discussion with @sminnee

if (oldExt !== newExt) {
// name field to autofill if extension has changed
// If server has requested a filename change, modify it here
if (json.Name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can have the undesired effect of replacing the Name value an edited Name field with the original value? It's not the best user experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about I conditionally send it back from the server; No json.Name means no change needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed it so that the current Name is always posted back, so that json.Name will reflect the current value, unless explicitly changed.


// If extension is the same, attempt to re-use existing name
if (File::get_file_extension($tmpFile['name']) === $file->getExtension()) {
$tmpFile['name'] = $file->Name;
Copy link
Contributor

Choose a reason for hiding this comment

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

rather than using the Name saved in the database, I wonder if the component could send the API the current value of the field on the form?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@tractorcow
Copy link
Contributor Author

Updated based on feedback.

Note that framework PR silverstripe/silverstripe-framework#6527 is now required for this fix.

And I wait for 1 second
And the "Name" field should contain "file1.jpg"
When I press the "Save" button
And I wait for 2 seconds
Copy link
Member

Choose a reason for hiding this comment

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

Not too happy about manual waits here, but it's just following a bad precedent. We need to work out if a fetch() is in progress through Behat feature context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's annoying I know, but we need a better wait-until-ready solution for behat.

@codecov-io
Copy link

codecov-io commented Jan 31, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@4d797b4).


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d797b4...6f852fb. Read the comment docs.

@tractorcow
Copy link
Contributor Author

I can't reproduce the composer issue locally; Downgrading to 1.3.1 to see if it's due to the recent composer release.

@tractorcow
Copy link
Contributor Author

I've raised composer/composer#6115 to investigate the possible regression in composer 1.3.2.

I suspect that the issue might be due to asset-admin dependency in the PR branch and the one cached by packagist differing.

I've raised #378, and suspect that force-merging this (with a broken build) and then updating packagist may resolve the issue. It can't help to experiment. :)

@tractorcow
Copy link
Contributor Author

I've force-merged #378 and updated packagist to determine if the issue lies between travis and packagist (which could explain why I couldn't resolve the issue locally).

@tractorcow
Copy link
Contributor Author

For some reason that issue resolved itself, yet without leaving behind any explanation as to why it was broken. :)

@tractorcow
Copy link
Contributor Author

Only failure now is the behat failure, i.e. a real one. However this already exists prior to this PR. (siiigh).

@chillu chillu merged commit 29f0f94 into silverstripe:master Feb 1, 2017
@chillu chillu deleted the pulls/4.0/fix-replace-setname branch February 1, 2017 03:58
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

4 participants