Skip to content

Commit

Permalink
Merge branch 'refresh' into refresh-search
Browse files Browse the repository at this point in the history
  • Loading branch information
benkt2 authored Jul 10, 2020
2 parents a97f51b + fe016af commit 252869f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ API_ISO3_ATTRIBUTE=XXXXXXXXXX
API_COUNTRY_NAME_ATTRIBUTE=XXXXXXXXXX
API_JRC_COUNTRY_AREA_ATTRIBUTE=XXXXXXXXXX
API_JRC_TERR_AREA_ATTRIBUTE=XXXXXXXXXX

76 changes: 70 additions & 6 deletions config/initializers/comfortable_mexican_sofa.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'cms_tags/date_not_null'
require 'cms_tags/text_custom'
# encoding: utf-8
Expand Down Expand Up @@ -37,10 +39,10 @@
# Sofa allows you to setup entire site from files. Database is updated with each
# request (if necessary). Please note that database entries are destroyed if there's
# no corresponding file. Fixtures are disabled by default.
#config.enable_fixtures = false
# config.enable_fixtures = false

# Path where fixtures can be located.
#config.fixtures_path = File.expand_path('cms', Rails.root)
# config.fixtures_path = File.expand_path('cms', Rails.root)

# Importing fixtures into Database
# To load fixtures into the database just run this rake task:
Expand Down Expand Up @@ -96,14 +98,13 @@

# Create thumbnails of all images uploaded to the CMS
# - dropdownImage dimensions were calculated at thier largest in the desktop breakpoint
#config.upload_file_options[:styles] = { dropdownImage: '853x853>'}

# config.upload_file_options[:styles] = { dropdownImage: '853x853>'}
end

# Default credentials for ComfortableMexicanSofa::AccessControl::AdminAuthentication
# YOU REALLY WANT TO CHANGE THIS BEFORE PUTTING YOUR SITE LIVE
ComfortableMexicanSofa::AccessControl::AdminAuthentication.username = ENV["COMFY_ADMIN_USERNAME"]
ComfortableMexicanSofa::AccessControl::AdminAuthentication.password = ENV["COMFY_ADMIN_PASSWORD"]
ComfortableMexicanSofa::AccessControl::AdminAuthentication.username = ENV['COMFY_ADMIN_USERNAME']
ComfortableMexicanSofa::AccessControl::AdminAuthentication.password = ENV['COMFY_ADMIN_PASSWORD']

# Uncomment this module and `config.admin_auth` above to use custom admin authentication
# module ComfyAdminAuthentication
Expand All @@ -125,3 +126,66 @@
# return true
# end
# end

module ComfortableMexicanSofa
# ------------------------------------------------------------- #
# ADD ADDITIONAL MODELS HERE THAT SHOULD BE INCLUDED IN EXPORTS #
# ------------------------------------------------------------- #
#
# THE EXPORT OF MODEL DATA IS IN A SIMPLE JSON FORMAT.
#
# PLEASE TAKE THIS INTO CONSIDERATION IF YOU INTEND TO RESTORE MORE COMPLEX
# MODEL DATA. YOU MAY NEED TO ENHANCE THIS EXTENDED FUNCTIONALITY IF SO.
# ------------------------------------------------------------- #
module ExtraModels
COMFY_CMS_INCLUDED_EXPORT_MODELS = %w[CallToAction].freeze
end

module Seeds
class Importer
old_import = instance_method(:import!)

# RUN THE EXISTING IMPORT, THEN RUN THE EXTENDED IMPORT BEHAVIOUR.
define_method(:import!) do |*args|
ActiveRecord::Base.transaction do
old_import.bind(self).call(*args)

ExtraModels::COMFY_CMS_INCLUDED_EXPORT_MODELS.each do |model_name|
path = ::File.join(ComfortableMexicanSofa.config.seeds_path, from, model_name.underscore + '.json')
raise Error, "File for import: '#{path}' is not found" unless ::File.exist?(path)

model_name.constantize.destroy_all
::File.open(path, 'r') do |file|
::JSON.load(file).each do |record|
model_name.constantize.create!(record)
end
end
message = "[CMS SEEDS] Imported Model \t #{model_name}"
ComfortableMexicanSofa.logger.info(message)
end
end
end
end

class Exporter
old_export = instance_method(:export!)

# RUN THE EXISTING EXPORT, THEN RUN THE EXTENDED EXPORT BEHAVIOUR.
define_method(:export!) do |*args|
ActiveRecord::Base.transaction do
old_export.bind(self).call(*args)

ExtraModels::COMFY_CMS_INCLUDED_EXPORT_MODELS.each do |model_name|
path = ::File.join(ComfortableMexicanSofa.config.seeds_path, from, model_name.underscore + '.json')
::FileUtils.rm_rf(path)
::File.open(path, 'w') do |file|
file.write(model_name.constantize.all.to_json)
end
message = "[CMS SEEDS] Exported Model \t #{model_name}"
ComfortableMexicanSofa.logger.info(message)
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion db
Submodule db updated 205 files

0 comments on commit 252869f

Please sign in to comment.