From ddff6c71d7843cf2eaa1e12003930eb65d27ef20 Mon Sep 17 00:00:00 2001 From: jazzari Date: Thu, 5 Oct 2023 17:13:47 -0300 Subject: [PATCH 01/10] =?UTF-8?q?fix:=20corregida=20identaci=C3=B3n=20#130?= =?UTF-8?q?77?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/site.rb | 9 +-------- app/services/site_service.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index a8c5e376..89dd5ca8 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -54,8 +54,7 @@ class Site < ApplicationRecord before_create :clone_skel! # Elimina el directorio al destruir un sitio before_destroy :remove_directories! - # Cambiar el nombre del directorio - before_update :update_name! + before_save :add_private_key_if_missing! # Guardar la configuración si hubo cambios after_save :sync_attributes_with_config! @@ -485,12 +484,6 @@ class Site < ApplicationRecord FileUtils.rm_rf path end - def update_name! - return unless name_changed? - - FileUtils.mv path_was, path - reload_jekyll! - end # Sincroniza algunos atributos del sitio con su configuración y # guarda los cambios diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 7022244c..3a803972 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -87,6 +87,15 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do result.present? end + def rename(name) + Site.transaction do + site.name = name + FileUtils.mv site.path_was, site.path(name: name) + ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) + site.save + end + end + private # Guarda los cambios de la configuración en el repositorio git From 5fbb276f719a80839abc9afcba2c14c9a2a63905 Mon Sep 17 00:00:00 2001 From: jazzari Date: Thu, 5 Oct 2023 17:19:41 -0300 Subject: [PATCH 02/10] fix: arreglada indentacion #13077 --- app/services/site_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 3a803972..5522245a 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -95,7 +95,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do site.save end end - + private # Guarda los cambios de la configuración en el repositorio git From 1675e32fe84556afdc45bea9837a1773623c1f4b Mon Sep 17 00:00:00 2001 From: jazzari Date: Mon, 9 Oct 2023 15:50:25 -0300 Subject: [PATCH 03/10] =?UTF-8?q?fix:=20agregado=20bloque=20de=20excepci?= =?UTF-8?q?=C3=B3n=20en=20metodo=20rename=20#13077?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/site_service.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 5522245a..90a4a339 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -90,9 +90,13 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do def rename(name) Site.transaction do site.name = name - FileUtils.mv site.path_was, site.path(name: name) + raise ActiveRecord::Rollback if File.exists?(name) + FileUtils.mv site.path_was, site.path unless File.exists?(name) ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) site.save + rescue StandardError + FileUtils.mv site.path, site.path_was if File.exists?(name) + raise end end From 7e0ab59ffa5d2b53239f18cee6324c14bd57918e Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 17 Oct 2023 14:36:34 -0300 Subject: [PATCH 04/10] fix: arreglado rescue que devuelve el repositorio a su estado original #13077 --- app/services/site_service.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 90a4a339..532d48ac 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -88,14 +88,16 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do end def rename(name) + moved = false Site.transaction do + raise ActiveRecord::Rollback if site.path site.name = name - raise ActiveRecord::Rollback if File.exists?(name) - FileUtils.mv site.path_was, site.path unless File.exists?(name) + FileUtils.mv (site.path_was, site.path) unless File.exists?(name) ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) site.save + moved = true rescue StandardError - FileUtils.mv site.path, site.path_was if File.exists?(name) + FileUtils.mv (site.path, site.path_was) if moved raise end end From 63884a89150e55df0af122654ff27f9dfbeeaea3 Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 14 Nov 2023 16:05:19 +0100 Subject: [PATCH 05/10] merge WIP --- app/services/site_service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 532d48ac..d7112321 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -88,6 +88,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do end def rename(name) + moved = false moved = false Site.transaction do raise ActiveRecord::Rollback if site.path @@ -96,6 +97,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) site.save moved = true + moved = true rescue StandardError FileUtils.mv (site.path, site.path_was) if moved raise From 0071ab7328fb6c329315f29cb4787bded6b2aa75 Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 14 Nov 2023 16:12:15 +0100 Subject: [PATCH 06/10] fix: modificado metodo rename en site_service.rb #13077 --- app/services/site_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index d7112321..994b16d8 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -89,7 +89,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do def rename(name) moved = false - moved = false + Site.transaction do raise ActiveRecord::Rollback if site.path site.name = name @@ -97,7 +97,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) site.save moved = true - moved = true + rescue StandardError FileUtils.mv (site.path, site.path_was) if moved raise From 76e2fd8f6072babcb05facc9d5741e3283b9c6c7 Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 21 Nov 2023 13:59:02 +0100 Subject: [PATCH 07/10] fix: corregida condicion en metodo Rename en site_service.rb #13077 --- app/services/site_service.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 994b16d8..8cb012a0 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -89,15 +89,13 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do def rename(name) moved = false + site.name = name Site.transaction do - raise ActiveRecord::Rollback if site.path - site.name = name - FileUtils.mv (site.path_was, site.path) unless File.exists?(name) + raise ActiveRecord::Rollback if (site.path == site.path_was) ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) site.save moved = true - rescue StandardError FileUtils.mv (site.path, site.path_was) if moved raise From b658ecc3748910eafc137c09c74c20ac6f83e84d Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 21 Nov 2023 16:45:20 +0100 Subject: [PATCH 08/10] fix: corregido metodo rename #13077 --- app/services/site_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 8cb012a0..f7cfd668 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -88,11 +88,13 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do end def rename(name) + return if name == site.name moved = false site.name = name Site.transaction do - raise ActiveRecord::Rollback if (site.path == site.path_was) + raise ActiveRecord::Rollback if site.path + FileUtils.mv (site.path_was, site.path) ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) site.save moved = true From 49106874b0f06a55b14487e6d7be9b34f346cc16 Mon Sep 17 00:00:00 2001 From: jazzari Date: Wed, 22 Nov 2023 14:17:57 +0100 Subject: [PATCH 09/10] fix: corregido metodo Rename en site_service.rb #13077 --- app/services/site_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index f7cfd668..51146b13 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -93,7 +93,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do site.name = name Site.transaction do - raise ActiveRecord::Rollback if site.path + raise ActiveRecord::Rollback if File.exists?(site.path) FileUtils.mv (site.path_was, site.path) ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) site.save From a1daa759ecaaa0f1dd27b1ed4caa35aff972d0eb Mon Sep 17 00:00:00 2001 From: jazzari Date: Wed, 22 Nov 2023 17:12:15 +0100 Subject: [PATCH 10/10] fix: movido boolean en metodo Rename #13077 --- app/services/site_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 51146b13..7e1bef6b 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -95,9 +95,9 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do Site.transaction do raise ActiveRecord::Rollback if File.exists?(site.path) FileUtils.mv (site.path_was, site.path) + moved = true ActiveStorage::Blob.where(service_name: site.name_was).update_all(service_name: site.name) site.save - moved = true rescue StandardError FileUtils.mv (site.path, site.path_was) if moved raise