Skip to content

Commit

Permalink
Fixed #65 (clear cache should not remove all files in public).
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Nov 4, 2013
1 parent afecab2 commit a9b365e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
22 changes: 9 additions & 13 deletions app/models/site.rb
Expand Up @@ -463,7 +463,7 @@ def iformats_updated!
end
end

def clear_cache(clear_zafu = true)
def clear_cache(should_clear_zafu = true)
paths = ["#{SITES_ROOT}#{self.cache_path}"]
aliases = Site.all(:conditions => {:master_id => self.id})
aliases.each do |site|
Expand All @@ -484,21 +484,17 @@ def clear_cache(clear_zafu = true)
end
end

# Clear zafu
if clear_zafu
paths = ["#{SITES_ROOT}#{self.zafu_path}"]
aliases.each do |site|
paths << "#{SITES_ROOT}#{site.cache_path}"
end
paths.each do |path|
if File.exist?(path)
FileUtils.rmtree(path)
end
end
end
clear_zafu if should_clear_zafu

true
end

def clear_zafu
path = "#{SITES_ROOT}#{self.zafu_path}"
if File.exist?(path)
FileUtils.rmtree(path)
end
end

# Rebuild vhash indices for the Site. This method uses the Worker thread to rebuild and works on
# chunks of 50 nodes.
Expand Down
24 changes: 6 additions & 18 deletions lib/tasks/zena.rake
Expand Up @@ -235,28 +235,16 @@ namespace :zena do
end

desc "Remove all zafu compiled templates"
task :clear_zafu => :zena_config do
if File.exist?(SITES_ROOT)
Dir.foreach(SITES_ROOT) do |site|
next if site =~ /^\./
FileUtils.rmtree(File.join(SITES_ROOT, site, 'zafu'))
end
task :clear_zafu => :environment do
Site.all.each do |site|
site.clear_zafu
end
end

desc "Remove all cached data" # FIXME: cachedPages db should be cleared to
task :clear_cache => :environment do
if File.exist?(SITES_ROOT)
Dir.foreach(SITES_ROOT) do |site|
next if site =~ /^\./ || !File.exist?(File.join(SITES_ROOT,site,'public'))
Dir.foreach(File.join(SITES_ROOT,site,'public')) do |elem|
next unless elem =~ /^(\w\w\.html|\w\w)$/
FileUtils.rmtree(File.join(SITES_ROOT, site, 'public', elem))
end
end
['caches', 'cached_pages', 'cached_pages_nodes'].each do |tbl|
Site.connection.execute "DELETE FROM #{tbl}"
end
Site.all.each do |site|
site.clear_cache
end
end

Expand All @@ -278,7 +266,7 @@ namespace :zena do
end

task :full_backup => :environment do
data_folders = Site.find(:all).map { |s| File.join(SITES_ROOT, s.data_path) }.reject { |p| !File.exist?(p) }
data_folders = Site.all.map { |s| File.join(SITES_ROOT, s.data_path) }.reject { |p| !File.exist?(p) }
cmd = "tar czf #{RAILS_ROOT}/sites_data.tgz #{data_folders.join(' ')}"
puts cmd
puts `#{cmd}`
Expand Down

0 comments on commit a9b365e

Please sign in to comment.