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

[5.x]: temp folders not deleting #16388

Closed
matthewstick opened this issue Jan 4, 2025 · 14 comments
Closed

[5.x]: temp folders not deleting #16388

matthewstick opened this issue Jan 4, 2025 · 14 comments
Labels

Comments

@matthewstick
Copy link

matthewstick commented Jan 4, 2025

What happened?

Description

I have several dozen temp folders that appear in the control panel -> Assets. They have names like temp_aqjohrdcimamnobrewqkvplvakvlngvyaefh.

These folders are empty of assets. Nothing is inside.

I want to delete them.

  • I run the asset index cleanup, listing empty folders, but it does not detect them to delete them.
  • These do not appear in the local file systems, so I can't delete there either.
  • I run the garbage cleanup - php craft gc - and it says they are deleted, but they do not delete.

I do not know how to get rid of them in a batch way. If I try manually to check it and click delete, it works one by one. if i check more than one, the button to delete gets disabled. So I have to do them all manually.

Ideally this should not happen in the first place. Thoughts? Thanks!

Craft CMS version

5.5.8

PHP version

8.2.0

Operating system and version

Linux 5.15.49-linuxkit

Database type and version

MySQL 8.0.26

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

Plugins
CKEditor 4.4.0
Cloner 3.0.1
Feed Me 6.6.1
Field Manager 4.0.3

@brandonkelly
Copy link
Member

brandonkelly commented Jan 4, 2025

These are probably being created because you have an Assets field that is outputting {slug} in the upload path, which is being replaced with the element’s temporary slug, if an asset is added before a slug has been added.

I just added a utils/delete-empty-volume-folders CLI command for Craft 4.4 and 5.6, which you can execute to clean them up. (f3708d2)

brandonkelly added a commit that referenced this issue Jan 4, 2025
@brandonkelly
Copy link
Member

Craft 4.14.0 and 5.6.0 are out with that new utils/delete-empty-volume-folders command 🎉

@matthewstick
Copy link
Author

@brandonkelly unfortunately, I ran this command on the altest craft - utils/delete-empty-volume-folders

It deleted about 650 folders that had images and videos. and left ONLY the empty volume folders.

In effect, it completely destroyed the site and left just the thing I was trying to delete

PHP version | 8.2.20
Linux 5.4.245-200.el7.x86_64
MariaDB 10.5.16
Imagick 3.7.0 (ImageMagick 6.9.13-11)
Craft Pro 5.6.0.2
Yii version | 2.0.51
Twig version | v3.15.0

brandonkelly added a commit that referenced this issue Jan 23, 2025
@brandonkelly
Copy link
Member

Oh no, I’m so sorry about that. I didn’t think to test with folders that were empty in terms of not having any assets directly in them, but had subfolders. It looks like that was the issue here, and Craft 5.6.1 is out now with a fix.

@matthewstick
Copy link
Author

Hi! That did NOT wipe everything this time. Thank you.

There are still 35 empty folders that begin with "temp_" like "temp_aqjohrdcimamnobrewqkvplvakvlngvyaefh" in the root of the assets volume.

Maybe its because the same long name also exists in projects/temp_aqjohrdcimamnobrewqkvplvakvlngvyaefh, for example? And inside projects/temp_aqjohrdcimamnobrewqkvplvakvlngvyaefh, for example, there are images? So the root folder has like "phantom folders" that connect to projects? The root temp_ folders are empty, wheras the same name temp_ folder in projects/ is not

I'm using projects/{slug} in the path. I can't say for sure if they were created before slug was created. But you'd think after a slug is saved that temp_### folders would "automatically rename" to the right projects/{slug} folder.

And it's still ongoing. So even if there is a project already saed, that has a slug, uploaded images are still getting put in the temp_ folders instead of projects/{slug}. It's becoming an issue because there are 800+ projects and they want to update them all ◡̈

Any ideas?

@brandonkelly
Copy link
Member

There are still 35 empty folders that begin with "temp_" like "temp_aqjohrdcimamnobrewqkvplvakvlngvyaefh" in the root of the assets volume.

Guessing those contain soft-deleted assets, so they are ignored by the command.

But you'd think after a slug is saved that temp_### folders would "automatically rename" to the right projects/{slug} folder.

Yeah, at least maybe Assets fields can be updated to automatically delete the folder after it’s done moving assets around, if the folder is empty.

And it's still ongoing. So even if there is a project already saed, that has a slug, uploaded images are still getting put in the temp_ folders instead of projects/{slug}.

Do you have autosaveDrafts disabled in config/general.php by chance? If so that would exacerbate this issue because newly-created entries wouldn’t actually have a slug saved to them before assets are uploaded, until you press Save.

Otherwise, if you can tell me specific steps to reproduce, where you are seeing assets uploaded to a temp folder despite the entry definitely already having a slug, we can look into that further.

@matthewstick
Copy link
Author

Hi @brandonkelly Thanks! I'll zip the files and email support. I think it's how the {slug} variable works in nested entry types/matrix fields. It's like permanently stuck in temp_

@brandonkelly
Copy link
Member

brandonkelly commented Jan 23, 2025

Assets fields within Matrix fields will need to use {owner.slug} instead of {slug}.

@matthewstick
Copy link
Author

matthewstick commented Jan 23, 2025

Ok, I'm just going off this tip note:
Tip: The path can contain variables like {slug} or {author.username}. Maybe that tip could link to other variables?

I did change the image and video paths in those fields all to "projects/{owner.slug}" instead of "projects/{slug}" and it still has the issue though....

I see some notes here.. but this is older and I have the same issue and don't see a resolution here
https://craftcms.stackexchange.com/questions/1332/having-problems-with-dynamic-asset-folders-and-owner-slug

@brandonkelly
Copy link
Member

Just testing this on my end and it’s working as expected.

I created a Matrix field, with a selected entry type called “Image” that has an Assets field with the following settings:

  • Restrict assets to a single location: ✅
  • Asset Location: projects/{owner.slug}

I then created a new entry in a section that has the Matrix field, entered the title “Testing”, ensured the Slug field was filled in (“testing”), created an Image nested entry in the Matrix field, and uploaded an image to it. As expected, the image was immediately uploaded to a projects/testing subfolder, and no other subfolders exist in projects/.

@matthewstick
Copy link
Author

matthewstick commented Jan 23, 2025 via email

@matthewstick
Copy link
Author

@brandonkelly - ok it did have to do with nesting. We figured it out. Here's the note for others to see:

From craft email support:
Right, it is because of the nesting -- as I say, owner.slug will go one level up, so if slugs aren't set on those entries it'll use the temp_ version.

What I think you need is projects/{{ object.getRootOwner().slug }} as the Default Upload Location. That will get the slug of the project, rather than the Matrix entries. I just tested that with your files, and it was placed in the correct folder (screenshot attached.)

@brandonkelly
Copy link
Member

Ah, you must have 2+ layers of nesting then?

@matthewstick
Copy link
Author

Yes that's right. If you could forward this to your documentation team - that would be lovely! Not sure where this was written out. Thanks!

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

No branches or pull requests

2 participants