From 7191baff4abd7d6358769a5aebdd032e84c80aba Mon Sep 17 00:00:00 2001 From: f Date: Mon, 31 May 2021 13:23:40 -0300 Subject: [PATCH 1/3] =?UTF-8?q?reindexar=20despu=C3=A9s=20de=20mergear?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/sites_controller.rb | 2 +- app/services/site_service.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 20ce5bad..bdaa9011 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -107,7 +107,7 @@ class SitesController < ApplicationController def merge authorize site - if site.repository.merge(current_usuarie) + if SiteService.new(site: site, usuarie: current_usuarie).merge flash[:success] = I18n.t('sites.fetch.merge.success') else flash[:error] = I18n.t('sites.fetch.merge.error') diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 4f3905a5..389549c3 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -61,6 +61,18 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do commit_config(action: :tor) end + # Trae cambios desde la rama remota y reindexa los artículos. + # + # @return [Boolean] + def merge + result = site.repository.merge(usuarie) + + # TODO: Implementar callbacks + site.try(:index_posts!) if result + + result.present? + end + private # Guarda los cambios de la configuración en el repositorio git From 810c5e32da4157813b905c2320ee4c25ebe1f848 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 16 Jun 2021 09:11:13 -0300 Subject: [PATCH 2/3] convertir valores en arrays por retrocompatibilidad MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit esto permite indexar sitios antiguos y cargar artículos sin generar errores. --- app/models/metadata_array.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/metadata_array.rb b/app/models/metadata_array.rb index 9f5a84b6..96d3be3c 100644 --- a/app/models/metadata_array.rb +++ b/app/models/metadata_array.rb @@ -23,6 +23,14 @@ class MetadataArray < MetadataTemplate value.join(', ') end + # Obtiene el valor desde el documento, convirtiéndolo a Array si no lo + # era ya, por retrocompabilidad. + # + # @return [Array] + def document_value + [super].flatten(1) + end + alias indexable_values values private From 78a3cae077fae9bf5415e24db782db34fc5c7477 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 16 Jun 2021 09:13:40 -0300 Subject: [PATCH 3/3] solo indexar los valores actuales MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sin este cambio los artículos se indexaban por todas las categorías posibles! --- app/models/metadata_array.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/metadata_array.rb b/app/models/metadata_array.rb index 96d3be3c..0527ccb8 100644 --- a/app/models/metadata_array.rb +++ b/app/models/metadata_array.rb @@ -31,7 +31,7 @@ class MetadataArray < MetadataTemplate [super].flatten(1) end - alias indexable_values values + alias indexable_values value private