diff --git a/app/models/communication/website/github_file.rb b/app/models/communication/website/github_file.rb index 17aa444517ca08198c3f580f910f9a72d2867926..79febf595ed86735d83a021a52e15bb776f675f4 100644 --- a/app/models/communication/website/github_file.rb +++ b/app/models/communication/website/github_file.rb @@ -78,7 +78,17 @@ class Communication::Website::GithubFile < ApplicationRecord def remove_from_github return unless github.valid? - github.remove(github_path, github_remove_commit_message) + github.remove github_path, github_remove_commit_message + remove_media_from_github + end + + def remove_media_from_github + return unless about.respond_to?(:active_storage_blobs) + about.active_storage_blobs.each { |blob| remove_blob_from_github(blob) } + end + + def remove_blob_from_github(blob) + github.remove github_blob_path(blob), github_blob_remove_commit_message end def github @@ -96,7 +106,7 @@ class Communication::Website::GithubFile < ApplicationRecord def github_blob_params(blob) blob.analyze unless blob.analyzed? { - path: "_data/media/#{blob.id[0..1]}/#{blob.id}.yml", + path: github_blob_path(blob), data: ApplicationController.render( template: 'active_storage/blobs/jekyll', layout: false, @@ -105,6 +115,10 @@ class Communication::Website::GithubFile < ApplicationRecord } end + def github_blob_path(blob) + "_data/media/#{blob.id[0..1]}/#{blob.id}.yml" + end + def github_commit_message "[#{about.class.name.demodulize}] Save #{about.to_s}" end @@ -116,4 +130,8 @@ class Communication::Website::GithubFile < ApplicationRecord def github_remove_commit_message "[#{about.class.name.demodulize}] Remove #{about.to_s}" end + + def github_blob_remove_commit_message(blob) + "[Medium] Remove ##{blob.id}" + end end diff --git a/app/models/communication/website/with_publishable_objects.rb b/app/models/communication/website/with_publishable_objects.rb index 78b8d7f2bbdb6789243d21907538db2a9f905d28..d2c019325fba29f37893bd2c4262af28c01540c7 100644 --- a/app/models/communication/website/with_publishable_objects.rb +++ b/app/models/communication/website/with_publishable_objects.rb @@ -2,32 +2,11 @@ module Communication::Website::WithPublishableObjects extend ActiveSupport::Concern included do - def publish_about_object # TODO: Handle Research::Journal then use the commented version. # about.force_publish! unless about.nil? about.force_publish! if about.is_a?(Education::School) end - def publish_blob(blob) - return unless github.valid? - blob.analyze unless blob.analyzed? - github_path = "_data/media/#{blob.id[0..1]}/#{blob.id}.yml" - github_commit_message = "[Medium] Save ##{blob.id}" - data = ApplicationController.render( - template: 'active_storage/blobs/jekyll', - layout: false, - assigns: { blob: blob } - ) - github.publish(path: github_path, commit: github_commit_message, data: data) - end - handle_asynchronously :publish_blob, queue: 'default' - - def remove_blob(blob) - return unless github.valid? - github_path = "_data/media/#{blob.id[0..1]}/#{blob.id}.yml" - github_commit_message = "[Medium] Remove ##{blob.id}" - github.remove(github_path, github_commit_message) - end end end