2010-09-22 22:59:30 +00:00
|
|
|
require 'zip/zipfilesystem'
|
|
|
|
|
|
|
|
module Locomotive
|
|
|
|
module Import
|
|
|
|
class Job
|
|
|
|
|
|
|
|
def initialize(theme_file, site = nil, options = {})
|
|
|
|
raise "Theme zipfile not found" unless File.exists?(theme_file)
|
|
|
|
|
|
|
|
@theme_file = theme_file
|
|
|
|
@site = site
|
|
|
|
@options = Hash.new(true).merge(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
|
|
|
self.unzip!
|
|
|
|
|
|
|
|
raise "No database.yml found in the theme zipfile" if @database.nil?
|
|
|
|
|
2010-09-23 23:00:13 +00:00
|
|
|
context = {
|
|
|
|
:database => @database,
|
|
|
|
:site => @site,
|
|
|
|
:theme_path => @theme_path
|
|
|
|
}
|
2010-09-22 22:59:30 +00:00
|
|
|
|
2010-09-23 23:00:13 +00:00
|
|
|
Locomotive::Import::Site.process(context)
|
|
|
|
|
|
|
|
Locomotive::Import::ContentTypes.process(context)
|
|
|
|
|
|
|
|
# Locomotive::Import::Assets.process(context)
|
|
|
|
|
|
|
|
# Locomotive::Import::Snippets.process(context)
|
|
|
|
|
|
|
|
Locomotive::Import::Pages.process(context)
|
2010-09-22 22:59:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def unzip!
|
|
|
|
Zip::ZipFile.open(@theme_file) do |zipfile|
|
|
|
|
destination_path = File.join(Rails.root, 'tmp', 'themes', @site.id.to_s)
|
|
|
|
|
|
|
|
zipfile.each do |entry|
|
|
|
|
next if entry.name =~ /__MACOSX/
|
|
|
|
|
|
|
|
if entry.name =~ /database.yml$/
|
|
|
|
|
|
|
|
@database = YAML.load(zipfile.read(entry.name))
|
|
|
|
@theme_path= File.join(destination_path, entry.name.gsub('database.yml', ''))
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2010-09-23 23:00:13 +00:00
|
|
|
FileUtils.mkdir_p(File.dirname(File.join(destination_path, entry.name)))
|
|
|
|
|
|
|
|
zipfile.extract(entry, File.join(destination_path, entry.name))
|
2010-09-22 22:59:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|