Fix bug for rails 4.2.
This commit is contained in:
parent
3be81db424
commit
b3dfe4981a
|
@ -7,6 +7,8 @@ class Admin::GalleriesController < OrbitAdminController
|
||||||
layout :compute_layout
|
layout :compute_layout
|
||||||
find_tag = Tag.all.select{|value| value.name==I18n.t('gallery.not_show_desc')}
|
find_tag = Tag.all.select{|value| value.name==I18n.t('gallery.not_show_desc')}
|
||||||
RackTempMiddleExist = defined?(Rack::TempfileReaper)
|
RackTempMiddleExist = defined?(Rack::TempfileReaper)
|
||||||
|
RACK_TEMPFILES = defined?(Rack::RACK_TEMPFILES) ? Rack::RACK_TEMPFILES : 'rack.tempfiles'
|
||||||
|
Is_Rails5 = (Rails.version.to_f >= 5)
|
||||||
if find_tag.length==0
|
if find_tag.length==0
|
||||||
module_app_id = ModuleApp.where(:key=>"gallery").first[:_id]
|
module_app_id = ModuleApp.where(:key=>"gallery").first[:_id]
|
||||||
tags = ModuleApp.where(:key=>"gallery").first.tags
|
tags = ModuleApp.where(:key=>"gallery").first.tags
|
||||||
|
@ -40,6 +42,20 @@ class Admin::GalleriesController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if RackTempMiddleExist # Avoid Rack::TempfileReaper Middleware to unlink temp files automatically.
|
||||||
|
if Is_Rails5
|
||||||
|
def fix_tempfile_reaper
|
||||||
|
request.set_header(RACK_TEMPFILES, [])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
def fix_tempfile_reaper
|
||||||
|
env[RACK_TEMPFILES] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
def fix_tempfile_reaper #do nothing for old rack
|
||||||
|
end
|
||||||
|
end
|
||||||
def compute_layout
|
def compute_layout
|
||||||
if action_name== 'index' && !params['page_no'].nil?
|
if action_name== 'index' && !params['page_no'].nil?
|
||||||
false
|
false
|
||||||
|
@ -500,17 +516,21 @@ class Admin::GalleriesController < OrbitAdminController
|
||||||
Thread.new do
|
Thread.new do
|
||||||
album_unprocess.each_with_index do |un_image,i|
|
album_unprocess.each_with_index do |un_image,i|
|
||||||
begin
|
begin
|
||||||
album = AlbumImage.all.select{|value| value.id.to_s == un_image.image_id.to_s}[0]
|
album = AlbumImage.where(:id => un_image.image_id).first
|
||||||
album.file = un_image.save_var
|
if album.nil?
|
||||||
album.save!
|
un_image.delete
|
||||||
file = un_image.save_var.tempfile
|
else
|
||||||
file.close
|
album.file = un_image.save_var
|
||||||
File.delete file.path
|
album.save!
|
||||||
un_image.delete
|
file = un_image.save_var.tempfile
|
||||||
variable = AlbumVariable.first
|
file.close
|
||||||
variable.progress_filename = album[:file]
|
File.delete file.path
|
||||||
variable.progress_percent = ((i+1)*100.0/count).floor.to_s + '%'
|
un_image.delete
|
||||||
variable.save!
|
variable = AlbumVariable.first
|
||||||
|
variable.progress_filename = album[:file]
|
||||||
|
variable.progress_percent = ((i+1)*100.0/count).floor.to_s + '%'
|
||||||
|
variable.save!
|
||||||
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
puts ['err',un_image.inspect,e.inspect]
|
puts ['err',un_image.inspect,e.inspect]
|
||||||
un_image.destroy
|
un_image.destroy
|
||||||
|
@ -559,7 +579,7 @@ class Admin::GalleriesController < OrbitAdminController
|
||||||
album_unprocess.save_var = file
|
album_unprocess.save_var = file
|
||||||
album_unprocess.save!
|
album_unprocess.save!
|
||||||
ObjectSpace.undefine_finalizer(file.tempfile)
|
ObjectSpace.undefine_finalizer(file.tempfile)
|
||||||
request.set_header(Rack::RACK_TEMPFILES, []) if RackTempMiddleExist # Avoid Rack::TempfileReaper Middleware to unlink temp files automatically.
|
fix_tempfile_reaper
|
||||||
end
|
end
|
||||||
image.save!
|
image.save!
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue