Abilitare la funzione “pulisci caricamenti” suona spaventoso con il messaggio di avviso. Durante la conversione di un forum esistente a Discourse, questa impostazione verrà disabilitata. Non tutti gli script di importazione registreranno correttamente tutti i caricamenti nei post, quindi se la abiliti, potresti perdere molti allegati.
Con la seguente query puoi verificare se i caricamenti sono correttamente referenziati dai post:
select p.post_id, u.id as upload_id
from (select id post_id, (regexp_matches(cooked, 'data-download-href=[^\\s]+/default/([a-z0-9]+)', 'g'))[1] upload_sha from posts where raw like '%upload://%' order by created_at) as p
join uploads u on u.sha1 = p.upload_sha
where not exists(select * from upload_references r where r.upload_id = u.id)
Questa query non dovrebbe restituire alcuna riga se tutto è corretto. Se utilizzi questa query nel plugin Data Explorer, collegherà anche in modo ordinato i post che hanno allegati non referenziati.
Se la query sopra restituisce risultati, puoi correggere i riferimenti mancanti ai caricamenti con la seguente query:
insert into upload_references(upload_id, target_type, target_id, created_at, updated_at)
select u.id, 'Post', p.post_id, u.created_at, u.updated_at
from (select id post_id, (regexp_matches(cooked, 'data-download-href=[^\\s]+/default/([a-z0-9]+)', 'g'))[1] upload_sha from posts where raw like '%upload://%' order by created_at) as p
join uploads u on u.sha1 = p.upload_sha
on conflict do nothing;
Avrai bisogno di accesso diretto al database per apportare la modifica correttiva.