Copying one issue and its child issues is a natively built-in feature and thus works just fine.
But is there a way to do this multiple times? Like re-creating one issue (including its children) twenty or fifty times?
Edit 2
This new functionality should be accessible via the Redmine
interface and compatible to any browser.
It does not matter whether it is a completely new Plugin, an extension to the built-in copy feature, a call to a PHP-script
or anything else. Due to compatibility (networking, browsers etc.) I guess a completely server-side modification is the only way to go here.
What parts of the default plugin (as created in the voting tutorial) or a core element would have to be changed?
Where can I find the code for the native issue copy function?
Or - if all this is too complicated - how would I write my plugin to point to a PHP
file that manipulates the SQL
database directly?
Edit:
To clarify: just like the normal copy function (either in the context menu or the top-right link, I don't care) I want to copy one issue and its sub-issues n times. To let the user set the amount n, any user number input may suffice, like a textbox, a pop-up etc.
I think the simplest way to do this is to start with redmine source modification. Once it works you can move on and try to extract this feature into plugin.
Note, that I am not a ruby developer, so some things below are just my guesses. But I did few small redmine modifications like this before and hope that my thoughts can be useful.
It will also be easier if you familiar with some of MVC frameworks (for any language), because they mostly have a similar structure with routes, controllers, views and models.
The link to copy single issue looks like this: //redmine.myserver.com/projects/myapp/issues/12407/copy
.
My idea is to add a num_copies
parameter to this link and use it in the code to create many copies.
You need no UI for that, once implemented the feature will work like this:
copy
action for it?num_copies=XX
parameter into the URL (//redmine.myserver.com/projects/myapp/issues/12407/copy?num_copies=50
) and press 'Enter' to reload the formnum_copies
parameterNow, how to do this. I am referring to the redmine mirror on github which looks fresh.
.../copy
link is handledWhen you open the form to copy the issue, you'll see form like this:
<form action="/projects/myapp/issues" class="new_issue" id="issue-form" method="post"> <input id="copy_from" name="copy_from" type="hidden" value="12407"> <div class="box tabular"> <div id="all_attributes"> ... </form>
Note the form action, it points to the /issues
link and it will submit the copy_from
parameter (this is ID of the issue we are copying).
We could first go and check through the config/routes.rb
, but we can just guess that we need the controllers/issues_controller.rb
Search for the place where copy_from
parameter is used.
You'll see the build_new_issue_from_params
method. Now search for its usages and you'll find this:
before_filter :build_new_issue_from_params, :only => [:new, :create]
From how it looks, I guess that it is called before both new
and create
actions. Looking at new and create definitions, the new
action renders the new issue form and the create
action handles the form post.
num_copies
parameter to the formFind the view file used by new issue action. Here there is a template for the new issue form, try to add num_copies
parameter similar to the copy_from:
<%= title l(:label_issue_new) %> <%= call_hook(:view_issues_new_top, {:issue => @issue}) %> ... <%= error_messages_for 'issue' %> <%= hidden_field_tag 'copy_from', params[:copy_from] if params[:copy_from] %>
Here I am not 100% sure if it will just work if you add a similar line for `num_copies. You may also need to modify the route.
When done, you should have the new issue form like this:
<form action="/projects/myapp/issues" class="new_issue" id="issue-form" method="post"> <input id="copy_from" name="copy_from" type="hidden" value="12407"> <input id="copy_from" name="num_copies" type="hidden" value="50"> <div class="box tabular"> <div id="all_attributes"> ... </form>
num_copies
parameterIt should be done in the create action:
def create ... call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) if @issue.save ... end
Here you already have the @issue
variable created in the build_new_issue_from_params
method and what you need to do is to check if num_copies
parameter is set and if it is set then copy / save the @issue
in a loop to create additional copies.
I can't provide the exact code snippet for this, but it should not be very complex. Check this code in the bulk_update
method, it looks like what you need:
issue = orig_issue.copy({}, :attachments => copy_attachments, :subtasks => copy_subtasks, :link => link_copy?(params[:link_copy]) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With