diff --git a/app/settings.rb b/app/settings.rb index 1a003e07..27b8b6cd 100644 --- a/app/settings.rb +++ b/app/settings.rb @@ -64,6 +64,7 @@ post '/settings/:username/change_name' do require_login require_ownership_for_settings + old_site = Site[username: @site.username] old_username = @site.username if params[:name] == nil || params[:name] == '' @@ -87,9 +88,10 @@ post '/settings/:username/change_name' do @site.move_files_from old_username } - old_site_file_paths.each do |site_file_path| - @site.delete_cache site_file_path - end + old_site.delete_all_thumbnails_and_screenshots + old_site.delete_all_cache + @site.delete_all_cache + @site.regenerate_thumbnails_and_screenshots flash[:success] = "Site/user name has been changed. You will need to use this name to login, don't forget it!" redirect "/settings/#{@site.username}#username" diff --git a/models/site.rb b/models/site.rb index 52564876..1346c1f2 100644 --- a/models/site.rb +++ b/models/site.rb @@ -524,9 +524,7 @@ class Site < Sequel::Model save validate: false destroy - site_files.each do |site_file| - delete_cache site_file.path - end + delete_all_cache end def ban_all_sites_on_account! @@ -736,6 +734,12 @@ class Site < Sequel::Model end end + def delete_all_cache + site_files.each do |site_file| + delete_cache site_file.path + end + end + def delete_cache(path) purge_cache path end @@ -1716,7 +1720,23 @@ class Site < Sequel::Model regenerate_thumbnails end - def generate_screenshot_or_thumbnail(path, screenshot_delay=0) + def delete_all_thumbnails_and_screenshots + site_files.each do |sf| + delete_thumbnail_or_screenshot sf.path + end + end + + def delete_thumbnail_or_screenshot(path) + extname = File.extname path + + if extname.match HTML_REGEX + screenshots_delete path + elsif extname.match IMAGE_REGEX + thumbnails_delete path + end + end + + def generate_thumbnail_or_screenshot(path, screenshot_delay=0) extname = File.extname path if extname.match HTML_REGEX @@ -1778,7 +1798,7 @@ class Site < Sequel::Model site_file.save purge_cache path - generate_screenshot_or_thumbnail relative_path, SCREENSHOT_DELAY_SECONDS + generate_thumbnail_or_screenshot relative_path, SCREENSHOT_DELAY_SECONDS true end diff --git a/models/site_file.rb b/models/site_file.rb index 52c44837..e857f287 100644 --- a/models/site_file.rb +++ b/models/site_file.rb @@ -61,6 +61,8 @@ class SiteFile < Sequel::Model begin FileUtils.mv site.files_path(path), site.files_path(new_path) + site.delete_thumbnail_or_screenshot current_path + site.generate_thumbnail_or_screenshot new_path rescue Errno::ENOENT => e return false, 'destination directory does not exist' if e.message =~ /No such file or directory/i raise e @@ -80,8 +82,10 @@ class SiteFile < Sequel::Model original_site_file_path = site_file.path site_file.path = site_file.path.gsub(/^#{current_path}\//, "#{new_path}\/") site_file.save_changes - site.purge_cache original_site_file_path + site.delete_thumbnail_or_screenshot original_site_file_path + site.generate_thumbnail_or_screenshot site_file.path site.purge_cache site_file.path + site.purge_cache original_site_file_path end end end