From fd80b2d825a097f269310c27b83ecd934a4acfc8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Wed, 29 Dec 2021 12:21:46 +0100
Subject: [PATCH] check github valid, descendent has websites & programs path
 child

---
 app/models/concerns/with_github_files.rb | 14 ++++++++------
 app/models/education/program.rb          |  5 ++++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/app/models/concerns/with_github_files.rb b/app/models/concerns/with_github_files.rb
index 79caadb30..3232d8ae3 100644
--- a/app/models/concerns/with_github_files.rb
+++ b/app/models/concerns/with_github_files.rb
@@ -63,15 +63,17 @@ module WithGithubFiles
   end
 
   def publish_github_files_with_descendents
-    list_of_websites.each do |website|
-      website_github = Github.with_website website
+    list_of_websites.each do |current_website|
+      website_github = Github.with_website current_website
+      next unless website_github.valid?
       target_github_files = []
       github_manifest.each do |manifest_item|
-        github_file = github_files.where(website: website, manifest_identifier: manifest_item[:identifier]).first_or_create
+        github_file = github_files.where(website: current_website, manifest_identifier: manifest_item[:identifier]).first_or_create
         target_github_files << github_file
         github_file.add_to_batch(website_github)
         descendents.each do |descendent|
-          descendent_github_file = descendent.github_files.where(website: website, manifest_identifier: manifest_item[:identifier]).first_or_create
+          next unless descendent.list_of_websites.include? current_website
+          descendent_github_file = descendent.github_files.where(website: current_website, manifest_identifier: manifest_item[:identifier]).first_or_create
           target_github_files << descendent_github_file
           descendent_github_file.add_to_batch(website_github)
         end
@@ -85,9 +87,9 @@ module WithGithubFiles
   end
 
   def unpublish_github_files
-    list_of_websites.each do |website|
+    list_of_websites.each do |current_website|
       github_manifest.each do |manifest_item|
-        github_files.find_by(website: website, manifest_identifier: manifest_item[:identifier])&.unpublish
+        github_files.find_by(website: current_website, manifest_identifier: manifest_item[:identifier])&.unpublish
       end
     end
   end
diff --git a/app/models/education/program.rb b/app/models/education/program.rb
index f6bddcdf3..55ed4b6ad 100644
--- a/app/models/education/program.rb
+++ b/app/models/education/program.rb
@@ -114,7 +114,10 @@ class Education::Program < ApplicationRecord
   end
 
   def update_children_paths
-    children.each(&:save)
+    children.each do |child|
+      child.update_column :path, child.generated_path
+      child.update_children_paths
+    end
   end
 
   def list_of_other_programs
-- 
GitLab