1

I am getting in redmine Request-URI Too Long The requested URL's length exceeds the capacity limit for this server. whenever I try to select csv in timesheet plugin to export the timesheet report. How do i solve this please tell me

Samane
  • 500
  • 7
  • 23
ruby
  • 63
  • 1
  • 9

1 Answers1

1

The problem is the method. You are trying to retrieve too many parameters in the url and Apache (or any other like this one) have a limit of 2000 characters by default. In my case I didnt have access to the Apache server so changing the .conf file was not an option.

Looking into the forks of the repository I found someone who has already solved this issue. Here is a link to SashaH's pull request. This pull request is fairly new so it's not committed yet.

Just change the code as indicated and the plugin should work as you want:

app/helpers/timesheet_helper.rb

   :timesheet => timesheet.to_param)
   end

-  def link_to_csv_export(timesheet)
-    link_to('CSV',
-      {
-        :controller => 'timesheet',
-        :action => 'report',
-        :format => 'csv',
-        :timesheet => timesheet.to_param
-      },
-      :method => 'post',
-      :class => 'icon icon-timesheet')
+  def form_for_csv_export(timesheet)
+    params_like_decode_url = CGI.unescape({:timesheet => timesheet.to_param}.to_query)
+    inputs = ""
+    form = form_tag :controller => 'timesheet', :action => 'report', :format => 'csv' do
+      params_like_decode_url.split("&").each do |param|
+        param_arr = param.split("=")
+        inputs << hidden_field_tag(param_arr.first, param_arr.last, :id => "")
+      end
+      inputs << submit_tag("CSV")
+      inputs.html_safe
+    end
+    form.html_safe
   end

   def toggle_arrows(element, js_function)

app/models/timesheet.rb

   def to_csv
     out = "";
+
+    handle_time_entries = {}
+    time_entries.each do |k,v|
+      if k.is_a? String
+          handle_time_entries[k] = v
+          next;
+      end
+      handle_time_entries[k.name] = v
+    end
+
+    time_entries = handle_time_entries
     FCSV.generate(out, :encoding => 'u', :force_quotes => true) do |csv|
       csv << csv_header

 @@ -314,7 +325,7 @@ def time_entries_for_user(user, options={})

     return TimeEntry.includes(self.includes).
       where(self.conditions([user], extra_conditions)).
-      order('spent_on ASC')
+      order('spent_on ASC').references(self.includes)
   end

   def fetch_time_entries_by_project

app/views/timesheet/report.html.erb

 <div class="contextual">
-  <%= link_to_csv_export(@timesheet) %>
+  <%= form_for_csv_export(@timesheet) %>
   <%= permalink_to_timesheet(@timesheet) %>
 </div>

init.rb

 require 'redmine'

 ## Taken from lib/redmine.rb
-#if RUBY_VERSION < '1.9'
-#  require 'faster_csv'
-#else
-#  require 'csv'
-#  FCSV = CSV
-#end
+if RUBY_VERSION < '1.9'
+ require 'faster_csv'
+else
+ require 'csv'
+ FCSV = CSV
+end

 if Rails::VERSION::MAJOR < 3
   require 'dispatcher'
CubeJockey
  • 2,209
  • 8
  • 24
  • 31
Ruben Barbosa
  • 151
  • 1
  • 12