-
-
Notifications
You must be signed in to change notification settings - Fork 175
Description
Is your feature request related to a problem? Please describe.
I just switched over from PartKeepr and ran the import tool. It worked well, and all attachments are visible and available. However, all the imported parts have a null id_preview_attachment, so no preview image shows in the table (for a while, I thought the table didn't support images at all!). For my usage, the preview image is a critical feature, so for users like me it would be useful to automatically set the preview image on import (choosing between multiple attachments according to some heuristic - perhaps duplicating what PartKeepr did).
Describe the solution you'd like
On partkeepr import, automatically choose the preview image from the part's image attachments (if any).
Describe alternatives you've considered
None worth typing out. Happy with my workaround - I understand import is a relatively niche feature.
Additional context
For now, I've bulk-updated the preview images like this:
sudo docker exec --user=www-data -it partdb bin/console doctrine:query:sql "UPDATE parts SET id_preview_attachment = (SELECT a.id FROM attachments a WHERE a.element_id = parts.id AND a.class_name = 'Part' AND (a.internal_path LIKE '%.jpg' OR a.internal_path LIKE '%.jpeg' OR a.internal_path LIKE '%.png' OR a.internal_path LIKE '%.gif' OR a.internal_path LIKE '%.webp' OR a.external_path LIKE '%.jpg' OR a.external_path LIKE '%.jpeg' OR a.external_path LIKE '%.png' OR a.external_path LIKE '%.gif' OR a.external_path LIKE '%.webp' OR a.original_filename LIKE '%.jpg' OR a.original_filename LIKE '%.jpeg' OR a.original_filename LIKE '%.png' OR a.original_filename LIKE '%.gif' OR a.original_filename LIKE '%.webp') ORDER BY a.id ASC LIMIT 1) WHERE parts.tags LIKE '%partkeepr-imported%' AND parts.id_preview_attachment IS NULL"
The query will:
- Find all parts with 'partkeepr-imported' in their tags
- Only update parts where id_preview_attachment is currently NULL
- Set the preview to the first image attachment found (checking internal_path, external_path, and original_filename for common image extensions)
- Only look at attachments with class_name = 'Part'
After running this, you should see thumbnails appear for your PartKeepr-imported parts in the parts table. Keep in mind this query was written by a non-expert - it may be a bad idea, run at your own risk, but it worked for me.