Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Resource < ApplicationRecord
as: :owner, class_name: "PrimaryAsset", dependent: :destroy
has_many :gallery_assets, -> { where(type: "GalleryAsset") },
as: :owner, class_name: "GalleryAsset", dependent: :destroy
has_many :rich_text_assets, -> { where(type: "RichTextAsset") },
as: :owner, class_name: "RichTextAsset", dependent: :destroy

# Default values
attribute :inactive, :boolean, default: false
Expand Down
2 changes: 2 additions & 0 deletions app/models/workshop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Workshop < ApplicationRecord
as: :owner, class_name: "PrimaryAsset", dependent: :destroy
has_many :gallery_assets, -> { where(type: "GalleryAsset") },
as: :owner, class_name: "GalleryAsset", dependent: :destroy
has_many :rich_text_assets, -> { where(type: "RichTextAsset") },
as: :owner, class_name: "RichTextAsset", dependent: :destroy

# Callbacks
before_save :set_time_frame
Expand Down
2 changes: 2 additions & 0 deletions app/models/workshop_variation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class WorkshopVariation < ApplicationRecord
as: :owner, class_name: "PrimaryAsset", dependent: :destroy
has_many :gallery_assets, -> { where(type: "GalleryAsset") },
as: :owner, class_name: "GalleryAsset", dependent: :destroy
has_many :rich_text_assets, -> { where(type: "RichTextAsset") },
as: :owner, class_name: "RichTextAsset", dependent: :destroy

validates :name, presence: true, uniqueness: { scope: :workshop_id, case_sensitive: false }

Expand Down
15 changes: 9 additions & 6 deletions lib/tasks/rich_text_urls_update.rake
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ namespace :rich_text_urls_update do
url = match[regex, 1] # extract the actual URL
aws_prefix = "https://s3.amazonaws.com/awbwassets/"
aws_prefix_2 = "http://s3.amazonaws.com/awbwassets/"
aws_prefix_3 = "//s3.amazonaws.com/awbwassets/"
dashboard_url = nil
key = nil
puts url
Expand All @@ -132,6 +133,8 @@ namespace :rich_text_urls_update do
key = url.sub(aws_prefix, "")
when ->(u) { u.start_with?(aws_prefix_2) }
key = url.sub(aws_prefix_2, "")
when ->(u) { u.start_with?(aws_prefix_3) }
key = url.sub(aws_prefix_3, "")
else
csv << [ model.name, record.id, column, url, nil, "skipped", "No Matching Url", nil ]
next
Expand All @@ -151,7 +154,7 @@ namespace :rich_text_urls_update do

begin
blob = ActiveStorage::Blob.find_by(aws_key: key)
image = record.images.build(type: "RichTextAsset")
asset = record.rich_text_assets.build
file_name = File.basename(key)
temp = nil

Expand Down Expand Up @@ -180,14 +183,14 @@ namespace :rich_text_urls_update do
)
blob.update!(aws_key: key)
end
image.file.attach(blob)
image.save!
asset.file.attach(blob)
asset.save!

new_url = url_for(image.file)
new_url = url_for(asset.file)

# Verify attachment and association
record.images.reload
unless record.images.include?(image) && image.file.attached?
record.rich_text_assets.reload
unless record.rich_text_assets.include?(asset) && asset.file.attached?
raise "Media not associated with record or file missing"
end
content = record.public_send(column)
Expand Down