Permalink
Browse files

First commit of the whining cronjob

  • Loading branch information...
chantra committed Jul 16, 2009
0 parents commit 39f143454fd032c7d11705b8d5e2bd3939eae611
@@ -0,0 +1 @@
+*.swp
@@ -0,0 +1,2 @@
+Thu Jul 16 15:17:11 CEST 2009
+ * First release of redmine_whining plugin/cronjob
@@ -0,0 +1,18 @@
+This plugin provides email alerts when an issue had not been updated
+since a certain time.
+
+Created by Emmanuel Bretelle
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -0,0 +1,12 @@
+= whining
+
+This plugin provides email alerts when an issue had not been updated
+since a certain time.
+
+Created by Emmanuel Bretelle
+
+Usage:
+------
+Create a cron job with a line similar to this:
+0 7 * * 1,2,3,4,5 www-data cd /path/to/redmine && /usr/bin/rake redmine:send_whining days=7 RAILS_ENV="production"
+
@@ -0,0 +1,9 @@
+<p><%= l(:mail_body_whining, @issues.size, @days) %></p>
+
+<ul>
+<% @issues.each do |issue| -%>
+ <li><%=h "#{issue.project} - #{issue.tracker} ##{issue.id}: #{issue.subject} was last updated on #{issue.updated_on} " %></li>
+<% end -%>
+</ul>
+
+<p><%= link_to l(:label_issue_view_all), @issues_url %></p>
@@ -0,0 +1,7 @@
+<%= l(:mail_body_whining, @issues.size, @days) %>:
+
+<% @issues.each do |issue| -%>
+* <%= "#{issue.project} - #{issue.tracker} ##{issue.id}: #{issue.subject} was last updated on #{issue.updated_on}" %>
+<% end -%>
+
+<%= @issues_url %>
@@ -0,0 +1,8 @@
+require 'redmine'
+
+Redmine::Plugin.register :redmine_whining do
+ name 'Redmine Whining plugin'
+ author 'Emmanuel Bretelle'
+ description 'A plugin to send email alerts when an issue did not get udated since a certain amount of time. This plugin MUST be called from a cronjob.'
+ version '0.0.1'
+end
@@ -0,0 +1,3 @@
+# English strings go here
+mail_body_whining: "%d issue(s) that are assigned to you haven't been updated in the last %d days:"
+mail_subject_whining: "%d issue(s) not updated in the last %d days"
@@ -0,0 +1,71 @@
+# redMine - project management software
+# Copyright (C) 2009 Emmanuel Bretelle
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+desc <<-END_DESC
+Send reminders about issues that were not updated since X days.
+
+Available options:
+ * days => number of days since last update (defaults to 7)
+ * tracker => id of tracker (defaults to all trackers)
+ * project => id or identifier of project (defaults to all projects)
+
+Example:
+ rake redmine:send_whining days=7 RAILS_ENV="production"
+END_DESC
+
+require 'config/environment'
+require "mailer"
+#require "actionmailer"
+
+class WhiningMailer < Mailer
+ def whining(user, issues, days)
+ set_language_if_valid user.language
+ recipients user.mail
+ subject l(:mail_subject_whining, issues.size, days)
+ body :issues => issues,
+ :days => days,
+ :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'updated_on', :sort_order => 'asc')
+ end
+
+ def self.whinings(options={})
+ days = options[:days] || 7
+ project = options[:project] ? Project.find(options[:project]) : nil
+ tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
+
+ s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.updated_on <= ? AND #{Issue.table_name}.assigned_to_id IS NOT NULL", false, days.day.until.to_date]
+ s << "#{Issue.table_name}.project_id = #{project.id}" if project
+ s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
+ issues_by_assignee = Issue.find(:all,
+ :include => [:status, :assigned_to, :project, :tracker],
+ :conditions => s.conditions
+ ).group_by(&:assigned_to)
+ issues_by_assignee.each do |assignee, issues|
+ deliver_whining(assignee, issues, days) unless assignee.nil?
+ end
+ end
+end
+
+namespace :redmine do
+ task :send_whining => :environment do
+ options = {}
+ options[:days] = ENV['days'].to_i if ENV['days']
+ options[:project] = ENV['project'] if ENV['project']
+ options[:tracker] = ENV['tracker'].to_i if ENV['tracker']
+
+ WhiningMailer.whinings(options)
+ end
+end
@@ -0,0 +1,5 @@
+# Load the normal Rails helper
+require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
+
+# Ensure that we are using the temporary fixture path
+Engines::Testing.set_fixture_path

0 comments on commit 39f1434

Please sign in to comment.