Skip to content

Commit 03ae0e1

Browse files
committed
Added fallback in case BINARY is not supported and fixed copyright message
1 parent ec582ba commit 03ae0e1

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

app/code/Magento/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/Directory.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -10,25 +10,43 @@
1010
use Magento\Framework\Api\Filter;
1111
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
1212
use Magento\Framework\Data\Collection\AbstractDb;
13+
use Psr\Log\LoggerInterface;
1314

1415
class Directory implements CustomFilterInterface
1516
{
17+
/**
18+
* @var LoggerInterface
19+
*/
20+
private $logger;
21+
22+
public function __construct(LoggerInterface $logger)
23+
{
24+
$this->logger = $logger;
25+
}
26+
1627
/**
1728
* @inheritDoc
1829
*/
1930
public function apply(Filter $filter, AbstractDb $collection): bool
2031
{
2132
$value = $filter->getValue() !== null ? str_replace('%', '', $filter->getValue()) : '';
2233

23-
/**
24-
* Use BINARY comparison for case-sensitive path filtering.
25-
* Without BINARY, MySQL's default case-insensitive comparison would match
26-
* directories like "Testing" and "testing" as the same, leading to incorrect
27-
* file visibility across directories with different case variations.
28-
* The regex '^{path}/[^\/]*$' ensures we only match files directly in the
29-
* specified directory, not in subdirectories.
30-
*/
31-
$collection->getSelect()->where('BINARY path REGEXP ? ', '^' . $value . '/[^\/]*$');
34+
try {
35+
/**
36+
* Use BINARY comparison for case-sensitive path filtering.
37+
* Without BINARY, MySQL's default case-insensitive comparison would match
38+
* directories like "Testing" and "testing" as the same, leading to incorrect
39+
* file visibility across directories with different case variations.
40+
* The regex '^{path}/[^\/]*$' ensures we only match files directly in the
41+
* specified directory, not in subdirectories.
42+
*/
43+
$collection->getSelect()->where('BINARY path REGEXP ? ', '^' . $value . '/[^\/]*$');
44+
} catch (\Exception $e) {
45+
// Log the error for debugging but continue with case-insensitive fallback
46+
// Note: This fallback means directory filtering will not be case-sensitive
47+
$this->logger->error('MediaGallery Directory Filter: BINARY REGEXP not supported, using case-insensitive fallback: ' . $e->getMessage());
48+
$collection->getSelect()->where('path REGEXP ? ', '^' . $value . '/[^\/]*$');
49+
}
3250

3351
return true;
3452
}

app/code/Magento/MediaGalleryUi/Test/Integration/Model/SearchCriteria/CollectionProcessor/FilterProcessor/DirectoryIntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

app/code/Magento/MediaGalleryUi/Test/Unit/Model/SearchCriteria/CollectionProcessor/FilterProcessor/DirectoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

0 commit comments

Comments
 (0)