Skip to content
Snippets Groups Projects
Commit df53cce9 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

destroy without dependencies

parent b012638e
No related branches found
Tags v3.1.5
No related merge requests found
......@@ -25,8 +25,11 @@ class Communication::Website::GitFile < ApplicationRecord
belongs_to :website, class_name: 'Communication::Website'
belongs_to :about, polymorphic: true
def self.sync(website, object, identifier)
attr_accessor :will_be_destroyed
def self.sync(website, object, identifier, destroy: false)
git_file = where(website: website, about: object, identifier: identifier).first_or_create
git_file.will_be_destroyed = destroy
website.git_repository.add_git_file git_file
end
......@@ -43,7 +46,7 @@ class Communication::Website::GitFile < ApplicationRecord
end
def should_destroy?
path.nil?
will_be_destroyed || path.nil?
end
def path
......
......@@ -72,7 +72,7 @@ class Communication::Website::Page < ApplicationRecord
scope :recent, -> { order(updated_at: :desc).limit(5) }
def git_path_static
"content/pages/#{path}/_index.html".gsub(/\/+/, '/')
"content/pages/#{path}/_index.html".gsub(/\/+/, '/') if published
end
def git_dependencies_static
......
......@@ -68,7 +68,7 @@ class Communication::Website::Post < ApplicationRecord
end
def git_path_static
"content/posts/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html"
"content/posts/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at
end
def git_dependencies_static
......
......@@ -32,8 +32,18 @@ module WithGit
end
def destroy_and_sync
# TODO
destroy_from_git
destroy
true
end
def destroy_from_git
websites_with_fallback.each do |website|
identifiers.each do |identifier|
Communication::Website::GitFile.sync website, self, identifier, destroy: true
end
website.git_repository.sync!
end
end
def sync_with_git
......
......@@ -56,11 +56,7 @@ class Research::Journal::Article < ApplicationRecord
end
def git_path_static
if published_at
"content/articles/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html"
else
nil
end
"content/articles/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at
end
def git_dependencies_static
......
......@@ -47,11 +47,7 @@ class Research::Journal::Volume < ApplicationRecord
end
def git_path_static
if published_at
"content/volumes/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html"
else
nil
end
"content/volumes/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at
end
def git_dependencies_static
......
......@@ -6,7 +6,10 @@ class Git::Repository
end
def add_git_file(git_file)
@commit_message = "[#{ git_file.about.class.name }] Save #{ git_file.about }" if git_files.empty?
if git_files.empty?
action = git_file.should_destroy? ? "Destroy" : "Save"
@commit_message = "[#{ git_file.about.class.name }] #{ action } #{ git_file.about }"
end
git_files << git_file
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment