【发布时间】:2020-03-25 00:08:04
【问题描述】:
您好,我有一个 rake 任务,当通过控制台工作执行时,它在调用 rake 任务时不起作用。实际上它确认发生了保存,而值没有更新。似乎缺少一些活动记录提交,因为我看到的日志中唯一的区别是如果运行(通过控制台)开始提交转储,而当作为 rake 任务运行时,Redmine 的 debug.log 中没有这样的部分......
这是它的内容:
namespace :redmine do
namespace :myplugin do
desc 'Updates custom field for idle tickets.'
task :update_idle => :environment do
Issue.open.each do |issue|
begin
days = DateTime.now.to_time - DateTime.parse(issue.updated_on.to_s).to_time
days = days/86400
if days > 0
cfv = issue.custom_field_values.detect {|cfv| cfv.custom_field_id == 19 }
cfv.value = days.ceil
if issue.save
puts "#{issue.id} saved"
else
puts "#{issue.id} not saved"
end
end
end
end
end
end
end
【问题讨论】:
-
如果您不更改问题属性而只更改自定义字段值,则有
save_custom_field_values方法,在acts_as_customizable模块中定义
标签: ruby-on-rails ruby rake redmine redmine-plugins