How to access plugin settings from a rake task
Added by Heiko Jung almost 5 years ago
Hello!
I'm trying to write my first plugin for Redmine. The plugin is supposed to enable Tickets to be deferred until a specific point in time is passed and then be reactivated automatically.
The plan is to write a plugin with a settings page for the configuration and then to run a rake task by cronjob or task scheduler (Windows) one or two times a day to check for tickets which have to be reactivated. Activation and deactivation only means changing the issue status.
My problem is that I can't access the settings of the plugin from my rake task. How can I access them?
For example one of my Settings is a Dropdown box @settings["delayed_tickets_states"]
My init.rb looks like this:
Redmine::Plugin.register :wolf_it_delayed_tickets do name 'WOLF IT Delayed Tickets Plugin' author 'xxxxxxx' description 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' version '0.0.1' url 'http://witgit.wolfit.intern:3000/Redmine/wolf_it_delayed_tickets' author_url 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' settings :default => {}, :partial => 'settings/wolf_it_delayed_tickets' end
The settings page already works, but I have no idea how to access the plugin settings from inside my rake task (this does NOT work, but it explains, what I want to do... at least I hope, it does...):
desc <<-END_DESC - reactivate deactivated due tickets Example: rake redmine:wit_reactivate_tickets END_DESC namespace :redmine do desc "Reactivates all Tickets hitting the defined criteria" task :wit_reactivate_tickets => :environment do options = {} options[:delayed_tickets_states] = @settings["delayed_tickets_states"] options[:reactivated_tickets_states] = @settings["reactivated_tickets_states"] options[:reactivated_tickets_days_before] = @settings["reactivated_tickets_days_before"] options[:wit_projects_list] = @settings["wit_projects_list"] options[:wit_trackers_list] = @settings["wit_trackers_list"] puts "~ Task - Criteria (See Plugin Settings): ~" puts "---------------------------------------" puts " Delayed State: " & @settings["delayed_tickets_states"].to_s puts " Reactivated State: " & @settings["reactivated_tickets_states"].to_s puts " " puts " Reactivation distance in days: " & @settings["reactivated_tickets_days_before"].to_s puts " " puts " Projects to consider: " & @settings["wit_projects_list"].to_s puts " Trackers to consider: " & @settings["wit_trackers_list"].to_s puts "---------------------------------------" end end
I'm new to Redmine plugin development and rails, but I do hope, someone can help me.
Thanks in advance!
Shoob
Replies (2)
RE: How to access plugin settings from a rake task
-
Added by Davide Giacometti over 4 years ago
Hi Heiko,
analyzing app/controllers/settings_controller.rb#plugin I was able to access plugin settings from a rake task with this code:
Setting.send "plugin_#{@plugin.id}"
It returns the settings hash for the plugin. Your plugin id is wolf_it_delayed_tickets, then:
Setting.send "plugin_wolf_it_delayed_tickets"
Davide
RE: How to access plugin settings from a rake task
-
Added by Jens Krämer over 4 years ago
no need to use send
, Setting.plugin_your_plugin_id
just works, returning the hash of your plugin settings.