Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -26,17 +26,17 @@ |
27 | 27 | return createPage($expressionNameSpaceId, getPageTitle($this->spelling)); |
28 | 28 | } |
29 | 29 | |
30 | | - function isBoundToDefinedMeaning($definedMeaningId, $dc=null) { |
31 | | - return expressionIsBoundToDefinedMeaning($definedMeaningId, $this->id, $dc); |
| 30 | + function isBoundToDefinedMeaning($definedMeaningId) { |
| 31 | + return expressionIsBoundToDefinedMeaning($definedMeaningId, $this->id); |
32 | 32 | } |
33 | 33 | |
34 | | - function bindToDefinedMeaning($definedMeaningId, $identicalMeaning, $dc=null) { |
35 | | - createSynonymOrTranslation($definedMeaningId, $this->id, $identicalMeaning, $dc); |
| 34 | + function bindToDefinedMeaning($definedMeaningId, $identicalMeaning) { |
| 35 | + createSynonymOrTranslation($definedMeaningId, $this->id, $identicalMeaning); |
36 | 36 | } |
37 | 37 | |
38 | | - function assureIsBoundToDefinedMeaning($definedMeaningId, $identicalMeaning, $dc=null) { |
39 | | - if (!$this->isBoundToDefinedMeaning($definedMeaningId, $dc)) |
40 | | - $this->bindToDefinedMeaning($definedMeaningId, $identicalMeaning, $dc); |
| 38 | + function assureIsBoundToDefinedMeaning($definedMeaningId, $identicalMeaning) { |
| 39 | + if (!$this->isBoundToDefinedMeaning($definedMeaningId)) |
| 40 | + $this->bindToDefinedMeaning($definedMeaningId, $identicalMeaning); |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | |
60 | 60 | $dbr = &wfGetDB(DB_MASTER); |
61 | 61 | $dbr->query("INSERT INTO {$dc}_objects (`table`, `UUID`) VALUES (". $dbr->addQuotes($table) . ", UUID())"); |
62 | | - |
| 62 | + |
63 | 63 | return $dbr->insertId(); |
64 | 64 | } |
65 | 65 | |
— | — | @@ -73,14 +73,14 @@ |
74 | 74 | ); |
75 | 75 | |
76 | 76 | if ($objectRecord = $dbr->fetchObject($queryResult)) |
77 | | - return $objectRecord->table; |
| 77 | + return $objectRecord->table; |
78 | 78 | else |
79 | 79 | return ""; |
80 | 80 | } |
81 | 81 | |
82 | | -function getExpressionId($spelling, $languageId, $dc=null) { |
| 82 | +function getExpressionId($spelling, $languageId) { |
83 | 83 | |
84 | | - $dc=wdGetDataSetContext($dc); |
| 84 | + $dc=wdGetDataSetContext(); |
85 | 85 | |
86 | 86 | $dbr = &wfGetDB(DB_SLAVE); |
87 | 87 | $sql = "SELECT expression_id FROM {$dc}_expression_ns " . |
— | — | @@ -91,10 +91,9 @@ |
92 | 92 | return isset($expression->expression_id) ? $expression->expression_id : null; |
93 | 93 | } |
94 | 94 | |
95 | | -function createExpressionId($spelling, $languageId, $dc=null) { |
| 95 | +function createExpressionId($spelling, $languageId) { |
96 | 96 | |
97 | | - $dc=wdGetDataSetContext($dc); |
98 | | - wfDebug("Context : $dc"); |
| 97 | + $dc=wdGetDataSetContext(); |
99 | 98 | |
100 | 99 | $expressionId = newObjectId("{$dc}_expression_ns"); |
101 | 100 | |
— | — | @@ -115,11 +114,20 @@ |
116 | 115 | $title = $dbr->addQuotes($title); |
117 | 116 | $timestamp = $dbr->timestamp(); |
118 | 117 | |
119 | | - $sql = "insert into page(page_namespace,page_title,page_is_new,page_touched) ". |
120 | | - "values($namespace, $title, 1, $timestamp)"; |
121 | | - $dbr->query($sql); |
122 | | - |
123 | | - return $dbr->insertId(); |
| 118 | + echo "createPage(): namespace = $namespace and title = $title\n"; |
| 119 | + $sql = "select page_id from page where page_namespace = $namespace and page_title = $title"; |
| 120 | + $queryResult = $dbr->query($sql); |
| 121 | + $page = $dbr->fetchObject($queryResult); |
| 122 | + if (isset($page->page_id) ){ |
| 123 | + return $page->page_id; |
| 124 | + } |
| 125 | + else{ |
| 126 | + $sql = "insert into page(page_namespace,page_title,page_is_new,page_touched) ". |
| 127 | + "values($namespace, $title, 1, $timestamp)"; |
| 128 | + $dbr->query($sql); |
| 129 | + |
| 130 | + return $dbr->insertId(); |
| 131 | + } |
124 | 132 | } |
125 | 133 | |
126 | 134 | function setPageLatestRevision($pageId, $latestRevision) { |
— | — | @@ -147,24 +155,29 @@ |
148 | 156 | return $revisionId; |
149 | 157 | } |
150 | 158 | |
151 | | -function findExpression($spelling, $languageId, $dc=null) { |
152 | | - if ($expressionId = getExpressionId($spelling, $languageId, $dc)) |
| 159 | +function findExpression($spelling, $languageId) { |
| 160 | + wfDebug( "findExpression $spelling" ); |
| 161 | + if ($expressionId = getExpressionId($spelling, $languageId)){ |
| 162 | + //wfDebug( "expression $spelling found in database" ); |
| 163 | + //exit(); |
153 | 164 | return new Expression($expressionId, $spelling, $languageId); |
154 | | - else |
| 165 | + } |
| 166 | + else{ |
155 | 167 | return null; |
| 168 | + } |
156 | 169 | } |
157 | 170 | |
158 | | -function createExpression($spelling, $languageId, $dc=null) { |
159 | | - $expression = new Expression(createExpressionId($spelling, $languageId, $dc), $spelling, $languageId); |
| 171 | +function createExpression($spelling, $languageId) { |
| 172 | + $expression = new Expression(createExpressionId($spelling, $languageId), $spelling, $languageId); |
160 | 173 | $expression->createNewInDatabase(); |
161 | 174 | return $expression; |
162 | 175 | } |
163 | 176 | |
164 | | -function findOrCreateExpression($spelling, $languageId, $dc=null) { |
165 | | - if ($expression = findExpression($spelling, $languageId, $dc)) |
| 177 | +function findOrCreateExpression($spelling, $languageId) { |
| 178 | + if ($expression = findExpression($spelling, $languageId)) |
166 | 179 | return $expression; |
167 | 180 | else |
168 | | - return createExpression($spelling, $languageId, $dc); |
| 181 | + return createExpression($spelling, $languageId); |
169 | 182 | } |
170 | 183 | |
171 | 184 | function getSynonymId($definedMeaningId, $expressionId) { |
— | — | @@ -179,9 +192,9 @@ |
180 | 193 | return 0; |
181 | 194 | } |
182 | 195 | |
183 | | -function createSynonymOrTranslation($definedMeaningId, $expressionId, $identicalMeaning, $dc=null) { |
| 196 | +function createSynonymOrTranslation($definedMeaningId, $expressionId, $identicalMeaning) { |
184 | 197 | |
185 | | - $dc=wdGetDataSetContext($dc); |
| 198 | + $dc=wdGetDataSetContext(); |
186 | 199 | |
187 | 200 | $synonymId = getSynonymId($definedMeaningId, $expressionId); |
188 | 201 | |
— | — | @@ -195,8 +208,8 @@ |
196 | 209 | $queryResult = $dbr->query($sql); |
197 | 210 | } |
198 | 211 | |
199 | | -function expressionIsBoundToDefinedMeaning($definedMeaningId, $expressionId, $dc=null) { |
200 | | - $dc=wdGetDataSetContext($dc); |
| 212 | +function expressionIsBoundToDefinedMeaning($definedMeaningId, $expressionId) { |
| 213 | + $dc=wdGetDataSetContext(); |
201 | 214 | $dbr = &wfGetDB(DB_SLAVE); |
202 | 215 | $queryResult = $dbr->query("SELECT expression_id FROM {$dc}_syntrans WHERE expression_id=$expressionId AND defined_meaning_id=$definedMeaningId AND ". getLatestTransactionRestriction("{$dc}_syntrans") ." LIMIT 1"); |
203 | 216 | |
— | — | @@ -432,8 +445,8 @@ |
433 | 446 | addTranslatedText($setId, $languageId, $text); |
434 | 447 | } |
435 | 448 | |
436 | | -function createText($text, $dc=null) { |
437 | | - $dc=wdGetDataSetContext($dc); |
| 449 | +function createText($text) { |
| 450 | + $dc=wdGetDataSetContext(); |
438 | 451 | $dbr = &wfGetDB(DB_MASTER); |
439 | 452 | $text = $dbr->addQuotes($text); |
440 | 453 | $sql = "insert into {$dc}_text(text_text) values($text)"; |
— | — | @@ -442,8 +455,8 @@ |
443 | 456 | return $dbr->insertId(); |
444 | 457 | } |
445 | 458 | |
446 | | -function createTranslatedContent($translatedContentId, $languageId, $textId, $dc=null) { |
447 | | - $dc=wdGetDataSetContext($dc); |
| 459 | +function createTranslatedContent($translatedContentId, $languageId, $textId) { |
| 460 | + $dc=wdGetDataSetContext(); |
448 | 461 | |
449 | 462 | $dbr = &wfGetDB(DB_MASTER); |
450 | 463 | $sql = "insert into {$dc}_translated_content(translated_content_id,language_id,text_id,add_transaction_id) values($translatedContentId, $languageId, $textId, ". getUpdateTransactionId() .")"; |
— | — | @@ -452,8 +465,8 @@ |
453 | 466 | return $dbr->insertId(); |
454 | 467 | } |
455 | 468 | |
456 | | -function translatedTextExists($textId, $languageId, $dc=null) { |
457 | | - $dc=wdGetDataSetContext($dc); |
| 469 | +function translatedTextExists($textId, $languageId) { |
| 470 | + $dc=wdGetDataSetContext(); |
458 | 471 | $dbr = &wfGetDB(DB_SLAVE); |
459 | 472 | $queryResult = $dbr->query( |
460 | 473 | "SELECT translated_content_id" . |
— | — | @@ -466,18 +479,18 @@ |
467 | 480 | return $dbr->numRows($queryResult) > 0; |
468 | 481 | } |
469 | 482 | |
470 | | -function addTranslatedText($translatedContentId, $languageId, $text,$dc=null) { |
471 | | - $textId = createText($text, $dc); |
472 | | - createTranslatedContent($translatedContentId, $languageId, $textId, $dc); |
| 483 | +function addTranslatedText($translatedContentId, $languageId, $text) { |
| 484 | + $textId = createText($text); |
| 485 | + createTranslatedContent($translatedContentId, $languageId, $textId); |
473 | 486 | } |
474 | 487 | |
475 | | -function addTranslatedTextIfNotPresent($translatedContentId, $languageId, $text, $dc=null) { |
476 | | - if (!translatedTextExists($translatedContentId, $languageId, $dc)) |
477 | | - addTranslatedText($translatedContentId, $languageId, $text, $dc); |
| 488 | +function addTranslatedTextIfNotPresent($translatedContentId, $languageId, $text) { |
| 489 | + if (!translatedTextExists($translatedContentId, $languageId)) |
| 490 | + addTranslatedText($translatedContentId, $languageId, $text); |
478 | 491 | } |
479 | 492 | |
480 | | -function getDefinedMeaningDefinitionId($definedMeaningId, $dc=null) { |
481 | | - $dc=wdGetDataSetContext($dc); |
| 493 | +function getDefinedMeaningDefinitionId($definedMeaningId) { |
| 494 | + $dc=wdGetDataSetContext(); |
482 | 495 | $dbr = &wfGetDB(DB_SLAVE); |
483 | 496 | $queryResult = $dbr->query("SELECT meaning_text_tcid FROM {$dc}_defined_meaning WHERE defined_meaning_id=$definedMeaningId " . |
484 | 497 | " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning")); |
— | — | @@ -485,9 +498,9 @@ |
486 | 499 | return $dbr->fetchObject($queryResult)->meaning_text_tcid; |
487 | 500 | } |
488 | 501 | |
489 | | -function updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId, $dc=null) { |
| 502 | +function updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId) { |
490 | 503 | $dbr = &wfGetDB(DB_MASTER); |
491 | | - $dc=wdGetDataSetContext($dc); |
| 504 | + $dc=wdGetDataSetContext(); |
492 | 505 | $dbr->query("UPDATE {$dc}_defined_meaning SET meaning_text_tcid=$definitionId WHERE defined_meaning_id=$definedMeaningId" . |
493 | 506 | " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning")); |
494 | 507 | } |
— | — | @@ -497,19 +510,19 @@ |
498 | 511 | return newObjectId("{$dc}_translated_content"); |
499 | 512 | } |
500 | 513 | |
501 | | -function addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text, $dc=null) { |
| 514 | +function addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text) { |
502 | 515 | $definitionId = newTranslatedContentId(); |
503 | | - addTranslatedText($definitionId, $languageId, $text, $dc); |
504 | | - updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId, $dc); |
| 516 | + addTranslatedText($definitionId, $languageId, $text); |
| 517 | + updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId); |
505 | 518 | } |
506 | 519 | |
507 | | -function addDefinedMeaningDefinition($definedMeaningId, $languageId, $text, $dc=null) { |
508 | | - $definitionId = getDefinedMeaningDefinitionId($definedMeaningId, $dc); |
| 520 | +function addDefinedMeaningDefinition($definedMeaningId, $languageId, $text) { |
| 521 | + $definitionId = getDefinedMeaningDefinitionId($definedMeaningId); |
509 | 522 | |
510 | 523 | if ($definitionId == 0) |
511 | | - addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text, $dc); |
| 524 | + addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text); |
512 | 525 | else |
513 | | - addTranslatedTextIfNotPresent($definitionId, $languageId, $text, $dc); |
| 526 | + addTranslatedTextIfNotPresent($definitionId, $languageId, $text); |
514 | 527 | } |
515 | 528 | |
516 | 529 | function createDefinedMeaningAlternativeDefinition($definedMeaningId, $translatedContentId, $sourceMeaningId) { |
— | — | @@ -607,12 +620,12 @@ |
608 | 621 | addDefinedMeaningToCollection($definedMeaningId, $collectionId, $internalId); |
609 | 622 | } |
610 | 623 | |
611 | | -function bootstrapCollection($collection, $languageId, $collectionType,$dc=null){ |
612 | | - $expression = findOrCreateExpression($collection, $languageId, $dc); |
613 | | - $definedMeaningId = addDefinedMeaning($expression->id, $dc); |
614 | | - $expression->assureIsBoundToDefinedMeaning($definedMeaningId, true, $dc); |
615 | | - addDefinedMeaningDefinition($definedMeaningId, $languageId, $collection, $dc); |
616 | | - return addCollection($definedMeaningId, $collectionType, $dc); |
| 624 | +function bootstrapCollection($collection, $languageId, $collectionType){ |
| 625 | + $expression = findOrCreateExpression($collection, $languageId); |
| 626 | + $definedMeaningId = addDefinedMeaning($expression->id); |
| 627 | + $expression->assureIsBoundToDefinedMeaning($definedMeaningId, true); |
| 628 | + addDefinedMeaningDefinition($definedMeaningId, $languageId, $collection); |
| 629 | + return addCollection($definedMeaningId, $collectionType); |
617 | 630 | } |
618 | 631 | |
619 | 632 | function getCollectionMeaningId($collectionId) { |
— | — | @@ -633,8 +646,8 @@ |
634 | 647 | return $dbr->fetchObject($queryResult)->collection_id; |
635 | 648 | } |
636 | 649 | |
637 | | -function addCollection($definedMeaningId, $collectionType, $dc=null) { |
638 | | - $dc=wdGetDataSetContext($dc); |
| 650 | +function addCollection($definedMeaningId, $collectionType) { |
| 651 | + $dc=wdGetDataSetContext(); |
639 | 652 | $collectionId = newObjectId("{$dc}_collection_ns"); |
640 | 653 | |
641 | 654 | $dbr = &wfGetDB(DB_MASTER); |
— | — | @@ -644,15 +657,18 @@ |
645 | 658 | return $collectionId; |
646 | 659 | } |
647 | 660 | |
648 | | -function addDefinedMeaning($definingExpressionId, $dc=null) { |
| 661 | +function addDefinedMeaning($definingExpressionId) { |
649 | 662 | $definedMeaningNameSpaceId = Namespace::getIndexForName('definedmeaning'); |
650 | | - $dc=wdGetDataSetContext($dc); |
| 663 | + $dc=wdGetDataSetContext(); |
651 | 664 | |
652 | 665 | $definedMeaningId = newObjectId("{$dc}_defined_meaning"); |
653 | 666 | |
| 667 | + //wfDebug( "addDefinedMeaning(): $definedMeaningId has to be inserted to the database $dc" ); |
654 | 668 | $dbr = &wfGetDB(DB_MASTER); |
655 | 669 | $dbr->query("INSERT INTO {$dc}_defined_meaning(defined_meaning_id, expression_id, add_transaction_id) values($definedMeaningId, $definingExpressionId, ". getUpdateTransactionId() .")"); |
656 | | - |
| 670 | + |
| 671 | + //wfDebug( "addDefinedMeaning(): after $definedMeaningId has been inserted in the database" ); |
| 672 | + |
657 | 673 | $expression = getExpression($definingExpressionId); |
658 | 674 | $pageId = createPage($definedMeaningNameSpaceId, getPageTitle("$expression->spelling ($definedMeaningId)")); |
659 | 675 | createInitialRevisionForPage($pageId, 'Created by adding defined meaning'); |
— | — | @@ -760,8 +776,8 @@ |
761 | 777 | "VALUES ($valueId, $objectId, $attributeId, $translatedContentId, ". getUpdateTransactionId() .")"); |
762 | 778 | } |
763 | 779 | |
764 | | -function addTranslatedTextAttributeValue($objectId, $attributeId, $languageId, $text, $dc) { |
765 | | - $dc=wdGetDataSetContext($dc); |
| 780 | +function addTranslatedTextAttributeValue($objectId, $attributeId, $languageId, $text) { |
| 781 | + $dc=wdGetDataSetContext(); |
766 | 782 | $translatedTextValueAttributeId = newObjectId("{$dc}_translated_content_attribute_values"); |
767 | 783 | $translatedContentId = newTranslatedContentId(); |
768 | 784 | |
— | — | @@ -1167,8 +1183,6 @@ |
1168 | 1184 | $dc=wdGetDataSetContext(); |
1169 | 1185 | } |
1170 | 1186 | $collection_id=getCollectionIdForDC($dc); |
1171 | | - if (is_null($collection_id)) |
1172 | | - return null; |
1173 | 1187 | $dbr = & wfGetDB(DB_SLAVE); |
1174 | 1188 | $dm=$dbr->addQuotes($dm); |
1175 | 1189 | $query = " |
— | — | @@ -1177,7 +1191,7 @@ |
1178 | 1192 | WHERE member_mid=$dm |
1179 | 1193 | AND collection_id=$collection_id; |
1180 | 1194 | "; |
1181 | | - $queryResult = $dbr->query($query,"getConceptId"); |
| 1195 | + $queryResult = $dbr->query($query); |
1182 | 1196 | $row=$dbr->fetchObject($queryResult); |
1183 | 1197 | return isset($row->concept_id) ? $row->concept_id : null; |
1184 | 1198 | } |