fisharebest / webtrees

Online genealogy
https://webtrees.net
GNU General Public License v3.0
492 stars 302 forks source link

Fix to allow webtrees1.7 to read location data created in webtrees 2.0 #3202

Closed ddrury closed 4 years ago

ddrury commented 4 years ago

There's something wrong with my system that prevents me creating a pull request for this! In the googlemaps module add the following code at about line 3799. I'm sure that there is a more correct way to do this with the existing code but said code makes my brain hurt.

Existing code

            if (!is_dir(WT_MODULES_DIR . 'googlemap/places/flags/')) {
                $set_icon = false;
            }

Insert new code

            // Fudge to allow webtrees 1.7 to read files created by webtrees 2.0
            $lines = array_map(function ($line) {
                return trim(str_replace('"', '', $line));
            }, $lines);

Existing code

            foreach ($lines as $p => $placerec) {
                $fieldrec = explode(';', $placerec);
fisharebest commented 4 years ago

The problem with trim() is that it removes too much.

CSV files use a double-enclosure character to embed it in text.

So, if we are using " as an enclosure, then we encode " as "". e.g.

php > fputcsv(fopen('php://output', 'w'), ['foo', '"bar"', 'baz'], ';', '"');
foo;"""bar""";baz

We really need to use fputcsv() and fgetcsv().

fisharebest commented 4 years ago

FYI, here's a placename in one of my test files: "Minnehaha", on the steamship.

I have updated the 1.7 code to use fputcsv() and fgetcsv().

In my tests, it can read files generated by 2.0 and also earlier versions of 1.7.

(And also files created by MS Excel.)

Can you test for me?

ddrury commented 4 years ago

I have a problem with a file I've just exported from 1.7 prior to this update The header line is "Level";"Country";"State";"County";"City";"Longitude";"Latitude";"Zoom level";"Icon"; note the trailing semicolon, this causes an error in line 3787 $fields is calculated as 10 not 9

fisharebest commented 4 years ago

Dang. I guess we need to ignore the header row, and count columns in the data rows.

Fix incoming...

ddrury commented 4 years ago

Latest commit fixes it - Minihaha is still afloat

fisharebest commented 4 years ago

Thanks for testing.