NOTE: This issue is reserved for one of the possible new students in MD Systems! Do not start to work on this except you are the student we sent this issue to :)
Problem/Motivation
There are similar constructs in tmgmt_write_request_messages(), JobAbortForm(), JobItemForm(), JobItemAbortForm() and tmgmt_file_import_form_submit(). We should refactor this to avoid duplicated code as suggested in #2672924: Disallow item deletion after submission and support item abort at comment #16.
Thus we either need a separate interface for getMessagesSince() or two separate typed methods - one for Job and one for JobItem case.
Proposed resolution
I would suggest to create a new function in tmgmt.module similar to tmgmt_write_request_messages(), which has JobInterface $job as parameter, and the new one needs to get JobItemInterface $job_item as parameter. Then properly call these functions where the duplicated code are mentioned above.
Discuss later if there is a better solution.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | refactor_code_where-2689025-20.patch | 4.83 KB | tbonomelli |
| #20 | interdiff-2689025-18-20.txt | 949 bytes | tbonomelli |
| #18 | refactor_code_where-2689025-18.patch | 4.86 KB | tbonomelli |
| #18 | interdiff-2689025-16-18.txt | 821 bytes | tbonomelli |
| #16 | refactor_code_where-2689025-16.patch | 4.75 KB | tbonomelli |
Comments
Comment #2
tduong commentedComment #3
tbonomelli commentedI created a new function
tmgmt_write_request_messages_for_jobItem().Then I removed the duplicated code and called the right function.
I didn't remove the duplicated code in JobAbortForm(), because there is something that doesn't make any sense to me. the duplicated code is inside an if statement. But after the if statement, the function
tmgmt_write_request_messages()gets called anyway.Comment #5
tbonomelli commentedI had to reroll the patch, This is the right one.
Comment #7
johnchque"tmgmt_write_request_messages_job_item" better?
$message->getMessage() should work better.
Not sure if, following this approach, we will need to remove the original function at some point so we should add two new functions, one called "tmgmt_write_request_messages_job_item" and the other "tmgmt_write_request_messages_job"
Comment #8
tbonomelli commentedAdjusted the names of the functions and fixed the
tmgmt_write_request_messages_jobfunction.Also fixed a wrong call of the function above.
Comment #9
johnchqueAs you can see here it seems that the job is sent. Should we use instead tmgmt_write_request_job ?
Comment #10
tbonomelli commentedtmgmt_write_request_job is being used now.
Comment #11
tbonomelli commentedAccidentally had a typo in the source when I created the last interdiff. I already removed it in the last patch.
Comment #12
johnchqueGood work, close enough.
Isn't this the job item?
Comment #13
berdirWhile this makes sense to clarify the function, this is an API change that's not really required.
We're in RC phase, so we try to avoid API changes as much as possible.
There's also a different way to solve this, see below.
JobItem actually has a getMessagesSince() method too, so we can use that directly.
I'd think that's what I would expect to happen, since you otherwise get the messages for all items in the job, not just this item.
Also, here's an idea. Instead of having two almost identical methods, we coud make one method that accepts both objects.
The easiest way to do that is to just remove the type hint and document that both objects are accepted on the @param. The stricter way would be to make a new interface "MessagesInterfaces" and move getMessages() and getMessagesSince() to that, implementing it in both objects. Then we can type hint on that and could later on even use it for other objects (like local task (items) when those get messages too.
Comment #14
tbonomelli commentedremoved the
tmgmt_write_request_messages_job_itemfunction.renamend
tmgmt_write_request_messages_jobtotmgmt_write_request_messagesand adjusted the function to work for jobs and jobitems.As mentioned in comment #3, what should I do about the duplicated code in the following case? The duplicated code is in an if statement, but the function gets called after the if statement anyways.
Comment #15
berdirwe might want to pass the job item here, the current code might only get the job because the function requested that.
Comment #16
tbonomelli commentedRemoved the duplicated code in JobAbortForm.php and fixed the
submitFormfunction.Adjusted the
ajaxReviewFormfunction in JobItemForm.php to call thetmgmt_write_request_messageswith a job_item instead of a job as parameter.Comment #17
berdirhm. This is a useful comment I think. Lets keep that, move it above the if and try to reword it a bit so it makes sense not only if it fails.
Comment #18
tbonomelli commentedI adjusted the comment.
Comment #19
tduong commentedCool, just a nitpick:
Better to call it $entity instead of $job_or_job_item :)
Not fully sure why we want to pass a job item in these places (JobItemForm code mentioned in #15)...
Comment #20
tbonomelli commentedChanged the name of the parameter from
$job_or_job_itemto$entityComment #21
johnchqueLooks nice.
Comment #23
miro_dietikerThx, committed. :-)