{"action":"created","issue":{"url":"https://api.github.com/repos/fisharebest/webtrees/issues/774","labels_url":"https://api.github.com/repos/fisharebest/webtrees/issues/774/labels{/name}","comments_url":"https://api.github.com/repos/fisharebest/webtrees/issues/774/comments","events_url":"https://api.github.com/repos/fisharebest/webtrees/issues/774/events","html_url":"https://github.com/fisharebest/webtrees/issues/774","id":120546542,"number":774,"title":"Minor bug in gedcom import","user":{"login":"MikeT2","id":16164366,"avatar_url":"https://avatars.githubusercontent.com/u/16164366?v=3","gravatar_id":"","url":"https://api.github.com/users/MikeT2","html_url":"https://github.com/MikeT2","followers_url":"https://api.github.com/users/MikeT2/followers","following_url":"https://api.github.com/users/MikeT2/following{/other_user}","gists_url":"https://api.github.com/users/MikeT2/gists{/gist_id}","starred_url":"https://api.github.com/users/MikeT2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MikeT2/subscriptions","organizations_url":"https://api.github.com/users/MikeT2/orgs","repos_url":"https://api.github.com/users/MikeT2/repos","events_url":"https://api.github.com/users/MikeT2/events{/privacy}","received_events_url":"https://api.github.com/users/MikeT2/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-05T10:45:04Z","updated_at":"2016-01-04T13:06:07Z","closed_at":"2016-01-03T15:31:58Z","body":"I've come across a minor bug that occurs when importing a gedcom that contains media objects that are linked to several different records (e.g. a scan of a census or parish register). In previous versions of webtrees only one media object would be created, and all the individual or family records that referred to it would be linked to that one object. When you used the **Lists -> Media objects** feature of webtrees, each media object would be shown once, and all the individuals or families that referred to it would be listed under it.\r\n\r\nIn webtrees version 1.7.2 that's no longer the case if media objects don't have a title (TITL) set. In that case a separate media object is created for each reference, so a census scan that shows four individuals in a tree will be created as four separate, but identical media objects, and will be listed four times in a media objects list.\r\n\r\nI'm not sure exactly which version of webtrees introduced this bug, but it's certainly there in 1.7.2 and definitely wasn't there in 1.6.2.\r\n\r\nI've done some poking around and the problem occurs in app/Functions/FunctionImport.php in the **createMediaObject()** function which starts at line 1011. One of the first things that function does is check whether the media object reference that's being imported has a title attribute that isn't blank. If a non-blank title attribute isn't found, then the variable $titl is set equal to variable $file. The function then goes on to check whether a matching media object has already been created, but that check always fails because previously created records of that same media object all have blank title attributes in the database.\r\n\r\nI compared **createMediaObject()** in 1.7.2's app/Functions/FunctionImport.php with **create_media_object()** in 1.6.2's includes/functions/functions_import.php but couldn't find any significant difference. So I poked around a bit further and compared the **__construct()** function of the **Media** class in 1.7.2's app/Media.php with the **__construct()** function of the **WT_Media** class in 1.6.2's library/WT/Media.php. And there I found a significant difference.\r\n\r\nIn 1.6.2's library/WT/Media.php lines 43 to 52 look like this:\r\n\r\nif (preg_match('/\\n1 FILE (.+)/', $gedcom . $pending, $match)) {\r\n\t\t\t$this->file = $match[1];\r\n\t\t} else {\r\n\t\t\t$this->file = '';\r\n\t\t}\r\n\t\tif (preg_match('/\\n\\d TITL (.+)/', $gedcom . $pending, $match)) {\r\n\t\t\t$this->title = $match[1];\r\n\t\t} else {\r\n\t\t\t$this->title = $this->file;\r\n\t\t}\r\n\r\n\r\nbut in 1.7.2's app/Media.php lines 46 to 51 are these:\r\n\r\nif (preg_match('/\\n1 FILE (.+)/', $gedcom . $pending, $match)) {\r\n\t\t\t$this->file = $match[1];\r\n\t\t}\r\n\t\tif (preg_match('/\\n\\d TITL (.+)/', $gedcom . $pending, $match)) {\r\n\t\t\t$this->title = $match[1];\r\n\t\t}\r\n\r\n\r\nSo in 1.6.2 that's where blank title attributes are set equal to file attributes before new media objects are created in the database. Those lines are missing in the equivalent 1.7.2 code so the title attribute remains blank in the database.\r\n\r\nI was able to fix this bug by adding the extra lines from 1.6.2's library/WT/Media.php into 1.7.2's app/Media.php, but I'm not sure what other implications that change will have.\r\n### This section added to my WT forum post ###\r\nIt seems to me that, in version 1.7.2, the code at the start of the **createMediaObject()** function in app/Functions/FunctionImport.php (lines 1012 to 1022) must be the same as the code in the **__construct()** function of the **Media** class in app/Media.php (lines 46 to 51). Whether or not that code sets a blank title attribute equal to file will depend on implications elsewehere in WebTrees that I'm not aware of.\r\n\r\nI'm attaching a sample gedcom that demonstrates this bug (I've had to change the extension to txt as GitHub wouldn't accept ged).\r\n\r\n[test.txt](https://github.com/fisharebest/webtrees/files/52807/test.txt)\r\n\r\nI hope that helps,\r\n\r\nMike"},"comment":{"url":"https://api.github.com/repos/fisharebest/webtrees/issues/comments/168672924","html_url":"https://github.com/fisharebest/webtrees/issues/774#issuecomment-168672924","issue_url":"https://api.github.com/repos/fisharebest/webtrees/issues/774","id":168672924,"user":{"login":"MikeT2","id":16164366,"avatar_url":"https://avatars.githubusercontent.com/u/16164366?v=3","gravatar_id":"","url":"https://api.github.com/users/MikeT2","html_url":"https://github.com/MikeT2","followers_url":"https://api.github.com/users/MikeT2/followers","following_url":"https://api.github.com/users/MikeT2/following{/other_user}","gists_url":"https://api.github.com/users/MikeT2/gists{/gist_id}","starred_url":"https://api.github.com/users/MikeT2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MikeT2/subscriptions","organizations_url":"https://api.github.com/users/MikeT2/orgs","repos_url":"https://api.github.com/users/MikeT2/repos","events_url":"https://api.github.com/users/MikeT2/events{/privacy}","received_events_url":"https://api.github.com/users/MikeT2/received_events","type":"User","site_admin":false},"created_at":"2016-01-04T13:06:07Z","updated_at":"2016-01-04T13:06:07Z","body":"Thanks Greg!\n\nMike\n\n\nOn 3 January 2016 at 11:32, Greg Roach <notifications@github.com> wrote:\n\n> It seems to me that, in version 1.7.2, the code at the start of the\n> createMediaObject() function in app/Functions/FunctionImport.php (lines\n> 1012 to 1022) must be the same as the code in the __construct() function of\n> the Media class in app/Media.php (lines 46 to 51).\n>\n> I'd agree with this analysis.\n>\n> Whether or not that code sets a blank title attribute equal to file will\n> depend on implications elsewehere in WebTrees that I'm not aware of.\n>\n> There was a reason for not using the filename - but I forget what it\n> was....\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/fisharebest/webtrees/issues/774#issuecomment-168505750>\n> .\n>\n"}}