Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php |
— | — | @@ -190,7 +190,7 @@ |
191 | 191 | |
192 | 192 | $id = SMWDataValueFactory::getPropertyObjectTypeID($property); |
193 | 193 | switch ($id) { |
194 | | - case '_txt': // long text property |
| 194 | + case '_txt': |
195 | 195 | $res = $db->select( $db->tableName('smw_longstrings'), |
196 | 196 | 'value_blob', |
197 | 197 | 'subject_id=' . $db->addQuotes($subject->getArticleID()) . |
— | — | @@ -204,7 +204,7 @@ |
205 | 205 | } |
206 | 206 | $db->freeResult($res); |
207 | 207 | break; |
208 | | - case '_wpg': // wiki page |
| 208 | + case '_wpg': |
209 | 209 | $res = $db->select( $db->tableName('smw_relations'), |
210 | 210 | 'object_title, object_namespace', |
211 | 211 | 'subject_id=' . $db->addQuotes($subject->getArticleID()) . |
— | — | @@ -219,7 +219,77 @@ |
220 | 220 | } |
221 | 221 | $db->freeResult($res); |
222 | 222 | break; |
223 | | - default: // all others |
| 223 | + case '__nry': |
| 224 | + $type = SMWDataValueFactory::getPropertyObjectTypeValue($property); |
| 225 | + $subtypes = $type->getTypeValues(); |
| 226 | + $res = $db->select( $db->tableName('smw_nary'), |
| 227 | + 'nary_key', |
| 228 | + 'subject_id=' . $db->addQuotes($subject->getArticleID()) . |
| 229 | + ' AND attribute_title=' . $db->addQuotes($property->getDBkey()), |
| 230 | + 'SMW::getPropertyValues', $this->getSQLOptions($requestoptions) ); |
| 231 | + ///TODO: presumably slow. Try to do less SQL queries by making a join with smw_nary |
| 232 | + while($row = $db->fetchObject($res)) { |
| 233 | + $res2 = $db->select( $db->tableName('smw_nary_attributes'), |
| 234 | + 'nary_pos, value_unit, value_xsd', |
| 235 | + 'subject_id=' . $db->addQuotes($subject->getArticleID()) . |
| 236 | + ' AND nary_key=' . $db->addQuotes($row->nary_key), |
| 237 | + 'SMW::getPropertyValues'); |
| 238 | + while($row2 = $db->fetchObject($res2)) { |
| 239 | + if ($row2->nary_pos < count($subtypes)) { |
| 240 | + $dv = SMWDataValueFactory::newTypeObjectValue($subtypes[$row2->nary_pos]); |
| 241 | + $dv->setXSDValue($row2->value_xsd, $row2->value_unit); |
| 242 | + $values[$row2->nary_pos] = $dv; |
| 243 | + } |
| 244 | + } |
| 245 | + $res2 = $db->select( $db->tableName('smw_nary_longstrings'), |
| 246 | + 'nary_pos, value_blob', |
| 247 | + 'subject_id=' . $db->addQuotes($subject->getArticleID()) . |
| 248 | + ' AND nary_key=' . $db->addQuotes($row->nary_key), |
| 249 | + 'SMW::getPropertyValues'); |
| 250 | + while($row2 = $db->fetchObject($res2)) { |
| 251 | + if ( $row2->nary_pos < count($subtypes) ) { |
| 252 | + $dv = SMWDataValueFactory::newTypeObjectValue($subtypes[$row2->nary_pos]); |
| 253 | + $dv->setXSDValue($row2->value_blob, ''); |
| 254 | + $values[$row2->nary_pos] = $dv; |
| 255 | + } |
| 256 | + } |
| 257 | + $res2 = $db->select( $db->tableName('smw_nary_relations'), |
| 258 | + 'nary_pos, object_title, object_namespace', |
| 259 | + 'subject_id=' . $db->addQuotes($subject->getArticleID()) . |
| 260 | + ' AND nary_key=' . $db->addQuotes($row->nary_key), |
| 261 | + 'SMW::getPropertyValues'); |
| 262 | + while($row2 = $db->fetchObject($res2)) { |
| 263 | + if ( ($row2->nary_pos < count($subtypes)) && |
| 264 | + ($subtypes[$row2->nary_pos]->getXSDValue() == '_wpg') ) { |
| 265 | + $dv = SMWDataValueFactory::newTypeIDValue('_wpg'); |
| 266 | + $dv->setValues($row2->object_title, $row2->object_namespace); |
| 267 | + $values[$row2->nary_pos] = $dv; |
| 268 | + } |
| 269 | + } |
| 270 | + $db->freeResult($res2); |
| 271 | + $uservalue = ''; /// hack hack hack |
| 272 | + $first = true; |
| 273 | + for ($i=0; $i<count($subtypes); $i++) { |
| 274 | +// if (!array_key_exists($i, $values) { |
| 275 | +// $values[$i] = NULL; |
| 276 | +// } |
| 277 | + if ($first) { |
| 278 | + $first = false; |
| 279 | + } else { |
| 280 | + $uservalue .= ';'; |
| 281 | + } |
| 282 | + if (array_key_exists($i, $values)) { |
| 283 | + $uservalue .= $values[$i]->getWikiValue(); |
| 284 | + } |
| 285 | + } |
| 286 | + $dv = SMWDataValueFactory::newPropertyObjectValue($property); |
| 287 | + $dv->setOutputFormat($outputformat); |
| 288 | + $dv->setUserValue($uservalue); |
| 289 | + $result[] = $dv; |
| 290 | + } |
| 291 | + $db->freeResult($res); |
| 292 | + break; |
| 293 | + default: |
224 | 294 | if ( ($requestoptions !== NULL) && ($requestoptions->boundary !== NULL) && |
225 | 295 | ($requestoptions->boundary->isNumeric()) ) { |
226 | 296 | $value_column = 'value_num'; |
— | — | @@ -288,48 +358,39 @@ |
289 | 359 | |
290 | 360 | function getAllPropertySubjects(Title $property, $requestoptions = NULL) { |
291 | 361 | $db =& wfGetDB( DB_SLAVE ); |
292 | | - $sql = 'attribute_title=' . $db->addQuotes($property->getDBkey()) . |
293 | | - $this->getSQLConditions($requestoptions,'subject_title','subject_title'); |
294 | | - |
295 | | - $result = array(); |
296 | 362 | $id = SMWDataValueFactory::getPropertyObjectTypeID($property); |
297 | 363 | switch ($id) { |
298 | 364 | case '_txt': |
299 | | - $res = $db->select( $db->tableName('smw_longstrings'), |
300 | | - 'DISTINCT subject_id', |
301 | | - $sql, 'SMW::getAllPropertySubjects', |
302 | | - $this->getSQLOptions($requestoptions,'subject_title') ); |
303 | | - if($db->numRows( $res ) > 0) { |
304 | | - while($row = $db->fetchObject($res)) { |
305 | | - $result[] = Title::newFromId($row->subject_id); |
306 | | - } |
307 | | - } |
308 | | - $db->freeResult($res); |
| 365 | + $tablename = 'smw_longstrings'; |
| 366 | + $pcolumn = 'attribute_title'; |
| 367 | + $extraconds = ''; |
309 | 368 | break; |
310 | 369 | case '_wpg': |
311 | | - $sql = 'relation_title=' . $db->addQuotes($property->getDBkey()) . |
312 | | - $this->getSQLConditions($requestoptions,'subject_title','subject_title'); |
313 | | - $res = $db->select( $db->tableName('smw_relations'), |
314 | | - 'DISTINCT subject_id', |
315 | | - $sql, 'SMW::getAllPropertySubjects', |
316 | | - $this->getSQLOptions($requestoptions,'subject_title') ); |
317 | | - while($row = $db->fetchObject($res)) { |
318 | | - $result[] = Title::newFromId($row->subject_id); |
319 | | - } |
320 | | - $db->freeResult($res); |
| 370 | + $tablename = 'smw_relations'; |
| 371 | + $pcolumn = 'relation_title'; |
| 372 | + $extraconds = $this->getSQLConditions($requestoptions,'subject_title','subject_title'); |
321 | 373 | break; |
| 374 | + case '__nry': |
| 375 | + $tablename = 'smw_nary'; |
| 376 | + $pcolumn = 'attribute_title'; |
| 377 | + $extraconds = $this->getSQLConditions($requestoptions,'subject_title','subject_title'); |
| 378 | + break; |
322 | 379 | default: |
323 | | - $res = $db->select( $db->tableName('smw_attributes'), |
324 | | - 'DISTINCT subject_id', |
325 | | - $sql, 'SMW::getAllPropertySubjects', |
326 | | - $this->getSQLOptions($requestoptions,'subject_title') ); |
327 | | - if($db->numRows( $res ) > 0) { |
328 | | - while($row = $db->fetchObject($res)) { |
329 | | - $result[] = Title::newFromId($row->subject_id); |
330 | | - } |
331 | | - } |
332 | | - $db->freeResult($res); |
| 380 | + $tablename = 'smw_attributes'; |
| 381 | + $pcolumn = 'attribute_title'; |
| 382 | + $extraconds = $this->getSQLConditions($requestoptions,'subject_title','subject_title'); |
333 | 383 | } |
| 384 | + |
| 385 | + $res = $db->select( $db->tableName($tablename), |
| 386 | + 'DISTINCT subject_id', |
| 387 | + $pcolumn .'=' . $db->addQuotes($property->getDBkey()) . $extraconds, |
| 388 | + 'SMW::getAllPropertySubjects', |
| 389 | + $this->getSQLOptions($requestoptions,'subject_title') ); |
| 390 | + $result = array(); |
| 391 | + while($row = $db->fetchObject($res)) { |
| 392 | + $result[] = Title::newFromId($row->subject_id); |
| 393 | + } |
| 394 | + $db->freeResult($res); |
334 | 395 | return $result; |
335 | 396 | } |
336 | 397 | |
— | — | @@ -368,6 +429,15 @@ |
369 | 430 | } |
370 | 431 | } |
371 | 432 | $db->freeResult($res); |
| 433 | + $res = $db->select( $db->tableName('smw_nary'), |
| 434 | + 'DISTINCT attribute_title', |
| 435 | + $sql, 'SMW::getProperties', $this->getSQLOptions($requestoptions,'attribute_title') ); |
| 436 | + if ($db->numRows( $res ) > 0) { |
| 437 | + while($row = $db->fetchObject($res)) { |
| 438 | + $result[] = Title::newFromText($row->attribute_title, SMW_NS_PROPERTY); |
| 439 | + } |
| 440 | + } |
| 441 | + $db->freeResult($res); |
372 | 442 | |
373 | 443 | return $result; |
374 | 444 | } |
— | — | @@ -410,17 +480,19 @@ |
411 | 481 | $db->delete('smw_nary', |
412 | 482 | array('subject_id' => $subject->getArticleID()), |
413 | 483 | 'SMW::deleteSubject::NAry'); |
| 484 | + if ($db->affectedRows() != 0) { |
414 | 485 | ///FIXME: check there were entries in smw_nary before continuing! |
415 | 486 | /// "Affected rows" should be easy to get |
416 | | - $db->delete('smw_nary_relations', |
417 | | - array('subject_id' => $subject->getArticleID()), |
418 | | - 'SMW::deleteSubject::NAryRelations'); |
419 | | - $db->delete('smw_nary_attributes', |
420 | | - array('subject_id' => $subject->getArticleID()), |
421 | | - 'SMW::deleteSubject::NAryAttributes'); |
422 | | - $db->delete('smw_nary_longstrings', |
423 | | - array('subject_id' => $subject->getArticleID()), |
424 | | - 'SMW::deleteSubject::NaryLongstrings'); |
| 487 | + $db->delete('smw_nary_relations', |
| 488 | + array('subject_id' => $subject->getArticleID()), |
| 489 | + 'SMW::deleteSubject::NAryRelations'); |
| 490 | + $db->delete('smw_nary_attributes', |
| 491 | + array('subject_id' => $subject->getArticleID()), |
| 492 | + 'SMW::deleteSubject::NAryAttributes'); |
| 493 | + $db->delete('smw_nary_longstrings', |
| 494 | + array('subject_id' => $subject->getArticleID()), |
| 495 | + 'SMW::deleteSubject::NaryLongstrings'); |
| 496 | + } |
425 | 497 | if ( $subject->getNamespace() == SMW_NS_PROPERTY ) { |
426 | 498 | $db->delete('smw_subprops', |
427 | 499 | array('subject_title' => $subject->getDBKey()), |
— | — | @@ -475,30 +547,32 @@ |
476 | 548 | 'nary_key' => $nkey ); |
477 | 549 | $npos = 0; |
478 | 550 | foreach ($value->getDVs() as $dv) { |
479 | | - switch ($dv->getTypeID()) { |
480 | | - case '_wpg': |
481 | | - $up_nary_relations[] = |
482 | | - array( 'subject_id' => $subject->getArticleID(), |
483 | | - 'nary_key' => $nkey, |
484 | | - 'nary_pos' => $npos, |
485 | | - 'object_namespace' => $dv->getNamespace(), |
486 | | - 'object_title' => $dv->getDBkey() ); |
487 | | - break; |
488 | | - case '_txt': |
489 | | - $up_nary_longstrings[] = |
490 | | - array( 'subject_id' => $subject->getArticleID(), |
491 | | - 'nary_key' => $nkey, |
492 | | - 'nary_pos' => $npos, |
493 | | - 'value_blob' => $dv->getXSDValue() ); |
494 | | - break; |
495 | | - default: |
496 | | - $up_nary_attributes[] = |
497 | | - array( 'subject_id' => $subject->getArticleID(), |
498 | | - 'nary_key' => $nkey, |
499 | | - 'nary_pos' => $npos, |
500 | | - 'value_unit' => $dv->getUnit(), |
501 | | - 'value_xsd' => $dv->getXSDValue(), |
502 | | - 'value_num' => $dv->getNumericValue() ); |
| 551 | + if ( ($dv !== NULL) && ($dv->isValid()) ) { |
| 552 | + switch ($dv->getTypeID()) { |
| 553 | + case '_wpg': |
| 554 | + $up_nary_relations[] = |
| 555 | + array( 'subject_id' => $subject->getArticleID(), |
| 556 | + 'nary_key' => $nkey, |
| 557 | + 'nary_pos' => $npos, |
| 558 | + 'object_namespace' => $dv->getNamespace(), |
| 559 | + 'object_title' => $dv->getDBkey() ); |
| 560 | + break; |
| 561 | + case '_txt': |
| 562 | + $up_nary_longstrings[] = |
| 563 | + array( 'subject_id' => $subject->getArticleID(), |
| 564 | + 'nary_key' => $nkey, |
| 565 | + 'nary_pos' => $npos, |
| 566 | + 'value_blob' => $dv->getXSDValue() ); |
| 567 | + break; |
| 568 | + default: |
| 569 | + $up_nary_attributes[] = |
| 570 | + array( 'subject_id' => $subject->getArticleID(), |
| 571 | + 'nary_key' => $nkey, |
| 572 | + 'nary_pos' => $npos, |
| 573 | + 'value_unit' => $dv->getUnit(), |
| 574 | + 'value_xsd' => $dv->getXSDValue(), |
| 575 | + 'value_num' => $dv->getNumericValue() ); |
| 576 | + } |
503 | 577 | } |
504 | 578 | $npos++; |
505 | 579 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php |
— | — | @@ -185,8 +185,10 @@ |
186 | 186 | */ |
187 | 187 | public function getTypeValues() { |
188 | 188 | $result = array(); |
| 189 | + $i = 0; |
189 | 190 | foreach ($this->getTypeLabels() as $tl) { |
190 | | - $result[] = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE, $tl); |
| 191 | + $result[$i] = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE, $tl); |
| 192 | + $i++; |
191 | 193 | } |
192 | 194 | return $result; |
193 | 195 | } |