diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 9c6ae182325c22ac5dd3d0c6ac4ecf375aec538a..532ad6302ebebdcd9fa2413213f9ba69128fb589 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -76,6 +76,10 @@ class Communication::Website < ApplicationRecord ", term: "%#{sanitize_sql_like(term)}%") } + def self.save_and_sync_websites! + find_each &:save_and_sync + end + def to_s "#{name}" end diff --git a/app/models/communication/website/with_connections.rb b/app/models/communication/website/with_connections.rb index c7b01d907a323c8f9e17f51d9c437080c51b47f5..29e44048317f7309c32b4f2e5551ac59086f9622 100644 --- a/app/models/communication/website/with_connections.rb +++ b/app/models/communication/website/with_connections.rb @@ -4,7 +4,7 @@ module Communication::Website::WithConnections included do has_many :connections - after_save :clean_connections! + before_save :clean_connections! end def clean_connections! diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index e920fb7c867e2af41471c49998ac08d123c05109..84542aa76c3b9d67d312ec6b08b85d90db1a3a9b 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -53,7 +53,6 @@ module WithGit websites_for_self.each do |website| website.touch next unless website.git_repository.valid? - dependencies = git_dependencies(website).to_a.flatten.uniq.compact dependencies.each do |object| Communication::Website::GitFile.sync website, object end @@ -65,6 +64,7 @@ module WithGit def destroy_from_git websites_for_self.each do |website| next unless website.git_repository.valid? + # FIXME dependencies = git_destroy_dependencies(website).to_a.flatten.uniq.compact dependencies.each do |object| Communication::Website::GitFile.sync website, object, destroy: true diff --git a/cron.json b/cron.json index 72d6dd6fd1eec1d1f7467c88ec588957bb912877..bfa2bc6421153fdbc67e53d2c51e44191b2fdebc 100644 --- a/cron.json +++ b/cron.json @@ -2,6 +2,9 @@ "jobs": [ { "command": "0 1 * * * rails auto:update_publications_from_hal" + }, + { + "command": "0 3 * * * rails auto:save_and_sync_websites" } ] } \ No newline at end of file diff --git a/lib/tasks/auto.rake b/lib/tasks/auto.rake index 7c47ebaaa12fc4eb079fb816c30ee163858ee133..2af83edd413a6606b88da8be7ed8347334287cc4 100644 --- a/lib/tasks/auto.rake +++ b/lib/tasks/auto.rake @@ -3,4 +3,9 @@ namespace :auto do task update_hal: :environment do Research::Hal.update_from_api! end + + desc 'Save all websites to update connections and clean Git repositories' + task save_and_sync_websites: :environment do + Communication::Website.save_and_sync_websites! + end end \ No newline at end of file