Commit d1d7de3d5053ba591a2945f6294c488045d716ae

Authored by Karpikau Andrei
1 parent 56f2b9d6

check update template and exist content elemen

... ... @@ -91,8 +91,38 @@ module Kanjai
91 91 source: item[:source],
92 92 elements: item[:elements],
93 93 field_options: item[:field_options]
94   -
95 94 )
  95 +
  96 + new_markers_general = item[:field_options].select{|item| item[:attributes]['repeat'] == 'false' }.collect{|item| item[:name] }
  97 + new_markers_repeat = item[:field_options].select{|item| item[:attributes]['repeat'] == 'true' }.collect{|item| item[:name] }
  98 +
  99 + Kanjai::PageContent.where(type_content: item[:code]).each do |page_content|
  100 + langs = page_content.page_content_markers.pluck(:lang).uniq
  101 + row_indexes = page_content.page_content_markers.pluck(:row_item).uniq
  102 + langs.each do |lang|
  103 + row_indexes.each do |index|
  104 +
  105 + work_new_markers = index.to_i == 0 ? new_markers_general : new_markers_repeat
  106 + #delete not exist more markers
  107 + page_content.page_content_markers.where(lang: lang, row_item: index).where.not(marker: work_new_markers).delete_all
  108 +
  109 + exist_markers = page_content.page_content_markers.where(lang: lang, row_item: index).pluck(:marker)
  110 + item[:field_options].select{|item| item[:attributes]['repeat'] == (index.to_i == 0 ? 'false' : 'true') }.each do |marker|
  111 + unless exist_markers.include?(marker[:name])
  112 + page_content.page_content_markers.create(
  113 + marker: marker[:name],
  114 + row_item: index,
  115 + marker_name: marker[:itemName],
  116 + lang: lang
  117 + )
  118 + end
  119 + end
  120 + end
  121 + end
  122 +
  123 + exist_markers = page_content.page_content_markers.pluck(:marker)
  124 + p exist_markers
  125 + end
96 126 end
97 127
98 128 content = parser.without_subparts
... ...
1 1 module Kanjai
2   - VERSION = "0.0.178"
  2 + VERSION = "0.0.179"
3 3 end
... ...