From 43a8fe27dca8e711b980b8a0e9034dd57bf142f2 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 6 Oct 2010 15:48:55 -0700 Subject: [PATCH] [#4604] Add a simple rake task to update missing cost caches --- README.rdoc | 2 ++ init.rb | 2 ++ lib/tasks/cache.rake | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 lib/tasks/cache.rake diff --git a/README.rdoc b/README.rdoc index e2fd6a0..3811f64 100644 --- a/README.rdoc +++ b/README.rdoc @@ -27,6 +27,7 @@ There are two sets of steps to install this plugin. The first one should be don These installation instructions are very specific because the Rate plugin adjusts data inside the Budget plugin so several data integrity checks are needed. 0. Backup up your data! Backup your data! +0. Install the Lockfile gem 1. Follow the Redmine plugin installation steps a http://www.redmine.org/wiki/redmine/Plugins Make sure the plugin is installed to +vendor/plugins/redmine_rate+ 2. Make sure you are running the 0.1.0 version of the Budget plugin and 0.0.1 version of the Billing plugin 3. Run the pre_install_export to export your current budget and billing data to file +rake rate_plugin:pre_install_export+ @@ -40,6 +41,7 @@ These installation instructions are very specific because the Rate plugin adjust === Option #2: If you do not have any data from Budget or Billing +0. Install the Lockfile gem 1. Follow the Redmine plugin installation steps a http://www.redmine.org/wiki/redmine/Plugins Make sure the plugin is installed to +vendor/plugins/redmine_rate+ 2. Run the plugin migrations +rake db:migrate_plugins+ in order to get the new tables for Rates 3. Restart your Redmine web servers (e.g. mongrel, thin, mod_rails) diff --git a/init.rb b/init.rb index 71d5e48..e5d6665 100644 --- a/init.rb +++ b/init.rb @@ -4,6 +4,8 @@ require 'dispatcher' Dispatcher.to_prepare :redmine_rate do + gem 'lockfile' + require_dependency 'sort_helper' SortHelper.send(:include, RateSortHelperPatch) diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake new file mode 100644 index 0000000..de9c7ef --- /dev/null +++ b/lib/tasks/cache.rake @@ -0,0 +1,20 @@ +require 'lockfile' + +namespace :rate_plugin do + namespace :cache do + desc "Update Time Entry cost caches" + task :update_cost_cache => :environment do + Lockfile('update_cost_cache', :retries => 0) do + TimeEntry.all(:conditions => {:cost => nil}).each do |time_entry| + begin + time_entry.save_cached_cost + rescue Rate::InvalidParameterException => ex + puts "Error saving #{time_entry.id}: #{ex.message}" + end + + end + + end + end + end +end