diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 5770a717..20256d68 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -17,7 +17,9 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do post.slug.value = p[:slug] if p[:slug].present? end - commit(action: :created, add: update_related_posts) if post.save + update_related_posts + + commit(action: :created, add: files) if post.save update_site_license! @@ -35,7 +37,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do # Los artículos anónimos siempre son borradores params[:draft] = true - commit(action: :created, add: [post.path.absolute]) if post.update(anon_post_params) + commit(action: :created, add: files) if post.update(anon_post_params) post end @@ -48,9 +50,11 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do rm = [] rm << post.path.value_was if post.path.changed? + update_related_posts + # Es importante que el artículo se guarde primero y luego los # relacionados. - commit(action: :updated, add: update_related_posts, rm: rm) + commit(action: :updated, add: files, rm: rm) update_site_license! end @@ -97,6 +101,15 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do private + # Una lista de archivos a modificar + # + # @return [Set] + def files + @files ||= Set.new.tap do |f| + f << post.path.absolute + end + end + def commit(action:, add: [], rm: []) site.repository.commit(add: add, rm: rm, @@ -147,8 +160,10 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do end posts.map do |p| - p.path.absolute if p.save(validate: false) - end.compact << post.path.absolute + next unless p.save(validate: false) + + files << p.path.absolute + end end # Si les usuaries modifican o crean una licencia, considerarla