Skip to content

Commit d31cd74

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Accepted Community Pull Requests: - #27092: Adding failure callback to ui file uploader (by @bartoszkubicki) - #29885: Prevent flushing same tags several times (by @siimm) Fixed GitHub Issues: - #29557: [Issue] Adding failure callback to ui file uploader (reported by @m2-assistant[bot]) has been fixed in #27092 by @bartoszkubicki in 2.4-develop branch Related commits: 1. 3f7a163 2. c00b24d 3. f15cf5e 4. 939056f 5. 71bc1f4 6. 1e9001b 7. 82290c6 8. 9d99f32 9. 9cfff6e - #29890: [Issue] Prevent flushing same tags several times (reported by @m2-assistant[bot]) has been fixed in #29885 by @siimm in 2.4-develop branch Related commits: 1. 256cedd 2. f17148f 3. 47761ec 4. 2844fbf
2 parents c0088d3 + 5209417 commit d31cd74

File tree

4 files changed

+114
-24
lines changed

4 files changed

+114
-24
lines changed

app/code/Magento/Ui/view/base/web/js/form/element/file-uploader.js

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ define([
5454
this.$fileInput = fileInput;
5555

5656
_.extend(this.uploaderConfig, {
57-
dropZone: $(fileInput).closest(this.dropZone),
58-
change: this.onFilesChoosed.bind(this),
59-
drop: this.onFilesChoosed.bind(this),
60-
add: this.onBeforeFileUpload.bind(this),
61-
done: this.onFileUploaded.bind(this),
62-
start: this.onLoadingStart.bind(this),
63-
stop: this.onLoadingStop.bind(this)
57+
dropZone: $(fileInput).closest(this.dropZone),
58+
change: this.onFilesChoosed.bind(this),
59+
drop: this.onFilesChoosed.bind(this),
60+
add: this.onBeforeFileUpload.bind(this),
61+
fail: this.onFail.bind(this),
62+
done: this.onFileUploaded.bind(this),
63+
start: this.onLoadingStart.bind(this),
64+
stop: this.onLoadingStop.bind(this)
6465
});
6566

6667
$(fileInput).fileupload(this.uploaderConfig);
@@ -328,11 +329,12 @@ define([
328329
* May be used for implementation of additional validation rules,
329330
* e.g. total files and a total size rules.
330331
*
331-
* @param {Event} e - Event object.
332+
* @param {Event} event - Event object.
332333
* @param {Object} data - File data that will be uploaded.
333334
*/
334-
onFilesChoosed: function (e, data) {
335-
// no option exists in fileuploader for restricting upload chains to single files; this enforces that policy
335+
onFilesChoosed: function (event, data) {
336+
// no option exists in file uploader for restricting upload chains to single files
337+
// this enforces that policy
336338
if (!this.isMultipleFiles) {
337339
data.files.splice(1);
338340
}
@@ -341,13 +343,13 @@ define([
341343
/**
342344
* Handler which is invoked prior to the start of a file upload.
343345
*
344-
* @param {Event} e - Event object.
346+
* @param {Event} event - Event object.
345347
* @param {Object} data - File data that will be uploaded.
346348
*/
347-
onBeforeFileUpload: function (e, data) {
348-
var file = data.files[0],
349-
allowed = this.isFileAllowed(file),
350-
target = $(e.target);
349+
onBeforeFileUpload: function (event, data) {
350+
var file = data.files[0],
351+
allowed = this.isFileAllowed(file),
352+
target = $(event.target);
351353

352354
if (this.disabled()) {
353355
this.notifyError($t('The file upload field is disabled.'));
@@ -356,7 +358,7 @@ define([
356358
}
357359

358360
if (allowed.passed) {
359-
target.on('fileuploadsend', function (event, postData) {
361+
target.on('fileuploadsend', function (eventBound, postData) {
360362
postData.data.append('param_name', this.paramName);
361363
}.bind(data));
362364

@@ -386,16 +388,25 @@ define([
386388
});
387389
},
388390

391+
/**
392+
* @param {Event} event
393+
* @param {Object} data
394+
*/
395+
onFail: function (event, data) {
396+
console.error(data.jqXHR.responseText);
397+
console.error(data.jqXHR.status);
398+
},
399+
389400
/**
390401
* Handler of the file upload complete event.
391402
*
392-
* @param {Event} e
403+
* @param {Event} event
393404
* @param {Object} data
394405
*/
395-
onFileUploaded: function (e, data) {
406+
onFileUploaded: function (event, data) {
396407
var uploadedFilename = data.files[0].name,
397-
file = data.result,
398-
error = file.error;
408+
file = data.result,
409+
error = file.error;
399410

400411
error ?
401412
this.aggregateError(uploadedFilename, error) :
@@ -469,10 +480,10 @@ define([
469480
* Handler of the preview image load event.
470481
*
471482
* @param {Object} file - File associated with an image.
472-
* @param {Event} e
483+
* @param {Event} event
473484
*/
474-
onPreviewLoad: function (file, e) {
475-
var img = e.currentTarget;
485+
onPreviewLoad: function (file, event) {
486+
var img = event.currentTarget;
476487

477488
file.previewWidth = img.naturalWidth;
478489
file.previewHeight = img.naturalHeight;

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/element/file-uploader.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,27 @@ define([
358358
});
359359
});
360360

361+
describe('onFail handler', function () {
362+
it('it logs responseText and status', function () {
363+
var fakeEvent = {
364+
target: document.createElement('input')
365+
},
366+
data = {
367+
jqXHR: {
368+
responseText: 'Failed',
369+
status: '500'
370+
}
371+
};
372+
373+
spyOn(console, 'error');
374+
375+
component.onFail(fakeEvent, data);
376+
expect(console.error).toHaveBeenCalledWith(data.jqXHR.responseText);
377+
expect(console.error).toHaveBeenCalledWith(data.jqXHR.status);
378+
expect(console.error).toHaveBeenCalledTimes(2);
379+
});
380+
});
381+
361382
describe('aggregateError method', function () {
362383
it('should append onto aggregatedErrors array when called', function () {
363384
spyOn(component.aggregatedErrors, 'push');

lib/internal/Magento/Framework/Indexer/CacheContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ public function getIdentities()
7373
$identities[] = $cacheTag . '_' . $id;
7474
}
7575
}
76-
return array_merge($identities, array_unique($this->tags));
76+
return array_unique(array_merge($identities, array_unique($this->tags)));
7777
}
7878
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Framework\Indexer\Test\Unit;
10+
11+
use Magento\Framework\Indexer\CacheContext;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class CacheContextTest extends TestCase
15+
{
16+
/**
17+
* @var Batch
18+
*/
19+
private $object;
20+
21+
protected function setUp(): void
22+
{
23+
$this->object = new CacheContext();
24+
}
25+
26+
/**
27+
* @param array $tagsData
28+
* @param array $expected
29+
* @dataProvider getTagsDataProvider
30+
*/
31+
public function testUniqueTags($tagsData, $expected)
32+
{
33+
foreach ($tagsData as $tagSet) {
34+
foreach ($tagSet as $cacheTag => $ids) {
35+
$this->object->registerEntities($cacheTag, $ids);
36+
}
37+
}
38+
39+
$this->assertEquals($this->object->getIdentities(), $expected);
40+
}
41+
42+
/**
43+
* @return array
44+
*/
45+
public function getTagsDataProvider()
46+
{
47+
return [
48+
'same entities and ids' => [
49+
[['cat_p' => [1]], ['cat_p' => [1]]],
50+
['cat_p_1']
51+
],
52+
'same entities with overlapping ids' => [
53+
[['cat_p' => [1, 2, 3]], ['cat_p' => [3]]],
54+
['cat_p_1', 'cat_p_2', 'cat_p_3']
55+
]
56+
];
57+
}
58+
}

0 commit comments

Comments
 (0)