diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index 4fe68ac63e9b23ce04657ebf44da39c7fb7ada7b..a52bd59dc32d28eb9918c408fa3d4b010004e8a7 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -51,8 +51,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web def create @page.website = @website - if @page.save - @page.sync_with_git + if @page.save_and_sync redirect_to admin_communication_website_page_path(@page), notice: t('admin.successfully_created_html', model: @page.to_s) else breadcrumb @@ -61,8 +60,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web end def update - if @page.update(page_params) - @page.sync_with_git + if @page.update_and_sync(page_params) redirect_to admin_communication_website_page_path(@page), notice: t('admin.successfully_updated_html', model: @page.to_s) else breadcrumb @@ -72,7 +70,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web end def destroy - @page.destroy + @page.destroy_and_sync redirect_to admin_communication_website_pages_url(@website), notice: t('admin.successfully_destroyed_html', model: @page.to_s) end diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb index 309996e3fcda8205cedb60d85f5fad56c7aca6b2..e680a59b7824808682a72b21c95eac2285f85929 100644 --- a/app/controllers/admin/communication/website/posts_controller.rb +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -27,8 +27,7 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web def create @post.website = @website - if @post.save - @post.sync_with_git + if @post.save_and_sync redirect_to admin_communication_website_post_path(@post), notice: t('admin.successfully_created_html', model: @post.to_s) else breadcrumb @@ -37,8 +36,7 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web end def update - if @post.update(post_params) - @post.sync_with_git + if @post.update_and_sync(post_params) redirect_to admin_communication_website_post_path(@post), notice: t('admin.successfully_updated_html', model: @post.to_s) else breadcrumb @@ -48,7 +46,7 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web end def destroy - @post.destroy + @post.destroy_and_sync redirect_to admin_communication_website_posts_url, notice: t('admin.successfully_destroyed_html', model: @post.to_s) end diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index 6de6df853b214f1c7684227d9178f1082973b6df..1879c7ed610bd81d2467d27f28840bdfd762317f 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -8,34 +8,59 @@ module WithGit dependent: :destroy end - def sync_with_git - websites.each do |website| - identifiers.each do |identifier| - Communication::Website::GitFile.sync website, self, identifier - git_dependencies(identifier).each do |object| - Communication::Website::GitFile.sync website, object, identifier - end - end - website.git_repository.sync! + def git_path_static + '' + end + + # Overridden if websites relation exists + def websites + [website] + end + + def save_and_sync + if save + sync_with_git + true + else + false end end - handle_asynchronously :sync_with_git - def git_path_static - '' + def update_and_sync(params) + if update(params) + sync_with_git + true + else + false + end end - def git_dependencies(identifier) - [] + def destroy_and_sync + # TODO + destroy end + protected + # Overridden for multiple files generation def identifiers [:static] end - # Overridden if websites relation exists - def websites - [website] + def git_dependencies(identifier) + [] end + + def sync_with_git + websites.each do |website| + identifiers.each do |identifier| + Communication::Website::GitFile.sync website, self, identifier + git_dependencies(identifier).each do |object| + Communication::Website::GitFile.sync website, object, identifier + end + end + website.git_repository.sync! + end + end + handle_asynchronously :sync_with_git end diff --git a/docs/websites/export.md b/docs/websites/export.md index bf9c2e88ad885f27f866847649dc9017d4e0bdab..e7fdeb9fe4104af3295ab1d333e8f190957acff6 100644 --- a/docs/websites/export.md +++ b/docs/websites/export.md @@ -52,19 +52,20 @@ Après l'enregistrement d'un objet, il faut, pour chaque website, lancer une tâ Cette tâche est lancée par les controllers, et intégrée dans le partial `WithGit`. ``` def create - @page.website = @website - if @page.save - @page.sync_with_git + if @page.save_and_sync ... end end def update - if @page.update(page_params) - @page.sync_with_git + if @page.update_and_sync(page_params) ... end end + +def destroy + +end ``` TODO gérer la suppression correctement