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

Fix for race condition while uploading multiple files with uploadimage plugin #1216

Merged
merged 6 commits into from
Nov 23, 2017

Conversation

mlewand
Copy link
Contributor

@mlewand mlewand commented Nov 23, 2017

What is the purpose of this pull request?

Bug fix

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

This issue is more of a workaround, as the problem is actually on a CKFinder side, but we can't quickly fix it there, so we'll patch client side first.

Now, the problem was that CKFinder had a problem handling multiple files with the same name loaded at once, so we'll generate unique file name for each one. It's a bit dirty, and optimistic, but should do the trick for now.

Manaul Tests

To be honest I had no good idea how to make a good manual test here. To make it reliable I have set a CKFinder 3 instance on my dev workstation, and added configuration to config.js:

By adding:

	config.uploadUrl = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&responseType=json';

And adding 'uploadimage' to the plugin list.

Closes #1213.

@mlewand mlewand requested a review from Comandeer November 23, 2017 13:58
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

Test is failing.

@@ -68,6 +68,8 @@

this.responseData = {};
};

// sinon.spy( CKEDITOR.fileTools.fileLoader.prototype, 'upload' );
Copy link
Member

Choose a reason for hiding this comment

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

This line could probably be deleted safely.

wait();
},

'test uploads generate unique names (#1213)': function() {
Copy link
Member

Choose a reason for hiding this comment

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

Test is always failing:

TypeError: Attempted to wrap create which is already wrapped

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooops, TBH don't know how I missed that.

// Returns an unique image file name.
function getUniqueImageFileName( type ) {
var date = new Date(),
dateParts = [ date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds() ];
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we use simply timestamp here, returned from Date.now()/Date.prototype.getTime()?

Copy link
Contributor Author

@mlewand mlewand Nov 23, 2017

Choose a reason for hiding this comment

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

We want to give it some human readability, at the same time not making the name too long. So we'd like to stick to YYYYmmddhhmmss schema.

@Comandeer Comandeer merged commit 8016dd5 into major Nov 23, 2017
@Comandeer Comandeer deleted the t/1213 branch November 23, 2017 17:13
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.

Race condition while uploading images to CKFinder using uploadimage plugin
2 participants