r23732 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23731‎ | r23732 | r23733 >
Date:13:01, 5 July 2007
Author:mulligen
Status:old
Tags:
Comment:
updated getUUID and createConceptMapping so that they see if a mapping has already been defined.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -597,8 +597,9 @@
598598 function getDefinedMeaningFromCollection($collectionId, $internalMemberId) {
599599 $dc=wdGetDataSetContext();
600600 $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 );
603604
604605 if ($definedMeaningObject = $dbr->fetchObject($queryResult))
605606 return $definedMeaningObject->member_mid;
@@ -1085,21 +1086,59 @@
10861087 */
10871088
10881089 function createConceptMapping($concepts) {
1089 - $uuid= getUUID();
 1090+ $uuid_map = getUUID($concepts);
10901091 foreach ($concepts as $dc => $dm_id) {
10911092 $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+ }
10931096 }
10941097 }
10951098
 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+
10961110 /** ask db to provide a universally unique id */
10971111
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;
11041143 }
11051144
11061145 /** this funtion assumes that there is only a single mapping collection */

Status & tagging log