# frozen_string_literal: true
module Decidim
# Looks for any occurence of "@deprecated_endpoint" in every database columns of type COLUMN_TYPES
# For each field containing @deprecated_endpoint:
# - Looks for the current ActiveStorage::Blob with the given filename
# - Find the blob's service_url
# - Replace the @deprecated_endpoint with the blob's service_url in text
# - Update the column
# Context:
# After S3 assets migration with rake task "bundle exec rake scaleway:storage:migrate_from_local", every linked documents URL were well updated.
# However every links added to text fields redirecting to an uploaded file were outdated and still redirects to the old S3 bucket
class RepairUrlInContentService
COLUMN_TYPES = [:string, :jsonb, :text].freeze
DEFAULT_LOGGER = Rails.logger
# TODO: must work with image src
# @param [String] deprecated_endpoint
def self.run(deprecated_endpoint)
new(deprecated_endpoint).run
end
# @param [String] deprecated_endpoint
def initialize(deprecated_endpoint, logger = nil)
@logger = logger || DEFAULT_LOGGER
@deprecated_endpoint = deprecated_endpoint
end
def run
@param [String] deprecated_endpoint
https://api.github.com/OpenSourcePolitics/decidim-app/blob/dd254bd654e0302552aa13df0ef5e7c3baf83464/app/services/decidim/repair_url_in_content_service.rb#L17