mirror of
https://0xacab.org/sutty/sutty
synced 2025-03-15 02:08:20 +00:00
Merge branch 'issue-13077' into 'rails'
Metodo Rename en SiteService para renombrar el sitio y actualizar los blobs | issue-13077 See merge request sutty/sutty!211
This commit is contained in:
commit
557c592f63
2 changed files with 21 additions and 11 deletions
|
@ -54,8 +54,7 @@ class Site < ApplicationRecord
|
||||||
before_create :clone_skel!
|
before_create :clone_skel!
|
||||||
# Elimina el directorio al destruir un sitio
|
# Elimina el directorio al destruir un sitio
|
||||||
before_destroy :remove_directories!
|
before_destroy :remove_directories!
|
||||||
# Cambiar el nombre del directorio
|
|
||||||
before_update :update_name!
|
|
||||||
before_save :add_private_key_if_missing!
|
before_save :add_private_key_if_missing!
|
||||||
# Guardar la configuración si hubo cambios
|
# Guardar la configuración si hubo cambios
|
||||||
after_save :sync_attributes_with_config!
|
after_save :sync_attributes_with_config!
|
||||||
|
@ -488,12 +487,6 @@ class Site < ApplicationRecord
|
||||||
FileUtils.rm_rf path
|
FileUtils.rm_rf path
|
||||||
end
|
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
|
# Sincroniza algunos atributos del sitio con su configuración y
|
||||||
# guarda los cambios
|
# guarda los cambios
|
||||||
|
|
|
@ -88,6 +88,25 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
||||||
result.present?
|
result.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rename(name)
|
||||||
|
return if name == site.name
|
||||||
|
|
||||||
|
moved = false
|
||||||
|
site.name = name
|
||||||
|
|
||||||
|
Site.transaction do
|
||||||
|
raise ActiveRecord::Rollback if File.exist?(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
|
||||||
|
rescue StandardError
|
||||||
|
FileUtils.mv(site.path, site.path_was) if moved
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Guarda los cambios de la configuración en el repositorio git
|
# Guarda los cambios de la configuración en el repositorio git
|
||||||
|
@ -222,9 +241,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def with_all_locales
|
||||||
|
|
||||||
def with_all_locales(&block)
|
|
||||||
site.locales.map do |locale|
|
site.locales.map do |locale|
|
||||||
next unless I18n.available_locales.include? locale
|
next unless I18n.available_locales.include? locale
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue