Class: LatoCms::ExportSitemapCsvJob

Inherits:
Lato::ApplicationJob
  • Object
show all
Defined in:
app/jobs/lato_cms/export_sitemap_csv_job.rb

Overview

Exports every page across every locale of a spaces group as a CSV sitemap. Runs as a Lato::Operation so large sites don't block the request.

Instance Method Summary collapse

Instance Method Details

#perform(params = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/lato_cms/export_sitemap_csv_job.rb', line 7

def perform(params = {})
  params = params.with_indifferent_access
  pages = LatoCms::Page.for_lato_spaces_group(params[:lato_spaces_group_id]).order(:locale, :permalink)

  file_path = Rails.root.join('tmp', "sitemap_#{SecureRandom.hex(8)}.csv")
  generate_csv(file_path, pages)

  return file_path unless operation?

  save_operation_output_file(file_path)
  save_operation_output_message(I18n.t('lato_cms.sitemap_export_message', count: pages.count))
ensure
  File.delete(file_path) if file_path && File.exist?(file_path)
end