Feature #37530 » 37530-v2.patch
| app/views/settings/_display.html.erb | ||
|---|---|---|
|
<p><%= setting_text_field :thumbnails_size, :size => 6 %></p>
|
||
|
<p><%= setting_text_field :thumbnails_timeout, :size => 6 %></p>
|
||
|
<p><%= setting_select :new_item_menu_tab, [[l(:label_none), '0'], [l(:label_new_project_issue_tab_enabled), '1'], [l(:label_new_object_tab_enabled), '2']] %></p>
|
||
|
</div>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
setting_session_timeout: Session inactivity timeout
|
||
|
setting_thumbnails_enabled: Display attachment thumbnails
|
||
|
setting_thumbnails_size: Thumbnails size (in pixels)
|
||
|
setting_thumbnails_timeout: Thumbnails creation timeout (in seconds)
|
||
|
setting_non_working_week_days: Non-working days
|
||
|
setting_jsonp_enabled: Enable JSONP support
|
||
|
setting_default_projects_tracker_ids: Default trackers for new projects
|
||
| config/settings.yml | ||
|---|---|---|
|
thumbnails_size:
|
||
|
format: int
|
||
|
default: 100
|
||
|
thumbnails_timeout:
|
||
|
format: int
|
||
|
default: 10
|
||
|
non_working_week_days:
|
||
|
serialized: true
|
||
|
default:
|
||
| lib/redmine/thumbnail.rb | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
require 'fileutils'
|
||
|
require 'timeout'
|
||
|
module Redmine
|
||
|
module Thumbnail
|
||
| ... | ... | |
|
else
|
||
|
cmd = "#{shell_quote CONVERT_BIN} #{shell_quote source} -auto-orient -thumbnail #{shell_quote size_option} #{shell_quote target}"
|
||
|
end
|
||
|
unless system(cmd)
|
||
|
logger.error("Creating thumbnail failed (#{$?}):\nCommand: #{cmd}")
|
||
|
pid = nil
|
||
|
begin
|
||
|
Timeout.timeout(Setting.thumbnails_timeout.to_i) do
|
||
|
pid = Process.spawn(cmd)
|
||
|
_, status = Process.wait2(pid)
|
||
|
unless status.success?
|
||
|
logger.error("Creating thumbnail failed (#{status.exitstatus}):\nCommand: #{cmd}")
|
||
|
return nil
|
||
|
end
|
||
|
end
|
||
|
rescue Timeout::Error
|
||
|
begin
|
||
|
Process.kill('TERM', pid)
|
||
|
Timeout.timeout(1) { Process.wait(pid) }
|
||
|
rescue Timeout::Error
|
||
|
Process.kill('KILL', pid)
|
||
|
end
|
||
|
logger.error("Creating thumbnail timed out:\nCommand: #{cmd}")
|
||
|
return nil
|
||
|
end
|
||
|
end
|
||
| test/unit/attachment_test.rb | ||
|---|---|---|
|
ensure
|
||
|
set_tmp_attachments_directory
|
||
|
end
|
||
|
def test_thumbnail_should_timeout
|
||
|
dummy_pid = 37530
|
||
|
Process.stubs(:spawn).returns(dummy_pid)
|
||
|
Process.stubs(:wait2).raises(Timeout::Error)
|
||
|
Process.stubs(:kill).returns(1)
|
||
|
Process.stubs(:wait).returns(dummy_pid)
|
||
|
Rails.logger.expects(:error).with(regexp_matches(/Creating thumbnail timed out/))
|
||
|
set_fixtures_attachments_directory
|
||
|
Attachment.clear_thumbnails
|
||
|
attachment = Attachment.find(16)
|
||
|
thumbnail = attachment.thumbnail
|
||
|
assert_nil thumbnail
|
||
|
ensure
|
||
|
set_tmp_attachments_directory
|
||
|
end
|
||
|
else
|
||
|
puts '(ImageMagick convert not available)'
|
||
|
end
|
||