Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | define( 'NS_EXPRESSION', 16 ); |
| 5 | +define( 'NS_DEFINEDMEANING', 24 ); |
5 | 6 | |
6 | 7 | require_once( "Wikidata.php" ); |
7 | 8 | |
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | require_once( 'Transaction.php' ); |
| 5 | +require_once( 'WikiDataGlobals.php' ); |
5 | 6 | |
6 | 7 | class Expression { |
7 | 8 | public $id; |
— | — | @@ -54,6 +55,7 @@ |
55 | 56 | while ( $syntransRecord = $dbr->fetchObject( $queryResult ) ) { |
56 | 57 | $this->meaningIds[] = $syntransRecord->defined_meaning_id; |
57 | 58 | } |
| 59 | + $dbr->freeResult( $queryResult ) ; |
58 | 60 | } |
59 | 61 | |
60 | 62 | } |
— | — | @@ -64,9 +66,9 @@ |
65 | 67 | $dbr = wfGetDB( DB_SLAVE ); |
66 | 68 | $queryResult = $dbr->query( "SELECT spelling, language_id " . |
67 | 69 | " FROM {$dc}_expression " . |
68 | | - " WHERE {$dc}_expression.expression_id=$expressionId" . |
69 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) ); |
| 70 | + " WHERE {$dc}_expression.expression_id=$expressionId LIMIT 1" ); |
70 | 71 | $expressionRecord = $dbr->fetchObject( $queryResult ); |
| 72 | + $dbr->freeResult( $queryResult ) ; |
71 | 73 | if ( $expressionRecord ) { |
72 | 74 | $expression = new Expression( $expressionId, $expressionRecord->spelling, $expressionRecord->language_id ); |
73 | 75 | return $expression; |
— | — | @@ -78,10 +80,10 @@ |
79 | 81 | function newObjectId( $table ) { |
80 | 82 | $dc = wdGetDataSetContext(); |
81 | 83 | |
82 | | - $dbr = wfGetDB( DB_MASTER ); |
83 | | - $dbr->query( "INSERT INTO {$dc}_objects (`table`, `UUID`) VALUES (" . $dbr->addQuotes( $table ) . ", UUID())" ); |
| 84 | + $dbw = wfGetDB( DB_MASTER ); |
| 85 | + $dbw->query( "INSERT INTO {$dc}_objects (`table`, `UUID`) VALUES (" . $dbw->addQuotes( $table ) . ", UUID())" ); |
84 | 86 | |
85 | | - return $dbr->insertId(); |
| 87 | + return $dbw->insertId(); |
86 | 88 | } |
87 | 89 | |
88 | 90 | function getTableNameWithObjectId( $objectId ) { |
— | — | @@ -107,7 +109,7 @@ |
108 | 110 | $dbr = wfGetDB( DB_SLAVE ); |
109 | 111 | $sql = "SELECT expression_id FROM {$dc}_expression " . |
110 | 112 | 'WHERE spelling=binary ' . $dbr->addQuotes( $spelling ) . ' AND language_id=' . $languageId . |
111 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ); |
| 113 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ) . " LIMIT 1 " ; |
112 | 114 | $queryResult = $dbr->query( $sql ); |
113 | 115 | $expression = $dbr->fetchObject( $queryResult ); |
114 | 116 | return isset( $expression->expression_id ) ? $expression->expression_id : null; |
— | — | @@ -119,10 +121,10 @@ |
120 | 122 | |
121 | 123 | $expressionId = newObjectId( "{$dc}_expression" ); |
122 | 124 | |
123 | | - $dbr = wfGetDB( DB_MASTER ); |
124 | | - $spelling = $dbr->addQuotes( $spelling ); |
| 125 | + $dbw = wfGetDB( DB_MASTER ); |
| 126 | + $spelling = $dbw->addQuotes( $spelling ); |
125 | 127 | |
126 | | - $dbr->query( "INSERT INTO {$dc}_expression(expression_id, spelling, language_id, add_transaction_id) values($expressionId, $spelling, $languageId, " . getUpdateTransactionId() . ")" ); |
| 128 | + $dbw->query( "INSERT INTO {$dc}_expression(expression_id, spelling, language_id, add_transaction_id) values($expressionId, $spelling, $languageId, " . getUpdateTransactionId() . ")" ); |
127 | 129 | |
128 | 130 | return $expressionId; |
129 | 131 | } |
— | — | @@ -133,48 +135,47 @@ |
134 | 136 | |
135 | 137 | |
136 | 138 | function createPage( $namespace, $title ) { |
137 | | - $dbr = wfGetDB( DB_MASTER ); |
138 | | - $title = $dbr->addQuotes( $title ); |
139 | | - $timestamp = $dbr->timestamp(); |
| 139 | + $dbw = wfGetDB( DB_MASTER ); |
| 140 | + $title = $dbw->addQuotes( $title ); |
| 141 | + $timestamp = $dbw->timestamp(); |
140 | 142 | $sql = "select page_id from page where page_namespace = $namespace and page_title = $title"; |
141 | | - $queryResult = $dbr->query( $sql ); |
142 | | - $page = $dbr->fetchObject( $queryResult ); |
| 143 | + $queryResult = $dbw->query( $sql ); |
| 144 | + $page = $dbw->fetchObject( $queryResult ); |
143 | 145 | if ( isset( $page->page_id ) ) { |
144 | 146 | return $page->page_id; |
145 | 147 | } |
146 | 148 | else { |
147 | 149 | $sql = "insert into page(page_namespace,page_title,page_is_new,page_touched) " . |
148 | 150 | "values($namespace, $title, 1, $timestamp)"; |
149 | | - $dbr->query( $sql ); |
150 | | - return $dbr->insertId(); |
| 151 | + $dbw->query( $sql ); |
| 152 | + return $dbw->insertId(); |
151 | 153 | } |
152 | 154 | } |
153 | 155 | |
154 | 156 | function setPageLatestRevision( $pageId, $latestRevision ) { |
155 | | - $dbr = wfGetDB( DB_MASTER ); |
| 157 | + $dbw = wfGetDB( DB_MASTER ); |
156 | 158 | $sql = "update page set page_latest=$latestRevision where page_id=$pageId"; |
157 | | - $dbr->query( $sql ); |
| 159 | + $dbw->query( $sql ); |
158 | 160 | } |
159 | 161 | function createInitialRevisionForPage( $pageId, $comment ) { |
160 | | - global |
161 | | - $wgUser; |
| 162 | + global $wgUser; |
162 | 163 | |
163 | | - $dbr = wfGetDB( DB_MASTER ); |
| 164 | + $dbw = wfGetDB( DB_MASTER ); |
164 | 165 | $userId = $wgUser->getID(); |
165 | | - $userName = $dbr->addQuotes( $wgUser->getName() ); |
166 | | - $comment = $dbr->addQuotes( $comment ); |
167 | | - $timestamp = $dbr->timestamp(); |
| 166 | + $userName = $dbw->addQuotes( $wgUser->getName() ); |
| 167 | + $comment = $dbw->addQuotes( $comment ); |
| 168 | + $timestamp = $dbw->timestamp(); |
168 | 169 | |
169 | 170 | $sql = "insert into revision(rev_page,rev_comment,rev_user,rev_user_text,rev_timestamp) " . |
170 | 171 | "values($pageId, $comment, $userId, $userName, $timestamp)"; |
171 | | - $dbr->query( $sql ); |
| 172 | + $dbw->query( $sql ); |
172 | 173 | |
173 | | - $revisionId = $dbr->insertId(); |
| 174 | + $revisionId = $dbw->insertId(); |
174 | 175 | setPageLatestRevision( $pageId, $revisionId ); |
175 | 176 | |
176 | 177 | return $revisionId; |
177 | 178 | } |
178 | | - |
| 179 | + |
179 | 180 | function findExpression( $spelling, $languageId ) { |
180 | 181 | if ( $expressionId = getExpressionId( $spelling, $languageId ) ) { |
181 | 182 | return new Expression( $expressionId, $spelling, $languageId ); |
— | — | @@ -200,13 +201,12 @@ |
201 | 202 | return createExpression( $spelling, $languageId ); |
202 | 203 | } |
203 | 204 | |
204 | | - |
205 | | - |
206 | 205 | function getSynonymId( $definedMeaningId, $expressionId ) { |
207 | 206 | $dc = wdGetDataSetContext(); |
208 | 207 | $dbr = wfGetDB( DB_SLAVE ); |
209 | 208 | $queryResult = $dbr->query( "SELECT syntrans_sid FROM {$dc}_syntrans " . |
210 | | - "WHERE defined_meaning_id=$definedMeaningId AND expression_id=$expressionId LIMIT 1" ); |
| 209 | + "WHERE defined_meaning_id=$definedMeaningId AND expression_id=$expressionId " . |
| 210 | + getLatestTransactionRestriction( "{$dc}_syntrans" ) . " LIMIT 1" ); |
211 | 211 | |
212 | 212 | if ( $synonym = $dbr->fetchObject( $queryResult ) ) |
213 | 213 | return $synonym->syntrans_sid; |
— | — | @@ -223,16 +223,15 @@ |
224 | 224 | if ( $synonymId == 0 ) |
225 | 225 | $synonymId = newObjectId( "{$dc}_syntrans" ); |
226 | 226 | |
227 | | - $dbr = wfGetDB( DB_MASTER ); |
| 227 | + $dbw = wfGetDB( DB_MASTER ); |
228 | 228 | $identicalMeaningInteger = (int) $identicalMeaning; |
229 | 229 | $sql = "insert into {$dc}_syntrans(syntrans_sid, defined_meaning_id, expression_id, identical_meaning, add_transaction_id) " . |
230 | 230 | "values($synonymId, $definedMeaningId, $expressionId, $identicalMeaningInteger, " . getUpdateTransactionId() . ")"; |
231 | | - $queryResult = $dbr->query( $sql ); |
| 231 | + $queryResult = $dbw->query( $sql ); |
232 | 232 | } |
233 | 233 | |
234 | 234 | function expressionIsBoundToDefinedMeaning( $definedMeaningId, $expressionId ) { |
235 | | - global |
236 | | - $dataSet; |
| 235 | + global $dataSet; |
237 | 236 | |
238 | 237 | $dc = wdGetDataSetContext(); |
239 | 238 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -285,7 +284,7 @@ |
286 | 285 | $dbr = wfGetDB( DB_SLAVE ); |
287 | 286 | $queryResult = $dbr->query( "SELECT meaning1_mid FROM {$dc}_meaning_relations " . |
288 | 287 | "WHERE meaning1_mid=$definedMeaning1Id AND meaning2_mid=$definedMeaning2Id AND relationtype_mid=$relationTypeId " . |
289 | | - "AND " . getLatestTransactionRestriction( "{$dc}_meaning_relations" ) ); |
| 288 | + "AND " . getLatestTransactionRestriction( "{$dc}_meaning_relations" ) . " LIMIT 1" ); |
290 | 289 | |
291 | 290 | return $dbr->numRows( $queryResult ) > 0; |
292 | 291 | } |
— | — | @@ -298,10 +297,10 @@ |
299 | 298 | if ( $relationId == 0 ) |
300 | 299 | $relationId = newObjectId( "{$dc}_meaning_relations" ); |
301 | 300 | |
302 | | - $dbr = wfGetDB( DB_MASTER ); |
| 301 | + $dbw = wfGetDB( DB_MASTER ); |
303 | 302 | $sql = "INSERT INTO {$dc}_meaning_relations(relation_id, meaning1_mid, meaning2_mid, relationtype_mid, add_transaction_id) " . |
304 | 303 | " VALUES ($relationId, $definedMeaning1Id, $definedMeaning2Id, $relationTypeId, " . getUpdateTransactionId() . ")"; |
305 | | - $dbr->query( $sql ); |
| 304 | + $dbw->query( $sql ); |
306 | 305 | } |
307 | 306 | |
308 | 307 | function addRelation( $definedMeaning1Id, $relationTypeId, $definedMeaning2Id ) { |
— | — | @@ -311,16 +310,16 @@ |
312 | 311 | |
313 | 312 | function removeRelation( $definedMeaning1Id, $relationTypeId, $definedMeaning2Id ) { |
314 | 313 | $dc = wdGetDataSetContext(); |
315 | | - $dbr = wfGetDB( DB_MASTER ); |
316 | | - $dbr->query( "UPDATE {$dc}_meaning_relations SET remove_transaction_id=" . getUpdateTransactionId() . |
| 314 | + $dbw = wfGetDB( DB_MASTER ); |
| 315 | + $dbw->query( "UPDATE {$dc}_meaning_relations SET remove_transaction_id=" . getUpdateTransactionId() . |
317 | 316 | " WHERE meaning1_mid=$definedMeaning1Id AND meaning2_mid=$definedMeaning2Id AND relationtype_mid=$relationTypeId " . |
318 | 317 | " AND remove_transaction_id IS NULL" ); |
319 | 318 | } |
320 | 319 | |
321 | 320 | function removeRelationWithId( $relationId ) { |
322 | 321 | $dc = wdGetDataSetContext(); |
323 | | - $dbr = wfGetDB( DB_MASTER ); |
324 | | - $dbr->query( "UPDATE {$dc}_meaning_relations SET remove_transaction_id=" . getUpdateTransactionId() . |
| 322 | + $dbw = wfGetDB( DB_MASTER ); |
| 323 | + $dbw->query( "UPDATE {$dc}_meaning_relations SET remove_transaction_id=" . getUpdateTransactionId() . |
325 | 324 | " WHERE relation_id=$relationId " . |
326 | 325 | " AND remove_transaction_id IS NULL" ); |
327 | 326 | } |
— | — | @@ -336,13 +335,13 @@ |
337 | 336 | * @param unknown_type $relationTypeId dmid of the relationtype, optional. |
338 | 337 | * @param unknown_type $lhs dmid of the left hand side, optional. |
339 | 338 | * @param unknown_type $dmId dmid of the right hand side, optional. |
340 | | - * * @param unknown_type $dc the dataset, optional |
| 339 | + * @param unknown_type $dc the dataset, optional |
341 | 340 | */ |
342 | 341 | function getRelationDefinedMeanings( $relationTypeId = null, $lhs = null, $rhs = null, $dc = null ) { |
343 | 342 | $result = array(); |
344 | 343 | |
345 | 344 | $dc = wdGetDataSetContext( $dc ); |
346 | | - $dbr = wfGetDB( DB_MASTER ); |
| 345 | + $dbr = wfGetDB( DB_SLAVE ); |
347 | 346 | if ( $relationTypeId == null ) { |
348 | 347 | if ( $lhs == null ) { |
349 | 348 | if ( $rhs == null ) return $result; |
— | — | @@ -390,7 +389,8 @@ |
391 | 390 | while ( $row = $dbr->fetchRow( $queryResult ) ) { |
392 | 391 | $result[] = $row[0]; |
393 | 392 | } |
394 | | - |
| 393 | + $dbr->freeResult( $queryResult ) ; |
| 394 | + |
395 | 395 | return $result; |
396 | 396 | } |
397 | 397 | |
— | — | @@ -404,8 +404,8 @@ |
405 | 405 | $dbr = wfGetDB( DB_SLAVE ); |
406 | 406 | $queryResult = $dbr->query( "SELECT object_id FROM {$dc}_class_attributes" . |
407 | 407 | " WHERE class_mid=$classMeaningId AND level_mid=$levelMeaningId AND attribute_mid=$attributeMeaningId AND attribute_type = " . $dbr->addQuotes( $attributeType ) . |
408 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_class_attributes" ) ); |
409 | | - |
| 408 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_class_attributes" ) . " LIMIT 1" ); |
| 409 | + |
410 | 410 | return $dbr->numRows( $queryResult ) > 0; |
411 | 411 | } |
412 | 412 | |
— | — | @@ -417,10 +417,10 @@ |
418 | 418 | if ( $objectId == 0 ) |
419 | 419 | $objectId = newObjectId( "{$dc}_class_attributes" ); |
420 | 420 | |
421 | | - $dbr = wfGetDB( DB_MASTER ); |
| 421 | + $dbw = wfGetDB( DB_MASTER ); |
422 | 422 | $sql = "INSERT INTO {$dc}_class_attributes(object_id, class_mid, level_mid, attribute_mid, attribute_type, add_transaction_id) " . |
423 | | - " VALUES ($objectId, $classMeaningId, $levelMeaningId, $attributeMeaningId, " . $dbr->addQuotes( $attributeType ) . ', ' . getUpdateTransactionId() . ')'; |
424 | | - $dbr->query( $sql ); |
| 423 | + " VALUES ($objectId, $classMeaningId, $levelMeaningId, $attributeMeaningId, " . $dbw->addQuotes( $attributeType ) . ', ' . getUpdateTransactionId() . ')'; |
| 424 | + $dbw->query( $sql ); |
425 | 425 | } |
426 | 426 | |
427 | 427 | function getClassAttributeId( $classMeaningId, $levelMeaningId, $attributeMeaningId, $attributeType ) { |
— | — | @@ -437,8 +437,8 @@ |
438 | 438 | |
439 | 439 | function removeClassAttributeWithId( $classAttributeId ) { |
440 | 440 | $dc = wdGetDataSetContext(); |
441 | | - $dbr = wfGetDB( DB_MASTER ); |
442 | | - $dbr->query( "UPDATE {$dc}_class_attributes SET remove_transaction_id=" . getUpdateTransactionId() . |
| 441 | + $dbw = wfGetDB( DB_MASTER ); |
| 442 | + $dbw->query( "UPDATE {$dc}_class_attributes SET remove_transaction_id=" . getUpdateTransactionId() . |
443 | 443 | " WHERE object_id=$classAttributeId " . |
444 | 444 | " AND remove_transaction_id IS NULL" ); |
445 | 445 | } |
— | — | @@ -462,10 +462,10 @@ |
463 | 463 | if ( $classMembershipId == 0 ) |
464 | 464 | $classMembershipId = newObjectId( "{$dc}_class_membership" ); |
465 | 465 | |
466 | | - $dbr = wfGetDB( DB_MASTER ); |
| 466 | + $dbw = wfGetDB( DB_MASTER ); |
467 | 467 | $sql = "INSERT INTO {$dc}_class_membership(class_membership_id, class_mid, class_member_mid, add_transaction_id) " . |
468 | 468 | "VALUES ($classMembershipId, $classId, $classMemberId, " . getUpdateTransactionId() . ")"; |
469 | | - $dbr->query( $sql ); |
| 469 | + $dbw->query( $sql ); |
470 | 470 | } |
471 | 471 | |
472 | 472 | function classMembershipExists( $classMemberId, $classId ) { |
— | — | @@ -473,7 +473,7 @@ |
474 | 474 | $dbr = wfGetDB( DB_SLAVE ); |
475 | 475 | $queryResult = $dbr->query( "SELECT class_member_mid FROM {$dc}_class_membership " . |
476 | 476 | "WHERE class_mid=$classId AND class_member_mid=$classMemberId " . |
477 | | - "AND " . getLatestTransactionRestriction( "{$dc}_class_membership" ) ); |
| 477 | + "AND " . getLatestTransactionRestriction( "{$dc}_class_membership" ) . " LIMIT 1" ); |
478 | 478 | |
479 | 479 | return $dbr->numRows( $queryResult ) > 0; |
480 | 480 | } |
— | — | @@ -485,8 +485,8 @@ |
486 | 486 | |
487 | 487 | function removeClassMembership( $classMemberId, $classId ) { |
488 | 488 | $dc = wdGetDataSetContext(); |
489 | | - $dbr = wfGetDB( DB_MASTER ); |
490 | | - $dbr->query( "UPDATE {$dc}_class_membership SET remove_transaction_id=" . getUpdateTransactionId() . |
| 489 | + $dbw = wfGetDB( DB_MASTER ); |
| 490 | + $dbw->query( "UPDATE {$dc}_class_membership SET remove_transaction_id=" . getUpdateTransactionId() . |
491 | 491 | " WHERE class_mid=$classId AND class_member_mid=$classMemberId " . |
492 | 492 | " AND remove_transaction_id IS NULL" ); |
493 | 493 | } |
— | — | @@ -494,23 +494,23 @@ |
495 | 495 | function removeClassMembershipWithId( $classMembershipId ) { |
496 | 496 | $dc = wdGetDataSetContext(); |
497 | 497 | |
498 | | - $dbr = wfGetDB( DB_MASTER ); |
499 | | - $dbr->query( "UPDATE {$dc}_class_membership SET remove_transaction_id=" . getUpdateTransactionId() . |
| 498 | + $dbw = wfGetDB( DB_MASTER ); |
| 499 | + $dbw->query( "UPDATE {$dc}_class_membership SET remove_transaction_id=" . getUpdateTransactionId() . |
500 | 500 | " WHERE class_membership_id=$classMembershipId" . |
501 | 501 | " AND remove_transaction_id IS NULL" ); |
502 | 502 | } |
503 | 503 | |
504 | 504 | function removeSynonymOrTranslation( $definedMeaningId, $expressionId ) { |
505 | 505 | $dc = wdGetDataSetContext(); |
506 | | - $dbr = wfGetDB( DB_MASTER ); |
507 | | - $dbr->query( "UPDATE {$dc}_syntrans SET remove_transaction_id=" . getUpdateTransactionId() . |
| 506 | + $dbw = wfGetDB( DB_MASTER ); |
| 507 | + $dbw->query( "UPDATE {$dc}_syntrans SET remove_transaction_id=" . getUpdateTransactionId() . |
508 | 508 | " WHERE defined_meaning_id=$definedMeaningId AND expression_id=$expressionId AND remove_transaction_id IS NULL LIMIT 1" ); |
509 | 509 | } |
510 | 510 | |
511 | 511 | function removeSynonymOrTranslationWithId( $syntransId ) { |
512 | 512 | $dc = wdGetDataSetContext(); |
513 | | - $dbr = wfGetDB( DB_MASTER ); |
514 | | - $dbr->query( "UPDATE {$dc}_syntrans SET remove_transaction_id=" . getUpdateTransactionId() . |
| 513 | + $dbw = wfGetDB( DB_MASTER ); |
| 514 | + $dbw->query( "UPDATE {$dc}_syntrans SET remove_transaction_id=" . getUpdateTransactionId() . |
515 | 515 | " WHERE syntrans_sid=$syntransId AND remove_transaction_id IS NULL LIMIT 1" ); |
516 | 516 | } |
517 | 517 | |
— | — | @@ -524,7 +524,7 @@ |
525 | 525 | $dbr = wfGetDB( DB_SLAVE ); |
526 | 526 | $queryResult = $dbr->query( "SELECT defined_meaning_id, expression_id" . |
527 | 527 | " FROM {$dc}_syntrans" . |
528 | | - " WHERE syntrans_sid=$syntransId AND remove_transaction_id IS NULL" ); |
| 528 | + " WHERE syntrans_sid=$syntransId AND remove_transaction_id IS NULL LIMIT 1" ); |
529 | 529 | |
530 | 530 | if ( $syntrans = $dbr->fetchObject( $queryResult ) ) |
531 | 531 | updateSynonymOrTranslation( $syntrans->defined_meaning_id, $syntrans->expression_id, $identicalMeaning ); |
— | — | @@ -553,22 +553,22 @@ |
554 | 554 | |
555 | 555 | function createText( $text ) { |
556 | 556 | $dc = wdGetDataSetContext(); |
557 | | - $dbr = wfGetDB( DB_MASTER ); |
558 | | - $text = $dbr->addQuotes( $text ); |
| 557 | + $dbw = wfGetDB( DB_MASTER ); |
| 558 | + $text = $dbw->addQuotes( $text ); |
559 | 559 | $sql = "insert into {$dc}_text(text_text) values($text)"; |
560 | | - $dbr->query( $sql ); |
| 560 | + $dbw->query( $sql ); |
561 | 561 | |
562 | | - return $dbr->insertId(); |
| 562 | + return $dbw->insertId(); |
563 | 563 | } |
564 | 564 | |
565 | 565 | function createTranslatedContent( $translatedContentId, $languageId, $textId ) { |
566 | 566 | $dc = wdGetDataSetContext(); |
567 | 567 | |
568 | | - $dbr = wfGetDB( DB_MASTER ); |
| 568 | + $dbw = wfGetDB( DB_MASTER ); |
569 | 569 | $sql = "insert into {$dc}_translated_content(translated_content_id,language_id,text_id,add_transaction_id) values($translatedContentId, $languageId, $textId, " . getUpdateTransactionId() . ")"; |
570 | | - $dbr->query( $sql ); |
| 570 | + $dbw->query( $sql ); |
571 | 571 | |
572 | | - return $dbr->insertId(); |
| 572 | + return $dbw->insertId(); |
573 | 573 | } |
574 | 574 | |
575 | 575 | function translatedTextExists( $textId, $languageId ) { |
— | — | @@ -585,7 +585,7 @@ |
586 | 586 | " FROM {$dc}_translated_content" . |
587 | 587 | " WHERE translated_content_id=$textId" . |
588 | 588 | " AND language_id=$languageId" . |
589 | | - " AND " . getLatestTransactionRestriction( "{$dc}_translated_content" ) |
| 589 | + " AND " . getLatestTransactionRestriction( "{$dc}_translated_content" ) . " LIMIT 1" |
590 | 590 | ); |
591 | 591 | |
592 | 592 | return $dbr->numRows( $queryResult ) > 0; |
— | — | @@ -605,15 +605,15 @@ |
606 | 606 | $dc = wdGetDataSetContext(); |
607 | 607 | $dbr = wfGetDB( DB_SLAVE ); |
608 | 608 | $queryResult = $dbr->query( "SELECT meaning_text_tcid FROM {$dc}_defined_meaning WHERE defined_meaning_id=$definedMeaningId " . |
609 | | - " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) ); |
| 609 | + " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) . " LIMIT 1" ); |
610 | 610 | |
611 | 611 | return $dbr->fetchObject( $queryResult )->meaning_text_tcid; |
612 | 612 | } |
613 | 613 | |
614 | 614 | function updateDefinedMeaningDefinitionId( $definedMeaningId, $definitionId ) { |
615 | | - $dbr = wfGetDB( DB_MASTER ); |
| 615 | + $dbw = wfGetDB( DB_MASTER ); |
616 | 616 | $dc = wdGetDataSetContext(); |
617 | | - $dbr->query( "UPDATE {$dc}_defined_meaning SET meaning_text_tcid=$definitionId WHERE defined_meaning_id=$definedMeaningId" . |
| 617 | + $dbw->query( "UPDATE {$dc}_defined_meaning SET meaning_text_tcid=$definitionId WHERE defined_meaning_id=$definedMeaningId" . |
618 | 618 | " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) ); |
619 | 619 | } |
620 | 620 | |
— | — | @@ -639,8 +639,8 @@ |
640 | 640 | |
641 | 641 | function createDefinedMeaningAlternativeDefinition( $definedMeaningId, $translatedContentId, $sourceMeaningId ) { |
642 | 642 | $dc = wdGetDataSetContext(); |
643 | | - $dbr = wfGetDB( DB_MASTER ); |
644 | | - $dbr->query( "INSERT INTO {$dc}_alt_meaningtexts (meaning_mid, meaning_text_tcid, source_id, add_transaction_id) " . |
| 643 | + $dbw = wfGetDB( DB_MASTER ); |
| 644 | + $dbw->query( "INSERT INTO {$dc}_alt_meaningtexts (meaning_mid, meaning_text_tcid, source_id, add_transaction_id) " . |
645 | 645 | "VALUES ($definedMeaningId, $translatedContentId, $sourceMeaningId, " . getUpdateTransactionId() . ")" ); |
646 | 646 | } |
647 | 647 | |
— | — | @@ -653,15 +653,15 @@ |
654 | 654 | |
655 | 655 | function removeTranslatedText( $translatedContentId, $languageId ) { |
656 | 656 | $dc = wdGetDataSetContext(); |
657 | | - $dbr = wfGetDB( DB_MASTER ); |
658 | | - $dbr->query( "UPDATE {$dc}_translated_content SET remove_transaction_id=" . getUpdateTransactionId() . |
| 657 | + $dbw = wfGetDB( DB_MASTER ); |
| 658 | + $dbw->query( "UPDATE {$dc}_translated_content SET remove_transaction_id=" . getUpdateTransactionId() . |
659 | 659 | " WHERE translated_content_id=$translatedContentId AND language_id=$languageId AND remove_transaction_id IS NULL" ); |
660 | 660 | } |
661 | 661 | |
662 | 662 | function removeTranslatedTexts( $translatedContentId ) { |
663 | 663 | $dc = wdGetDataSetContext(); |
664 | | - $dbr = wfGetDB( DB_MASTER ); |
665 | | - $dbr->query( "UPDATE {$dc}_translated_content SET remove_transaction_id=" . getUpdateTransactionId() . |
| 664 | + $dbw = wfGetDB( DB_MASTER ); |
| 665 | + $dbw->query( "UPDATE {$dc}_translated_content SET remove_transaction_id=" . getUpdateTransactionId() . |
666 | 666 | " WHERE translated_content_id=$translatedContentId AND remove_transaction_id IS NULL" ); |
667 | 667 | } |
668 | 668 | |
— | — | @@ -674,8 +674,8 @@ |
675 | 675 | // removeTranslatedTexts($definitionId); |
676 | 676 | |
677 | 677 | $dc = wdGetDataSetContext(); |
678 | | - $dbr = wfGetDB( DB_MASTER ); |
679 | | - $dbr->query( "UPDATE {$dc}_alt_meaningtexts SET remove_transaction_id=" . getUpdateTransactionId() . |
| 678 | + $dbw = wfGetDB( DB_MASTER ); |
| 679 | + $dbw->query( "UPDATE {$dc}_alt_meaningtexts SET remove_transaction_id=" . getUpdateTransactionId() . |
680 | 680 | " WHERE meaning_text_tcid=$definitionId AND meaning_mid=$definedMeaningId" . |
681 | 681 | " AND remove_transaction_id IS NULL" ); |
682 | 682 | } |
— | — | @@ -691,16 +691,16 @@ |
692 | 692 | $dc = wdGetDataSetContext(); |
693 | 693 | $dbr = wfGetDB( DB_SLAVE ); |
694 | 694 | $queryResult = $dbr->query( "SELECT collection_id FROM {$dc}_collection_contents WHERE collection_id=$collectionId AND member_mid=$definedMeaningId " . |
695 | | - "AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) ); |
| 695 | + "AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . " LIMIT 1" ); |
696 | 696 | |
697 | 697 | return $dbr->numRows( $queryResult ) > 0; |
698 | 698 | } |
699 | 699 | |
700 | 700 | function addDefinedMeaningToCollection( $definedMeaningId, $collectionId, $internalId ) { |
701 | 701 | $dc = wdGetDataSetContext(); |
702 | | - $dbr = wfGetDB( DB_MASTER ); |
703 | | - $dbr->query( "INSERT INTO {$dc}_collection_contents(collection_id, member_mid, internal_member_id, add_transaction_id) " . |
704 | | - "VALUES ($collectionId, $definedMeaningId, " . $dbr->addQuotes( $internalId ) . ", " . getUpdateTransactionId() . ")" ); |
| 702 | + $dbw = wfGetDB( DB_MASTER ); |
| 703 | + $dbw->query( "INSERT INTO {$dc}_collection_contents(collection_id, member_mid, internal_member_id, add_transaction_id) " . |
| 704 | + "VALUES ($collectionId, $definedMeaningId, " . $dbw->addQuotes( $internalId ) . ", " . getUpdateTransactionId() . ")" ); |
705 | 705 | } |
706 | 706 | |
707 | 707 | function addDefinedMeaningToCollectionIfNotPresent( $definedMeaningId, $collectionId, $internalId ) { |
— | — | @@ -711,7 +711,7 @@ |
712 | 712 | function getDefinedMeaningFromCollection( $collectionId, $internalMemberId ) { |
713 | 713 | $dc = wdGetDataSetContext(); |
714 | 714 | $dbr = wfGetDB( DB_SLAVE ); |
715 | | - $query = "SELECT member_mid FROM {$dc}_collection_contents WHERE collection_id=$collectionId AND internal_member_id=" . $dbr->addQuotes( $internalMemberId ) . " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
| 715 | + $query = "SELECT member_mid FROM {$dc}_collection_contents WHERE collection_id=$collectionId AND internal_member_id=" . $dbr->addQuotes( $internalMemberId ) . " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . " LIMIT 1" ; |
716 | 716 | $queryResult = $dbr->query( $query ); |
717 | 717 | |
718 | 718 | if ( $definedMeaningObject = $dbr->fetchObject( $queryResult ) ) |
— | — | @@ -722,8 +722,8 @@ |
723 | 723 | |
724 | 724 | function removeDefinedMeaningFromCollection( $definedMeaningId, $collectionId ) { |
725 | 725 | $dc = wdGetDataSetContext(); |
726 | | - $dbr = wfGetDB( DB_MASTER ); |
727 | | - $dbr->query( "UPDATE {$dc}_collection_contents SET remove_transaction_id=" . getUpdateTransactionId() . |
| 726 | + $dbw = wfGetDB( DB_MASTER ); |
| 727 | + $dbw->query( "UPDATE {$dc}_collection_contents SET remove_transaction_id=" . getUpdateTransactionId() . |
728 | 728 | " WHERE collection_id=$collectionId AND member_mid=$definedMeaningId AND remove_transaction_id IS NULL" ); |
729 | 729 | } |
730 | 730 | |
— | — | @@ -744,7 +744,7 @@ |
745 | 745 | $dc = wdGetDataSetContext(); |
746 | 746 | $dbr = wfGetDB( DB_SLAVE ); |
747 | 747 | $queryResult = $dbr->query( "SELECT collection_mid FROM {$dc}_collection " . |
748 | | - " WHERE collection_id=$collectionId AND " . getLatestTransactionRestriction( "{$dc}_collection" ) ); |
| 748 | + " WHERE collection_id=$collectionId AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . " LIMIT 1" ); |
749 | 749 | |
750 | 750 | return $dbr->fetchObject( $queryResult )->collection_mid; |
751 | 751 | } |
— | — | @@ -753,7 +753,7 @@ |
754 | 754 | $dc = wdGetDataSetContext(); |
755 | 755 | $dbr = wfGetDB( DB_SLAVE ); |
756 | 756 | $queryResult = $dbr->query( "SELECT collection_id FROM {$dc}_collection " . |
757 | | - " WHERE collection_mid=$collectionMeaningId AND " . getLatestTransactionRestriction( "{$dc}_collection" ) ); |
| 757 | + " WHERE collection_mid=$collectionMeaningId AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . " LIMIT 1" ); |
758 | 758 | |
759 | 759 | return $dbr->fetchObject( $queryResult )->collection_id; |
760 | 760 | } |
— | — | @@ -762,28 +762,26 @@ |
763 | 763 | $dc = wdGetDataSetContext(); |
764 | 764 | $collectionId = newObjectId( "{$dc}_collection" ); |
765 | 765 | |
766 | | - $dbr = wfGetDB( DB_MASTER ); |
767 | | - $dbr->query( "INSERT INTO {$dc}_collection(collection_id, collection_mid, collection_type, add_transaction_id)" . |
| 766 | + $dbw = wfGetDB( DB_MASTER ); |
| 767 | + $dbw->query( "INSERT INTO {$dc}_collection(collection_id, collection_mid, collection_type, add_transaction_id)" . |
768 | 768 | " VALUES($collectionId, $definedMeaningId, '$collectionType', " . getUpdateTransactionId() . ")" ); |
769 | 769 | |
770 | 770 | return $collectionId; |
771 | 771 | } |
772 | 772 | |
773 | 773 | function addDefinedMeaning( $definingExpressionId ) { |
774 | | - # FIXME: Replace with method for Namspace::getIndexForName. |
775 | | - $definedMeaningNameSpaceId = 24; |
776 | 774 | $dc = wdGetDataSetContext(); |
777 | 775 | |
778 | 776 | $definedMeaningId = newObjectId( "{$dc}_defined_meaning" ); |
779 | 777 | |
780 | 778 | // wfDebug( "addDefinedMeaning(): $definedMeaningId has to be inserted to the database $dc" ); |
781 | | - $dbr = wfGetDB( DB_MASTER ); |
782 | | - $dbr->query( "INSERT INTO {$dc}_defined_meaning(defined_meaning_id, expression_id, add_transaction_id) values($definedMeaningId, $definingExpressionId, " . getUpdateTransactionId() . ")" ); |
| 779 | + $dbw = wfGetDB( DB_MASTER ); |
| 780 | + $dbw->query( "INSERT INTO {$dc}_defined_meaning(defined_meaning_id, expression_id, add_transaction_id) values($definedMeaningId, $definingExpressionId, " . getUpdateTransactionId() . ")" ); |
783 | 781 | |
784 | 782 | // wfDebug( "addDefinedMeaning(): after $definedMeaningId has been inserted in the database" ); |
785 | 783 | |
786 | 784 | $expression = getExpression( $definingExpressionId ); |
787 | | - $pageId = createPage( $definedMeaningNameSpaceId, getPageTitle( "$expression->spelling ($definedMeaningId)" ) ); |
| 785 | + $pageId = createPage( NS_DEFINEDMEANING, getPageTitle( "$expression->spelling ($definedMeaningId)" ) ); |
788 | 786 | createInitialRevisionForPage( $pageId, 'Created by adding defined meaning' ); |
789 | 787 | |
790 | 788 | return $definedMeaningId; |
— | — | @@ -807,17 +805,17 @@ |
808 | 806 | |
809 | 807 | function createTextAttributeValue( $textValueAttributeId, $objectId, $textAttributeId, $text ) { |
810 | 808 | $dc = wdGetDataSetContext(); |
811 | | - $dbr = wfGetDB( DB_MASTER ); |
812 | | - $dbr->query( |
| 809 | + $dbw = wfGetDB( DB_MASTER ); |
| 810 | + $dbw->query( |
813 | 811 | "INSERT INTO {$dc}_text_attribute_values (value_id, object_id, attribute_mid, text, add_transaction_id) " . |
814 | | - "VALUES ($textValueAttributeId, $objectId, $textAttributeId, " . $dbr->addQuotes( $text ) . ", " . getUpdateTransactionId() . ")" |
| 812 | + "VALUES ($textValueAttributeId, $objectId, $textAttributeId, " . $dbw->addQuotes( $text ) . ", " . getUpdateTransactionId() . ")" |
815 | 813 | ); |
816 | 814 | } |
817 | 815 | |
818 | 816 | function removeTextAttributeValue( $textValueAttributeId ) { |
819 | 817 | $dc = wdGetDataSetContext(); |
820 | | - $dbr = wfGetDB( DB_MASTER ); |
821 | | - $dbr->query( "UPDATE {$dc}_text_attribute_values SET remove_transaction_id=" . getUpdateTransactionId() . |
| 818 | + $dbw = wfGetDB( DB_MASTER ); |
| 819 | + $dbw->query( "UPDATE {$dc}_text_attribute_values SET remove_transaction_id=" . getUpdateTransactionId() . |
822 | 820 | " WHERE value_id=$textValueAttributeId" . |
823 | 821 | " AND remove_transaction_id IS NULL" ); |
824 | 822 | } |
— | — | @@ -835,7 +833,7 @@ |
836 | 834 | "SELECT object_id, attribute_mid, text" . |
837 | 835 | " FROM {$dc}_text_attribute_values" . |
838 | 836 | " WHERE value_id=$textValueAttributeId " . |
839 | | - " AND " . getLatestTransactionRestriction( "{$dc}_text_attribute_values" ) |
| 837 | + " AND " . getLatestTransactionRestriction( "{$dc}_text_attribute_values" ) . " LIMIT 1" |
840 | 838 | ); |
841 | 839 | |
842 | 840 | return $dbr->fetchObject( $queryResult ); |
— | — | @@ -849,17 +847,17 @@ |
850 | 848 | |
851 | 849 | function createLinkAttributeValue( $linkValueAttributeId, $objectId, $linkAttributeId, $url, $label = "" ) { |
852 | 850 | $dc = wdGetDataSetContext(); |
853 | | - $dbr = wfGetDB( DB_MASTER ); |
854 | | - $dbr->query( |
| 851 | + $dbw = wfGetDB( DB_MASTER ); |
| 852 | + $dbw->query( |
855 | 853 | "INSERT INTO {$dc}_url_attribute_values (value_id, object_id, attribute_mid, url, label, add_transaction_id) " . |
856 | | - "VALUES ($linkValueAttributeId, $objectId, $linkAttributeId, " . $dbr->addQuotes( $url ) . ", " . $dbr->addQuotes( $label ) . ", " . getUpdateTransactionId() . ")" |
| 854 | + "VALUES ($linkValueAttributeId, $objectId, $linkAttributeId, " . $dbw->addQuotes( $url ) . ", " . $dbw->addQuotes( $label ) . ", " . getUpdateTransactionId() . ")" |
857 | 855 | ); |
858 | 856 | } |
859 | 857 | |
860 | 858 | function removeLinkAttributeValue( $linkValueAttributeId ) { |
861 | 859 | $dc = wdGetDataSetContext(); |
862 | | - $dbr = wfGetDB( DB_MASTER ); |
863 | | - $dbr->query( |
| 860 | + $dbw = wfGetDB( DB_MASTER ); |
| 861 | + $dbw->query( |
864 | 862 | "UPDATE {$dc}_url_attribute_values SET remove_transaction_id=" . getUpdateTransactionId() . |
865 | 863 | " WHERE value_id=$linkValueAttributeId" . |
866 | 864 | " AND remove_transaction_id IS NULL" |
— | — | @@ -878,7 +876,7 @@ |
879 | 877 | $queryResult = $dbr->query( |
880 | 878 | "SELECT object_id, attribute_mid, url" . |
881 | 879 | " FROM {$dc}_url_attribute_values WHERE value_id=$linkValueAttributeId " . |
882 | | - " AND " . getLatestTransactionRestriction( "{$dc}_url_attribute_values" ) |
| 880 | + " AND " . getLatestTransactionRestriction( "{$dc}_url_attribute_values" ) . " LIMIT 1" |
883 | 881 | ); |
884 | 882 | |
885 | 883 | return $dbr->fetchObject( $queryResult ); |
— | — | @@ -886,8 +884,8 @@ |
887 | 885 | |
888 | 886 | function createTranslatedTextAttributeValue( $valueId, $objectId, $attributeId, $translatedContentId ) { |
889 | 887 | $dc = wdGetDataSetContext(); |
890 | | - $dbr = wfGetDB( DB_MASTER ); |
891 | | - $dbr->query( "INSERT INTO {$dc}_translated_content_attribute_values (value_id, object_id, attribute_mid, value_tcid, add_transaction_id) " . |
| 888 | + $dbw = wfGetDB( DB_MASTER ); |
| 889 | + $dbw->query( "INSERT INTO {$dc}_translated_content_attribute_values (value_id, object_id, attribute_mid, value_tcid, add_transaction_id) " . |
892 | 890 | "VALUES ($valueId, $objectId, $attributeId, $translatedContentId, " . getUpdateTransactionId() . ")" ); |
893 | 891 | } |
894 | 892 | |
— | — | @@ -904,7 +902,7 @@ |
905 | 903 | $dc = wdGetDataSetContext(); |
906 | 904 | $dbr = wfGetDB( DB_SLAVE ); |
907 | 905 | $queryResult = $dbr->query( "SELECT value_id, object_id, attribute_mid, value_tcid FROM {$dc}_translated_content_attribute_values WHERE value_id=$valueId " . |
908 | | - " AND " . getLatestTransactionRestriction( "{$dc}_translated_content_attribute_values" ) ); |
| 906 | + " AND " . getLatestTransactionRestriction( "{$dc}_translated_content_attribute_values" ) . " LIMIT 1" ); |
909 | 907 | |
910 | 908 | return $dbr->fetchObject( $queryResult ); |
911 | 909 | } |
— | — | @@ -920,8 +918,8 @@ |
921 | 919 | // back easier. |
922 | 920 | // removeTranslatedTexts($translatedTextAttribute->value_tcid); |
923 | 921 | |
924 | | - $dbr = wfGetDB( DB_MASTER ); |
925 | | - $dbr->query( |
| 922 | + $dbw = wfGetDB( DB_MASTER ); |
| 923 | + $dbw->query( |
926 | 924 | "UPDATE {$dc}_translated_content_attribute_values" . |
927 | 925 | " SET remove_transaction_id=" . getUpdateTransactionId() . |
928 | 926 | " WHERE value_id=$valueId" . |
— | — | @@ -935,7 +933,7 @@ |
936 | 934 | $queryResult = $dbr->query( "SELECT value_id FROM {$dc}_option_attribute_values" . |
937 | 935 | ' WHERE object_id = ' . $objectId . |
938 | 936 | ' AND option_id = ' . $optionId . |
939 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_values" ) ); |
| 937 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_values" ) . " LIMIT 1" ); |
940 | 938 | return $dbr->numRows( $queryResult ) > 0; |
941 | 939 | } |
942 | 940 | |
— | — | @@ -948,23 +946,23 @@ |
949 | 947 | $dc = wdGetDataSetContext(); |
950 | 948 | $valueId = newObjectId( "{$dc}_option_attribute_values" ); |
951 | 949 | |
952 | | - $dbr = wfGetDB( DB_MASTER ); |
| 950 | + $dbw = wfGetDB( DB_MASTER ); |
953 | 951 | $sql = "INSERT INTO {$dc}_option_attribute_values(value_id,object_id,option_id,add_transaction_id)" . |
954 | 952 | ' VALUES(' . $valueId . |
955 | 953 | ',' . $objectId . |
956 | 954 | ',' . $optionId . |
957 | 955 | ',' . getUpdateTransactionId() . ')'; |
958 | | - $dbr->query( $sql ); |
| 956 | + $dbw->query( $sql ); |
959 | 957 | } |
960 | 958 | |
961 | 959 | function removeOptionAttributeValue( $valueId ) { |
962 | 960 | $dc = wdGetDataSetContext(); |
963 | | - $dbr = wfGetDB( DB_MASTER ); |
| 961 | + $dbw = wfGetDB( DB_MASTER ); |
964 | 962 | $sql = "UPDATE {$dc}_option_attribute_values" . |
965 | 963 | ' SET remove_transaction_id = ' . getUpdateTransactionId() . |
966 | 964 | ' WHERE value_id = ' . $valueId . |
967 | 965 | ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_values" ); |
968 | | - $dbr->query( $sql ); |
| 966 | + $dbw->query( $sql ); |
969 | 967 | } |
970 | 968 | |
971 | 969 | function optionAttributeOptionExists( $attributeId, $optionMeaningId, $languageId ) { |
— | — | @@ -974,7 +972,7 @@ |
975 | 973 | ' WHERE attribute_id = ' . $attributeId . |
976 | 974 | ' AND option_mid = ' . $optionMeaningId . |
977 | 975 | ' AND language_id = ' . $languageId . |
978 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" ) ); |
| 976 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" ) . " LIMIT 1" ); |
979 | 977 | return $dbr->numRows( $queryResult ) > 0; |
980 | 978 | } |
981 | 979 | |
— | — | @@ -987,27 +985,27 @@ |
988 | 986 | $dc = wdGetDataSetContext(); |
989 | 987 | $optionId = newObjectId( "{$dc}_option_attribute_options" ); |
990 | 988 | |
991 | | - $dbr = wfGetDB( DB_MASTER ); |
| 989 | + $dbw = wfGetDB( DB_MASTER ); |
992 | 990 | $sql = "INSERT INTO {$dc}_option_attribute_options(option_id,attribute_id,option_mid,language_id,add_transaction_id)" . |
993 | 991 | ' VALUES(' . $optionId . |
994 | 992 | ',' . $attributeId . |
995 | 993 | ',' . $optionMeaningId . |
996 | 994 | ',' . $languageId . |
997 | 995 | ',' . getUpdateTransactionId() . ')'; |
998 | | - $dbr->query( $sql ); |
| 996 | + $dbw->query( $sql ); |
999 | 997 | } |
1000 | 998 | |
1001 | 999 | function removeOptionAttributeOption( $optionId ) { |
1002 | 1000 | $dc = wdGetDataSetContext(); |
1003 | | - $dbr = wfGetDB( DB_MASTER ); |
| 1001 | + $dbw = wfGetDB( DB_MASTER ); |
1004 | 1002 | |
1005 | 1003 | // first check if the option attribute option is still in use |
1006 | 1004 | $sql = "SELECT * FROM {$dc}_option_attribute_values" . |
1007 | 1005 | ' WHERE option_id = ' . $optionId . |
1008 | | - ' AND remove_transaction_id IS NULL' ; |
1009 | | - $queryResult = $dbr->query( $sql ); |
| 1006 | + ' AND remove_transaction_id IS NULL LIMIT 1' ; |
| 1007 | + $queryResult = $dbw->query( $sql ); |
1010 | 1008 | |
1011 | | - if ( $dbr->numRows( $queryResult ) > 0 ) { |
| 1009 | + if ( $dbw->numRows( $queryResult ) > 0 ) { |
1012 | 1010 | echo "\nThe option $optionId cannot be deleted because it is still in use!\n" ; |
1013 | 1011 | } else { |
1014 | 1012 | // option not used, can proceed to delete |
— | — | @@ -1016,7 +1014,7 @@ |
1017 | 1015 | ' SET remove_transaction_id = ' . $transactionId . |
1018 | 1016 | ' WHERE option_id = ' . $optionId . |
1019 | 1017 | ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" ); |
1020 | | - $dbr->query( $sql ); |
| 1018 | + $dbw->query( $sql ); |
1021 | 1019 | } |
1022 | 1020 | |
1023 | 1021 | // alternatively to checking if the attribute option is in use |
— | — | @@ -1040,7 +1038,6 @@ |
1041 | 1039 | function getDefinedMeaningDefinitionForLanguage( $definedMeaningId, $languageId, $dc = null ) { |
1042 | 1040 | if ( is_null( $dc ) ) { |
1043 | 1041 | $dc = wdGetDataSetContext(); |
1044 | | - |
1045 | 1042 | } |
1046 | 1043 | $dbr = wfGetDB( DB_SLAVE ); |
1047 | 1044 | $queryResult = $dbr->query( "SELECT text_text FROM {$dc}_defined_meaning as dm, {$dc}_translated_content as tc, {$dc}_text as t " . |
— | — | @@ -1048,7 +1045,7 @@ |
1049 | 1046 | " AND " . getLatestTransactionRestriction( 'dm' ) . |
1050 | 1047 | " AND " . getLatestTransactionRestriction( 'tc' ) . |
1051 | 1048 | " AND dm.meaning_text_tcid=tc.translated_content_id AND tc.language_id=$languageId " . |
1052 | | - " AND t.text_id=tc.text_id" ); |
| 1049 | + " AND t.text_id=tc.text_id LIMIT 1" ); |
1053 | 1050 | |
1054 | 1051 | if ( $definition = $dbr->fetchObject( $queryResult ) ) |
1055 | 1052 | return $definition->text_text; |
— | — | @@ -1115,17 +1112,17 @@ |
1116 | 1113 | |
1117 | 1114 | $definedMeaningId = $dbr->addQuotes( $definedMeaningId ); |
1118 | 1115 | $userLanguageId = $dbr->addQuotes( $userLanguageId ); |
1119 | | - $fallbackLanguageId = $dbr->addQuotes( $fallbackLanguageId ); |
1120 | 1116 | |
1121 | 1117 | if ( $userLanguageId ) { |
1122 | | - $actual_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$userLanguageId and {$dc}_expression.remove_transaction_id is NULL"; |
| 1118 | + $actual_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$userLanguageId and {$dc}_expression.remove_transaction_id is NULL LIMIT 1"; |
1123 | 1119 | |
1124 | 1120 | $res = $dbr->query( $actual_query ); |
1125 | 1121 | $row = $dbr->fetchObject( $res ); |
1126 | 1122 | if ( isset( $row->spelling ) ) return $row->spelling; |
1127 | 1123 | } |
1128 | 1124 | |
1129 | | - $fallback_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$fallbackLanguageId and {$dc}_expression.remove_transaction_id is NULL"; |
| 1125 | + $fallbackLanguageId = $dbr->addQuotes( $fallbackLanguageId ); |
| 1126 | + $fallback_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$fallbackLanguageId and {$dc}_expression.remove_transaction_id is NULL LIMIT 1"; |
1130 | 1127 | |
1131 | 1128 | $res = $dbr->query( $fallback_query ); |
1132 | 1129 | $row = $dbr->fetchObject( $res ); |
— | — | @@ -1153,7 +1150,7 @@ |
1154 | 1151 | " FROM ({$dc}_collection_contents INNER JOIN {$dc}_collection ON {$dc}_collection.collection_id = {$dc}_collection_contents.collection_id) " . |
1155 | 1152 | " WHERE {$dc}_collection_contents.member_mid = $objectId AND {$dc}_collection.collection_type = 'CLAS' " . |
1156 | 1153 | " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . " " . |
1157 | | - " AND " . getLatestTransactionRestriction( "{$dc}_collection" ); |
| 1154 | + " AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . " LIMIT 1" ; |
1158 | 1155 | $queryResult = $dbr->query( $query ); |
1159 | 1156 | |
1160 | 1157 | $result = $dbr->numRows( $queryResult ) > 0; |
— | — | @@ -1178,9 +1175,8 @@ |
1179 | 1176 | } |
1180 | 1177 | |
1181 | 1178 | function getCollectionContents( $collectionId ) { |
1182 | | - global |
1183 | | - $dataSet; |
1184 | | - |
| 1179 | + global $dataSet; |
| 1180 | + |
1185 | 1181 | $dc = wdGetDataSetContext(); |
1186 | 1182 | $dbr = & wfGetDB( DB_SLAVE ); |
1187 | 1183 | $queryResult = $dbr->query( |
— | — | @@ -1217,7 +1213,8 @@ |
1218 | 1214 | while ( $row = $dbr->fetchRow( $result ) ) { |
1219 | 1215 | $memberMids[] = $row['member_mid']; |
1220 | 1216 | } |
1221 | | - |
| 1217 | + $dbr->freeResult( $result ) ; |
| 1218 | + |
1222 | 1219 | return $memberMids; |
1223 | 1220 | } |
1224 | 1221 | |
— | — | @@ -1229,7 +1226,7 @@ |
1230 | 1227 | " FROM {$dc}_collection_contents " . |
1231 | 1228 | " WHERE collection_id=$collectionId" . |
1232 | 1229 | " AND internal_member_id=" . $dbr->addQuotes( $sourceIdentifier ) . |
1233 | | - " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) |
| 1230 | + " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . " LIMIT 1" |
1234 | 1231 | ); |
1235 | 1232 | |
1236 | 1233 | if ( $collectionEntry = $dbr->fetchObject( $queryResult ) ) |
— | — | @@ -1271,8 +1268,10 @@ |
1272 | 1269 | |
1273 | 1270 | $result = array(); |
1274 | 1271 | |
1275 | | - while ( $synonymRecord = $dbr->fetchObject( $queryResult ) ) |
1276 | | - $result[] = $synonymRecord->defined_meaning_id; |
| 1272 | + while ( $synonymRecord = $dbr->fetchObject( $queryResult ) ) { |
| 1273 | + $result[] = $synonymRecord->defined_meaning_id; |
| 1274 | + } |
| 1275 | + $dbr->freeResult( $queryResult ) ; |
1277 | 1276 | |
1278 | 1277 | return $result; |
1279 | 1278 | } |
— | — | @@ -1298,6 +1297,7 @@ |
1299 | 1298 | $result[] = $synonymRecord->defined_meaning_id; |
1300 | 1299 | } |
1301 | 1300 | } |
| 1301 | + $dbr->freeResult( $queryResult ) ; |
1302 | 1302 | |
1303 | 1303 | return $result; |
1304 | 1304 | } |
— | — | @@ -1324,7 +1324,7 @@ |
1325 | 1325 | |
1326 | 1326 | function getMapping( $dc, $collid, $dm_id ) { |
1327 | 1327 | $dbr = wfGetDB( DB_SLAVE ); |
1328 | | - $queryResult = $dbr->query( "select internal_member_id from {$dc}_collection_contents where collection_id = $collid AND member_mid = $dm_id" ); |
| 1328 | + $queryResult = $dbr->query( "select internal_member_id from {$dc}_collection_contents where collection_id = $collid AND member_mid = $dm_id LIMIT 1" ); |
1329 | 1329 | if ( $record = $dbr->fetchObject( $queryResult ) ) { |
1330 | 1330 | return $record->internal_member_id; |
1331 | 1331 | } |
— | — | @@ -1371,7 +1371,7 @@ |
1372 | 1372 | /** this funtion assumes that there is only a single mapping collection */ |
1373 | 1373 | |
1374 | 1374 | function getCollectionIdForDC( $dc ) { |
1375 | | - $dbr = & wfGetDB( DB_SLAVE ); |
| 1375 | + $dbr = & wfGetDB( DB_SLAVE ); |
1376 | 1376 | $query = " |
1377 | 1377 | SELECT collection_id FROM {$dc}_collection |
1378 | 1378 | WHERE collection_type=\"MAPP\" |
— | — | @@ -1391,12 +1391,12 @@ |
1392 | 1392 | // if(is_null($dc)) { |
1393 | 1393 | // $dc=wdGetDataSetContext(); |
1394 | 1394 | // } |
1395 | | - $dbr = & wfGetDB( DB_SLAVE ); |
| 1395 | + $dbw = & wfGetDB( DB_MASTER ); |
1396 | 1396 | |
1397 | 1397 | $collection_contents = "{$dc}_collection_contents"; |
1398 | | - $collid = $dbr->addQuotes( $collid ); |
1399 | | - $uuid = $dbr->addQuotes( $uuid ); |
1400 | | - $dm_id = $dbr->addQuotes( $dm_id ); |
| 1398 | + $collid = $dbw->addQuotes( $collid ); |
| 1399 | + $uuid = $dbw->addQuotes( $uuid ); |
| 1400 | + $dm_id = $dbw->addQuotes( $dm_id ); |
1401 | 1401 | |
1402 | 1402 | $add_transaction_id = $override_transaction; |
1403 | 1403 | if ( is_null( $add_transaction_id ) ) { |
— | — | @@ -1411,7 +1411,7 @@ |
1412 | 1412 | member_mid=$dm_id, |
1413 | 1413 | add_transaction_id=$add_transaction_id |
1414 | 1414 | "; |
1415 | | - $result = $dbr->query( $sql ); |
| 1415 | + $result = $dbw->query( $sql ); |
1416 | 1416 | } |
1417 | 1417 | |
1418 | 1418 | /**read a ConceptMapping from the database. |
— | — | @@ -1440,7 +1440,7 @@ |
1441 | 1441 | $query = " |
1442 | 1442 | SELECT member_mid FROM $collection_contents |
1443 | 1443 | WHERE collection_id = $collection_id |
1444 | | - AND internal_member_id=$concept_id |
| 1444 | + AND internal_member_id=$concept_id LIMIT 1 |
1445 | 1445 | "; |
1446 | 1446 | $queryResult = $dbr->query( $query ); |
1447 | 1447 | $row = $dbr->fetchObject( $queryResult ); |
— | — | @@ -1462,7 +1462,7 @@ |
1463 | 1463 | SELECT internal_member_id AS concept_id |
1464 | 1464 | FROM {$dc}_collection_contents |
1465 | 1465 | WHERE member_mid=$dm |
1466 | | - AND collection_id=$collection_id; |
| 1466 | + AND collection_id=$collection_id LIMIT 1 |
1467 | 1467 | "; |
1468 | 1468 | $queryResult = $dbr->query( $query ); |
1469 | 1469 | $row = $dbr->fetchObject( $queryResult ); |
— | — | @@ -1506,7 +1506,7 @@ |
1507 | 1507 | " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " . |
1508 | 1508 | " AND {$dc}_expression.expression_id={$dc}_defined_meaning.expression_id" . |
1509 | 1509 | " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) . |
1510 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) ); |
| 1510 | + " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . " LIMIT 1" ); |
1511 | 1511 | $expression = $dbr->fetchObject( $queryResult ); |
1512 | 1512 | return array( $expression->expression_id, $expression->spelling, $expression->language_id ); |
1513 | 1513 | } |
— | — | @@ -1521,7 +1521,7 @@ |
1522 | 1522 | " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " . |
1523 | 1523 | " AND {$dc}_expression.expression_id={$dc}_defined_meaning.expression_id" . |
1524 | 1524 | " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) . |
1525 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) ); |
| 1525 | + " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . " LIMIT 1" ); |
1526 | 1526 | $expression = $dbr->fetchObject( $queryResult ); |
1527 | 1527 | if ( $expression ) { |
1528 | 1528 | return $expression->spelling; |
— | — | @@ -1616,7 +1616,7 @@ |
1617 | 1617 | function getTextValue( $textId ) { |
1618 | 1618 | $dc = wdGetDataSetContext(); |
1619 | 1619 | $dbr = wfGetDB( DB_SLAVE ); |
1620 | | - $queryResult = $dbr->query( "SELECT text_text from {$dc}_text where text_id=$textId" ); |
| 1620 | + $queryResult = $dbr->query( "SELECT text_text from {$dc}_text where text_id=$textId LIMIT 1" ); |
1621 | 1621 | |
1622 | 1622 | return $dbr->fetchObject( $queryResult )->text_text; |
1623 | 1623 | } |
— | — | @@ -1628,12 +1628,13 @@ |
1629 | 1629 | $dbr = wfGetDB( DB_SLAVE ); |
1630 | 1630 | |
1631 | 1631 | $spelling = $dbr->addQuotes( $spelling ); |
1632 | | - $queryResult = $dbr->query( "SELECT * FROM {$dc}_expression WHERE {$dc}_expression.spelling=$spelling AND " . getLatestTransactionRestriction( "{$dc}_expression" ) ); |
| 1632 | + $queryResult = $dbr->query( "SELECT * FROM {$dc}_expression WHERE spelling=$spelling AND " . getLatestTransactionRestriction( "{$dc}_expression" ) ); |
1633 | 1633 | |
1634 | 1634 | $rv = array(); |
1635 | 1635 | while ( $expressionRecord = $dbr->fetchObject( $queryResult ) ) { |
1636 | 1636 | $rv[] = new Expression( $expressionRecord->expression_id, $expressionRecord->spelling, $expressionRecord->language_id ); |
1637 | 1637 | } |
| 1638 | + $dbr->freeResult( $queryResult ) ; |
1638 | 1639 | return $rv; |
1639 | 1640 | |
1640 | 1641 | } |
— | — | @@ -1672,7 +1673,7 @@ |
1673 | 1674 | $qry .= 'AND ' . getLatestTransactionRestriction( 'trans' ); |
1674 | 1675 | $qry .= 'AND ' . getLatestTransactionRestriction( 'dm' ); |
1675 | 1676 | |
1676 | | - |
| 1677 | + |
1677 | 1678 | $definitions = $dbr->query( $qry ); |
1678 | 1679 | while ( $row = $dbr->fetchRow( $definitions ) ) { |
1679 | 1680 | // $key becomes something like def_23 |