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

[4.x]: Assets::getAllDescendantFolders returns the $parentFolder folder in result #12536

Closed
leevigraham opened this issue Jan 15, 2023 · 3 comments

Comments

@leevigraham
Copy link
Contributor

leevigraham commented Jan 15, 2023

What happened?

Description

Assets.php calls $this->getAllDescendantFolders($folder) on line 330 and passes in the $folder.

Screenshot 2023-01-15 at 9 32 45 pm

getAllDescendantFolders($folder) creates a query using the same path as the parentFolder

Screenshot 2023-01-15 at 9 35 27 pm

As a result the parent is returned in the descendants:

Screenshot 2023-01-15 at 9 41 13 pm

Expected behavior

$parentFolder should not be included in the returned results.

Actual behavior

$parentFolder is included in the returned results.

Craft CMS version

4.3.6.1

PHP version

8.1

Operating system and version

13.1 (22C65)

Database type and version

MySQL

@leevigraham
Copy link
Contributor Author

@brandonkelly If you're looking at this Folder 155401 has the same path (weird duplicate) which is why it's also returned in the results.

leevigraham added a commit to leevigraham/cms that referenced this issue Jan 15, 2023
Fixes craftcms#12536.

Adding an `_` to the `like` query ensures there's at least one character after the parent folder slash.

MYSQL `_` reference: https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html#operator_like
Postgres `_` reference: https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE
@brandonkelly
Copy link
Member

This seems to be currently working as intended, as everything within Craft that calls the method is expecting the parent folder to be included in the results.

It’s obviously a bad method name though. To make amends. I’ve just given it a new $withParent argument for the next Craft 3 and 4 releases, which is true by default, but if you pass false it will omit the parent folder from the results.

@brandonkelly
Copy link
Member

Craft 3.7.64 and 4.3.7 have been released with that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants