Closed (fixed)
Project:
TMGMT Translator Gengo
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
15 Apr 2013 at 10:21 UTC
Updated:
7 May 2013 at 19:40 UTC
Jump to comment: Most recent file
Comments
Comment #1
blueminds commentedSo the initial very rough patch just as proof of concept.
Here are some remarks:
- Currently it does not use tmgmt api at all. I see following divergencies:
* tmgmt core mappings operate rather over job items, for gengo we deal with jobs as a whole or individual data items
* in gengo we use the mapping table to create placeholders that are removed after we receive mapping data and real mappings are created
Here are places where we will need to do the major refactoring:
- TMGMTMyGengoTranslatorPluginController::mapGengoJobs() - most of the mapping logic is here
- TMGMTMyGengoTranslatorPluginController::processGengoJobsUponTranslationRequest() - processing jobs right after the initial submission
- TMGMTMyGengoTranslatorPluginController::saveTranslation() - duplicate handling
- TMGMTMyGengoTranslatorPluginController::sendJob() - duplicate handling
I do not think we have to change current tmgmt core api, but job/jobItem::getRemoteMappings() where we should allow additional conditions for select.
Last think - duplicates. Currently we store a "local" mapping of two data items, where remote_identifier_1 is the data item key of mapped data item. I suggest we create a regular mapping to the same remote job. Then we can either try to load data for the item locally, and in case the job does not exist anymore we can pull from gengo.
Comment #2
blueminds commentedComment #3
berdirfetchAll() is not necessary, you can loop over the return value of execute().
Also, this can easily be written as a db_query('select * from {tmgmt_mygengo_mappings}') as it's not a dynamic query. Or then formatted correctly.
Use a multi-value insert here. $insert = db_insert()->fields(), then just $insert->values() and after the loop, $insert->execute().
More later.
Comment #4
berdirRaising this to major.
The current mapping is inflexible and I've seen various weird behaviors and bugs. Single mappings getting dropped suddenly, completely wrong mappings with wrong tjid's that didn't map the data item keys.
The form alter code is broken and doesn't check the job item id, so you end up with a random job id if you have multiple job items with the same data item keys.
If possible in anyway, we need to refactor the code to switch to the core mapping API for the new release.
Comment #5
berdirStarted working on this, will provide a patch tomorrow morning.
Comment #6
berdirHere's a first patch. Tests are passing, manual tests were working as well. Will comment on a few changes with dreditor in the next comment.
Comment #7
berdirNever rely on hook_schema() in an update hook, you must copy the table definition. You already worked around the problem in 7002 but it gets more and more complicated as you change the original structure. Decided to just remove that and make the removal conditional.
That's a trick that I'm using a few places now, making it a function is tricky as we still need the list() part.
One thing that we could consider for gengo jobs is something like a GengoJob($data) class, that allows us to do getJob(), getJobItem(), getDataItemKey() but that's stuff for later, if at all.
You can update specific things with updateData(), it's pretty neat. the tmgmt_ensure_keys_array() also wouldn't be necessary, it accepts both.
This was actually partially done twice in the old code, as mapGengoJobs() also did saveTranslation() for existing mappings.
Also, we should imho use "fetch" or so in the UI for this (button + message), not poll.
Noticed fatal errors in the log when gengo for some reason calls the callback for jobs that got deleted or so.
The first case should actually never happen, as we always create a mapping for each data item key with the order id below. But I left it in for now.
This is also done three times now, in slightly different variations, not yet sure how to consolidate it.
I think I don't use those anymore atm.
Moved this into sendJob() so that I have access to $translations in initGengoMapping.
As said before, we should imho have something like $translations = $this->buildTranslations($job) and then call $connector->submitJob() directly in requestTranslation() but that's right now a bit ugly due to the duplicate handling.
Which should be reworked now to have two mappings to the same gengo job. Then the UI (comment/revision) will be a lot easier to fix for duplicates.
Seeing this currently on the sandbox, just added a message for now so it's easier to debug. Will need to check with them why that is happening.
This is the immediate process case, where we don't have an order_id.
This works quite a bit different now and is only called for the manual poll/fetch action. It basically does this:
1. Load remote mappings
2. Load unique order ids
3. Load those and check for not yet mapped job ids. This again is something that should not happen but let's make sure.
4. Then load all existing mapped and new jobs.
5. Create mappings if they don't exist yet based on custom_data.
6. Save translations if there are any.
That's the += bug that I mentioned ;)
I really like how this got a *lot* easier :)
Comment #8
berdirOne more thing, this call in the callback resulted in an exponentioally increasing time when callbacks were invoked for created gengo jobs. Every time the order was requested, all jobs were requested and all translations updated if possible. Now that method does even more but as mentioned above, it's no longer called here. On the callback, we just update the mapping for the provided job id.
A job with 10 items or so took multiple minutes, it's down to a few seconds now.
Comment #9
berdirThis one should apply.
Comment #10
berdirOk. This should fix the duplicate handling, they're now tracked as additional remote data of a mapping. Making them separate mappings to the same job might be nicer but is also quite a bit more work as we still need this temporary storage for at least the order case. We do have a separate issue open to improve this.
When revising data items with duplicates, then those are set to pending as well and are then correctly updated again.
Also partially fixed the broken review UI for multi-value fields. Comments still show up wrong, but I'd prefer to refactor that to use methods provided by core for this instead of making the mess here bigger.
Interdiff is big but most of that just adding another foreach to the review alter code.
Comment #11
berdirOk, this should fix the polling bugs. Poor job items, always they get forgotton.
Comment #12
berdirFixed a stupid condition that was the wrong way round in the update function and added a ton of tests for order mode callback calls + polling.
The mock callbacks will need to be improved, for example, right the jobs callback doesn't actually check what arguments he gets, he just returns the previously entered response object. That makes it hard to actually validate that it was called with the right ids. But that might affect other tests, so I'll wait with improving that.
Comment #13
berdirCommited, updated changelog. While not perfect, this is certainly the way forward.