Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -597,8 +597,9 @@ |
598 | 598 | function getDefinedMeaningFromCollection($collectionId, $internalMemberId) { |
599 | 599 | $dc=wdGetDataSetContext(); |
600 | 600 | $dbr = &wfGetDB(DB_SLAVE); |
601 | | - $queryResult = $dbr->query("SELECT member_mid FROM {$dc}_collection_contents WHERE collection_id=$collectionId AND internal_member_id=". $dbr->addQuotes($internalMemberId) . |
602 | | - " AND " .getLatestTransactionRestriction("{$dc}_collection_contents")); |
| 601 | + $query = "SELECT member_mid FROM {$dc}_collection_contents WHERE collection_id=$collectionId AND internal_member_id=". $dbr->addQuotes($internalMemberId) . " AND " .getLatestTransactionRestriction("{$dc}_collection_contents"); |
| 602 | + echo "$query\n"; |
| 603 | + $queryResult = $dbr->query( $query ); |
603 | 604 | |
604 | 605 | if ($definedMeaningObject = $dbr->fetchObject($queryResult)) |
605 | 606 | return $definedMeaningObject->member_mid; |
— | — | @@ -1085,21 +1086,59 @@ |
1086 | 1087 | */ |
1087 | 1088 | |
1088 | 1089 | function createConceptMapping($concepts) { |
1089 | | - $uuid= getUUID(); |
| 1090 | + $uuid_map = getUUID($concepts); |
1090 | 1091 | foreach ($concepts as $dc => $dm_id) { |
1091 | 1092 | $collid=getCollectionIdForDC($dc); |
1092 | | - writeDmToCollection($dc, $collid, $uuid, $dm_id); |
| 1093 | + if ( $uuid_map[$dc] != -1 ){ |
| 1094 | + writeDmToCollection($dc, $collid, $uuid_map[$dc], $dm_id); |
| 1095 | + } |
1093 | 1096 | } |
1094 | 1097 | } |
1095 | 1098 | |
| 1099 | +function getMapping( $dc, $collid, $dm_id ){ |
| 1100 | + $dbr = &wfGetDB(DB_SLAVE); |
| 1101 | + $queryResult = $dbr->query( "select internal_member_id from {$dc}_collection_contents where collection_id = $collid AND member_mid = $dm_id" ); |
| 1102 | + if ( $record = $dbr->fetchObject($queryResult) ){ |
| 1103 | + return $record->internal_member_id; |
| 1104 | + } |
| 1105 | + else{ |
| 1106 | + return -1; |
| 1107 | + } |
| 1108 | +} |
| 1109 | + |
1096 | 1110 | /** ask db to provide a universally unique id */ |
1097 | 1111 | |
1098 | | -function getUUID() { |
1099 | | - $dbr = & wfGetDB(DB_SLAVE); |
1100 | | - $query="SELECT uuid() AS id"; |
1101 | | - $queryResult = $dbr->query($query); |
1102 | | - $row=$dbr->fetchObject($queryResult); |
1103 | | - return isset($row->id) ? $row->id : null; |
| 1112 | +function getUUID($concepts) { |
| 1113 | + $dbr = & wfGetDB(DB_SLAVE); |
| 1114 | + |
| 1115 | + $uuid_array = array(); |
| 1116 | + $uuid = -1; |
| 1117 | + |
| 1118 | + foreach ($concepts as $dc => $dm_id) { |
| 1119 | + $collid = getCollectionIdForDC($dc); |
| 1120 | + $uuid_array[$dc] = getMapping( $dc, $collid, $dm_id ); |
| 1121 | + if ( ( $uuid == -1 ) && ( $uuid_array[$dc] != -1 ) ){ |
| 1122 | + $uuid = $uuid_array[$dc]; |
| 1123 | + } |
| 1124 | + } |
| 1125 | + |
| 1126 | + if ( $uuid == -1 ){ |
| 1127 | + $query="SELECT uuid() AS id"; |
| 1128 | + $queryResult = $dbr->query($query); |
| 1129 | + $row=$dbr->fetchObject($queryResult); |
| 1130 | + $uuid = isset($row->id) ? $row->id : -1; |
| 1131 | + } |
| 1132 | + |
| 1133 | + foreach ($concepts as $dc => $dm_id) { |
| 1134 | + if ( $uuid_array[$dc] == -1 ){ |
| 1135 | + $uuid_array[$dc] = $uuid; |
| 1136 | + } |
| 1137 | + else{ |
| 1138 | + $uuid_array[$dc] = -1; |
| 1139 | + } |
| 1140 | + } |
| 1141 | + |
| 1142 | + return $uuid_array; |
1104 | 1143 | } |
1105 | 1144 | |
1106 | 1145 | /** this funtion assumes that there is only a single mapping collection */ |