278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
# File 'app/models/website.rb', line 278
def export
tmp_dir = Website.make_tmp_dir
file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
sections_path = Pathname.new(File.join(tmp_dir, 'sections'))
FileUtils.mkdir_p(sections_path) unless sections_path.exist?
articles_path = Pathname.new(File.join(tmp_dir, 'articles'))
FileUtils.mkdir_p(articles_path) unless articles_path.exist?
documented_contents_path = Pathname.new(File.join(tmp_dir, 'documented contents'))
FileUtils.mkdir_p(documented_contents_path) unless documented_contents_path.exist?
excerpts_path = Pathname.new(File.join(tmp_dir, 'excerpts'))
FileUtils.mkdir_p(excerpts_path) unless excerpts_path.exist?
image_assets_path = Pathname.new(File.join(tmp_dir, 'images'))
FileUtils.mkdir_p(image_assets_path) unless image_assets_path.exist?
file_assets_path = Pathname.new(File.join(tmp_dir, 'files'))
FileUtils.mkdir_p(file_assets_path) unless file_assets_path.exist?
sections.where('parent_id is null').each do |website_section|
save_section_layout_to_file(sections_path, website_section)
end
contents = sections.collect(&:contents).flatten.uniq
contents.each do |content|
File.open(File.join(articles_path, "#{content.internal_identifier}.html"), 'wb+') { |f| f.puts(content.body_html) }
unless content.excerpt_html.blank?
File.open(File.join(excerpts_path, "#{content.internal_identifier}.html"), 'wb+') { |f| f.puts(content.excerpt_html) }
end
end
online_document_sections.each do |online_documented_section|
extension = online_documented_section.use_markdown == true ? 'md' : 'html'
File.open(File.join(documented_contents_path, "#{online_documented_section.internal_identifier}.#{extension}"), 'wb+') { |f| f.puts(online_documented_section.documented_item_published_content_html(active_publication)) }
end
self.files.where("directory like '%/sites/#{self.iid}/images%'").all.each do |image_asset|
contents = file_support.get_contents(File.join(file_support.root, image_asset.directory, image_asset.name))
FileUtils.mkdir_p(File.join(image_assets_path, image_asset.directory))
File.open(File.join(image_assets_path, image_asset.directory, image_asset.name), 'wb+') { |f| f.puts(contents) }
end
self.files.where("directory like '%/#{Rails.application.config.erp_tech_svcs.file_assets_location}/sites/#{self.iid}%'").all.each do |file_asset|
contents = file_support.get_contents(File.join(file_support.root, file_asset.directory, file_asset.name))
FileUtils.mkdir_p(File.join(file_assets_path, file_asset.directory))
File.open(File.join(file_assets_path, file_asset.directory, file_asset.name), 'wb+') { |f| f.puts(contents) }
end
files = []
Dir.glob("#{tmp_dir.to_s}/**/*").each do |entry|
next if entry =~ /^\./
path = entry
entry = entry.gsub(Regexp.new(tmp_dir.to_s), '')
entry = entry.gsub(Regexp.new(/^\//), '')
files << {:path => path, :name => entry}
end
File.open(tmp_dir + 'setup.yml', 'wb+') { |f| f.puts(export_setup.to_yaml) }
(tmp_dir + "#{name}.zip").tap do |file_name|
file_name.unlink if file_name.exist?
Zip::ZipFile.open(file_name.to_s, Zip::ZipFile::CREATE) do |zip|
files.each { |file| zip.add(file[:name], file[:path]) if File.exists?(file[:path]) }
zip.add('setup.yml', tmp_dir + 'setup.yml')
end
end
end
|