Skip to content

Add a command to delete orphaned media#2033

Open
BentiGorlich wants to merge 7 commits intomainfrom
new/delete-orphaned-media
Open

Add a command to delete orphaned media#2033
BentiGorlich wants to merge 7 commits intomainfrom
new/delete-orphaned-media

Conversation

@BentiGorlich
Copy link
Member

No description provided.

@BentiGorlich BentiGorlich self-assigned this Feb 24, 2026
@BentiGorlich BentiGorlich added the enhancement New feature or request label Feb 24, 2026
```

Options:
- `--ignored-paths=IGNORED-PATHS`: A comma seperated list of paths to be ignored in this process. If the path starts with one of the supplied string it will be skipped. e.g. "/cache" [default: ""]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- `--ignored-paths=IGNORED-PATHS`: A comma seperated list of paths to be ignored in this process. If the path starts with one of the supplied string it will be skipped. e.g. "/cache" [default: ""]
- `--ignored-paths=IGNORED-PATHS`: A comma seperated list of paths to be ignored in this process. If the path starts with one of the supplied strings it will be skipped. e.g. "/cache" [default: ""]

if ($deleteEmptyDirectories) {
$contents = $this->publicUploadsFilesystem->listContents($path);
$length = 0;
foreach ($contents as $content) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this loop can be canceled after the first item or replaced with whatever "check for empty" functions the type of $contents supports

foreach ($contents as $content) {
++$length;
}
if (0 === $length) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

will this work for nested empty directories?

Copy link
Member Author

Choose a reason for hiding this comment

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

No it will probably not. Also for s3 servers it would be a lot faster if I'd remove the default delimiter on the list operation, which would probably lead to no directories being listed anymore (I think)

return [$path, end($parts)];
}

private function shouldNodeBeIgnored(array $ignoredPaths, StorageAttributes $content): bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

this might be extracted to a util class and then covered by a unit test

[['/cache'], 'ca/fe/asdoihsd.png', false],
[['/cache'], 'cache/ca/fe/asdoihsd.png', true],
[['cache'], 'cache/ca/fe/asdoihsd.png', true],
[['/cache'], 'cache/ca/fe/asdoihsd.png', true],
Copy link
Collaborator

Choose a reason for hiding this comment

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

this case is a duplicate; did you mean cache/?

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants