the problematic code snippet in l10n_community/export.inc
function l10n_community_export() {
$export_string = array()
while ($string = db_fetch_object($result)) {
if (!empty($export_string)) {
//save the string
}
$export_string = array('value' => $string->value, ...)
}
}
it is evident that the last string will not be exported
and I guess this is a duplicate: #231457: Missing strings in exports if version string is missing
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 331987-6.missing_export.6-1.patch | 6.7 KB | pasqualle |
| #1 | 331987-2.missing_export.6-1.patch | 13.88 KB | pasqualle |
Comments
Comment #1
pasquallethe change
Comment #2
zoltán balogh commentedThis patch is works fine.
Comment #3
gábor hojtsySorry that it took some time to review this patch, but it does need some thought. In short: neither the current code, nor your patch is right.
The current logic works this way:
What this does is that it keeps building up $export_string with all the location information for a string from multiple database result rows, until the next string comes around, when it saves $export_string, and starts processing of the next string. It does skip saving the last string, it is clear to me. You are right in that.
However, your code does the following (I did not actually try it, was just doing code review):
What this logic disrespects is that data for the same sid comes in a sequence of multiple rows from the database, and those should be aggregated in $export_string before handled. Your code seems to export multiple copies of the same string with bogus (duplicated) location information from the second copy onwards, when the same string appears multiple times in the exported "domain" (eg. Drupal core, module, theme).
What makes this code tricky is that even for the last database row, we don't know in advance whether that will be a new string or just additional location information for the existing one we are already handling. And we don't know when that last row comes, so handling the last row should be deferred until information is available that there are no more rows and we should close up the last string and save into $output / $string_files. So saving the last string is something we can only decide on after we are out of the while() loop.
Maybe we should refactor most of the inside of the while() loop to a function which would take most variables by reference, so we can call it once on each step inside the while() loop and once outside the while loop at the end to save the last string. Any good ideas are appreciated.
Comment #4
gábor hojtsyEdited the above flow of your code to say:
Instead of the original:
Which was a mistake in indentation. You always save the string for each new database row, regardless of conditionals, so the last DO should be on the same level as ALWAYS and IF.
Comment #5
pasqualleOK, I see the problem
it is possible to write a code where you do not need an extra function to save the string
for example:
but I agree that writing a new function to save the string would result a much cleaner code..
Comment #6
pasqualleComment #7
zoltán balogh commentedThis patch is works fine.
Comment #8
gábor hojtsyLooks great, thanks for the persistence and for the solution. Committed!