Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php |
— | — | @@ -504,40 +504,10 @@ |
505 | 505 | |
506 | 506 | function deleteSubject(Title $subject) { |
507 | 507 | wfProfileIn("SMWSQLStore::deleteSubjects (SMW)"); |
| 508 | + $this->deleteSemanticData($subject); |
508 | 509 | $db =& wfGetDB( DB_MASTER ); |
509 | | - $db->delete('smw_relations', |
510 | | - array('subject_id' => $subject->getArticleID()), |
511 | | - 'SMW::deleteSubject::Relations'); |
| 510 | + // also delete any occurence of subject in object positions: |
512 | 511 | $db->update('smw_relations', array('object_id' => NULL), array('object_id' => $subject->getArticleID()), 'SMW::deleteSubject::RelationObj'); |
513 | | - $db->delete('smw_attributes', |
514 | | - array('subject_id' => $subject->getArticleID()), |
515 | | - 'SMW::deleteSubject::Attributes'); |
516 | | - $db->delete('smw_longstrings', |
517 | | - array('subject_id' => $subject->getArticleID()), |
518 | | - 'SMW::deleteSubject::Longstrings'); |
519 | | - $db->delete('smw_specialprops', |
520 | | - array('subject_id' => $subject->getArticleID()), |
521 | | - 'SMW::deleteSubject::Specialprops'); |
522 | | - $db->delete('smw_nary', |
523 | | - array('subject_id' => $subject->getArticleID()), |
524 | | - 'SMW::deleteSubject::NAry'); |
525 | | - if ($db->affectedRows() != 0) { |
526 | | - $db->delete('smw_nary_relations', |
527 | | - array('subject_id' => $subject->getArticleID()), |
528 | | - 'SMW::deleteSubject::NAryRelations'); |
529 | | - $db->update('smw_nary_relations', array('object_id' => NULL), array('object_id' => $subject->getArticleID()), 'SMW::deleteSubject::NAryRelationsObj'); |
530 | | - $db->delete('smw_nary_attributes', |
531 | | - array('subject_id' => $subject->getArticleID()), |
532 | | - 'SMW::deleteSubject::NAryAttributes'); |
533 | | - $db->delete('smw_nary_longstrings', |
534 | | - array('subject_id' => $subject->getArticleID()), |
535 | | - 'SMW::deleteSubject::NaryLongstrings'); |
536 | | - } |
537 | | - if ( $subject->getNamespace() == SMW_NS_PROPERTY ) { |
538 | | - $db->delete('smw_subprops', |
539 | | - array('subject_title' => $subject->getDBKey()), |
540 | | - 'SMW::deleteSubject::Subprops'); |
541 | | - } |
542 | 512 | wfProfileOut("SMWSQLStore::deleteSubjects (SMW)"); |
543 | 513 | } |
544 | 514 | |
— | — | @@ -545,7 +515,7 @@ |
546 | 516 | wfProfileIn("SMWSQLStore::updateData (SMW)"); |
547 | 517 | $db =& wfGetDB( DB_MASTER ); |
548 | 518 | $subject = $data->getSubject(); |
549 | | - $this->deleteSubject($subject); |
| 519 | + $this->deleteSemanticData($subject); |
550 | 520 | |
551 | 521 | // do bulk updates: |
552 | 522 | $up_relations = array(); |
— | — | @@ -1179,6 +1149,46 @@ |
1180 | 1150 | } |
1181 | 1151 | return $sql_conds; |
1182 | 1152 | } |
| 1153 | + |
| 1154 | + /** |
| 1155 | + * Delete all semantic data stored for the given subject. |
| 1156 | + * Used for update purposes. |
| 1157 | + */ |
| 1158 | + protected function deleteSemanticData(Title $subject) { |
| 1159 | + $db =& wfGetDB( DB_MASTER ); |
| 1160 | + $db->delete('smw_relations', |
| 1161 | + array('subject_id' => $subject->getArticleID()), |
| 1162 | + 'SMW::deleteSubject::Relations'); |
| 1163 | + $db->delete('smw_attributes', |
| 1164 | + array('subject_id' => $subject->getArticleID()), |
| 1165 | + 'SMW::deleteSubject::Attributes'); |
| 1166 | + $db->delete('smw_longstrings', |
| 1167 | + array('subject_id' => $subject->getArticleID()), |
| 1168 | + 'SMW::deleteSubject::Longstrings'); |
| 1169 | + $db->delete('smw_specialprops', |
| 1170 | + array('subject_id' => $subject->getArticleID()), |
| 1171 | + 'SMW::deleteSubject::Specialprops'); |
| 1172 | + $db->delete('smw_nary', |
| 1173 | + array('subject_id' => $subject->getArticleID()), |
| 1174 | + 'SMW::deleteSubject::NAry'); |
| 1175 | + if ($db->affectedRows() != 0) { |
| 1176 | + $db->delete('smw_nary_relations', |
| 1177 | + array('subject_id' => $subject->getArticleID()), |
| 1178 | + 'SMW::deleteSubject::NAryRelations'); |
| 1179 | + $db->update('smw_nary_relations', array('object_id' => NULL), array('object_id' => $subject->getArticleID()), 'SMW::deleteSubject::NAryRelationsObj'); |
| 1180 | + $db->delete('smw_nary_attributes', |
| 1181 | + array('subject_id' => $subject->getArticleID()), |
| 1182 | + 'SMW::deleteSubject::NAryAttributes'); |
| 1183 | + $db->delete('smw_nary_longstrings', |
| 1184 | + array('subject_id' => $subject->getArticleID()), |
| 1185 | + 'SMW::deleteSubject::NaryLongstrings'); |
| 1186 | + } |
| 1187 | + if ( $subject->getNamespace() == SMW_NS_PROPERTY ) { |
| 1188 | + $db->delete('smw_subprops', |
| 1189 | + array('subject_title' => $subject->getDBKey()), |
| 1190 | + 'SMW::deleteSubject::Subprops'); |
| 1191 | + } |
| 1192 | + } |
1183 | 1193 | |
1184 | 1194 | /** |
1185 | 1195 | * Find out if the given page is a redirect and determine its target. |