Closed
Description
Hi @nutso, please check the following points
- I dont know why, but it seem that the recurring task is created as anon, not as author of the original task so it cannot be recurred further. I change the order of your code to set User.current at the beginning before making new_issue and everything seems OK
- In rare case, if the issue has empty start date the calculation of time span yield error. I change is to take create date of the issue as start date on that case. Here are the modification I did
# calculate the original number of days between start and due date
ddate = issue.due_date.blank? ? Time.now.to_date : issue.due_date
sdate = issue.start_date.blank? ? issue.created_on.to_date : issue.start_date
timespan = ddate - sdate #issue.due_date - issue.start_date
while need_to_recur?
usr_id = Setting.plugin_recurring_tasks['journal_attributed_to_user'].blank? ?
issue.author_id : Setting.plugin_recurring_tasks['journal_attributed_to_user'].to_i
defined_user = User.find(usr_id)
old_current_user = User.current
User.current = defined_user
new_issue = issue # default to existing issue
if Setting.plugin_recurring_tasks['reopen_issue'] != "1"
# duplicate issue
new_issue = issue.copy
end
if !Setting.plugin_recurring_tasks['journal_attributed_to_user'].blank?
issue.init_journal(defined_user, "#{l(:recurring_task_created)} => #{new_issue.id}: #{new_issue.subj_date}")
end
new_issue.due_date = next_scheduled_recurrence #41 previous_date_for_recurrence + recurrence_pattern
new_issue.start_date = new_issue.due_date - timespan
...