diff --git a/script/fix-active-storage-links.rb b/script/fix-active-storage-links.rb index 2fa66bbfd..d2cb856bf 100644 --- a/script/fix-active-storage-links.rb +++ b/script/fix-active-storage-links.rb @@ -11,13 +11,22 @@ ActionText::RichText.all.where("body LIKE '%/rails/active_storage/%'").find_each blobs = rich_text.embeds.map(&:blob) rich_text.body.send(:attachment_nodes).each do |node| - filename = node["filename"] + url = node["url"] + next unless url + url_encoded_filename = url.split("/").last + filename = URI.decode_www_form_component(url_encoded_filename) + + counter += 1 blob = blobs.select { |b| b.filename == filename } raise "Multiple blobs with filename #{filename}" if blob.size > 1 blob = blob.first - node["sgid"] = blob.attachable_sgid + if blob + node["sgid"] = blob.attachable_sgid + else + skipped += 1 + end end rich_text.save!