Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php |
— | — | @@ -106,9 +106,12 @@ |
107 | 107 | * protected, and thus can't be accessed externally. |
108 | 108 | */ |
109 | 109 | class SIOSQLStore extends SMWSQLStore2 { |
110 | | - static function getIDsForDeletion( $pageName, $namespace ) { |
111 | | - $ids = array(); |
| 110 | + static function deleteDataForPage( $subject ) { |
| 111 | + $pageName = $subject->getDBKey(); |
| 112 | + $namespace = $subject->getNamespace(); |
| 113 | + $idsForDeletion = array(); |
112 | 114 | |
| 115 | + // Get the set of IDs for internal objects to be deleted. |
113 | 116 | $iw = ''; |
114 | 117 | $db = wfGetDB( DB_SLAVE ); |
115 | 118 | $res = $db->select( |
— | — | @@ -118,11 +121,30 @@ |
119 | 122 | 'SIO::getSMWPageObjectIDs' |
120 | 123 | ); |
121 | 124 | while ( $row = $db->fetchObject( $res ) ) { |
122 | | - $ids[] = $row->smw_id; |
| 125 | + $idsForDeletion[] = $row->smw_id; |
123 | 126 | } |
124 | | - return $ids; |
| 127 | + |
| 128 | + if ( count( $idsForDeletion ) == 0 ) { |
| 129 | + return; |
| 130 | + } |
| 131 | + |
| 132 | + // Now, do the deletion. |
| 133 | + $db = wfGetDB( DB_MASTER ); |
| 134 | + $idsString = '(' . implode ( ', ', $idsForDeletion ) . ')'; |
| 135 | + $db->delete( 'smw_rels2', array( "(s_id IN $idsString) OR (o_id IN $idsString)" ), 'SIO::deleteRels2Data' ); |
| 136 | + $db->delete( 'smw_atts2', array( "s_id IN $idsString" ), 'SIO::deleteAtts2Data' ); |
| 137 | + $db->delete( 'smw_text2', array( "s_id IN $idsString" ), 'SIO::deleteText2Data' ); |
| 138 | + // Handle the sm_coords table only if the Semantic Maps |
| 139 | + // extension is installed and uses sm_coords. |
| 140 | + if ( defined( 'SM_VERSION' ) && version_compare( SM_VERSION, '0.6' ) >= 0 ) { |
| 141 | + $db->delete( 'sm_coords', array( "s_id IN $idsString" ), 'SIO::deleteCoordsData' ); |
| 142 | + } |
125 | 143 | } |
126 | 144 | |
| 145 | + /** |
| 146 | + * Returns the set of SQL values needed to insert the data for this |
| 147 | + * internal object into the database. |
| 148 | + */ |
127 | 149 | function getStorageSQL( $internalObject ) { |
128 | 150 | $ioID = $this->makeSMWPageID( $internalObject->getName(), $internalObject->getNamespace(), '' ); |
129 | 151 | $upRels2 = array(); |
— | — | @@ -232,6 +254,10 @@ |
233 | 255 | static $mInternalObjects = array(); |
234 | 256 | static $mHandledPages = array(); |
235 | 257 | |
| 258 | + /** |
| 259 | + * Called with the 'ParserClearState' hook, when more than one page |
| 260 | + * is parsed in a single action. |
| 261 | + */ |
236 | 262 | public static function clearState( &$parser ) { |
237 | 263 | // For some reason, the #set_internal calls on a page are |
238 | 264 | // sometimes called twice (or more?). Ideally, there would |
— | — | @@ -248,6 +274,9 @@ |
249 | 275 | return true; |
250 | 276 | } |
251 | 277 | |
| 278 | + /** |
| 279 | + * Handle the #set_internal parser function. |
| 280 | + */ |
252 | 281 | public static function doSetInternal( &$parser ) { |
253 | 282 | $title = $parser->getTitle(); |
254 | 283 | $mainPageFullName = $title->getText(); |
— | — | @@ -294,6 +323,9 @@ |
295 | 324 | self::$mInternalObjects[] = $internalObject; |
296 | 325 | } |
297 | 326 | |
| 327 | + /** |
| 328 | + * Handle the #set_internal_recurring_event parser function. |
| 329 | + */ |
298 | 330 | public static function doSetInternalRecurringEvent( &$parser ) { |
299 | 331 | $params = func_get_args(); |
300 | 332 | array_shift( $params ); // We already know the $parser ... |
— | — | @@ -320,6 +352,19 @@ |
321 | 353 | } |
322 | 354 | } |
323 | 355 | |
| 356 | + /** |
| 357 | + * Called when a page is deleted. |
| 358 | + */ |
| 359 | + public static function deleteData( $sqlStore, $subject ) { |
| 360 | + SIOSQLStore::deleteDataForPage( $subject ); |
| 361 | + return true; |
| 362 | + } |
| 363 | + |
| 364 | + /** |
| 365 | + * Called when a page's semantic data is updated - either it's been |
| 366 | + * modified, or one of its templates has been modified, or an SMW |
| 367 | + * "refresh data" action has been called. |
| 368 | + */ |
324 | 369 | public static function updateData( $sqlStore, $data ) { |
325 | 370 | $sioSQLStore = new SIOSQLStore(); |
326 | 371 | // Find all "pages" in the SMW IDs table that are internal |
— | — | @@ -328,9 +373,7 @@ |
329 | 374 | // Then save the current contents of the $mInternalObjects |
330 | 375 | // array. |
331 | 376 | $subject = $data->getSubject(); |
332 | | - $pageName = $subject->getDBKey(); |
333 | | - $namespace = $subject->getNamespace(); |
334 | | - $idsForDeletion = SIOSQLStore::getIDsForDeletion( $pageName, $namespace ); |
| 377 | + SIOSQLStore::deleteDataForPage( $subject ); |
335 | 378 | |
336 | 379 | $allRels2Inserts = array(); |
337 | 380 | $allAtts2Inserts = array(); |
— | — | @@ -347,17 +390,6 @@ |
348 | 391 | // now save everything to the database, in a single transaction |
349 | 392 | $db = wfGetDB( DB_MASTER ); |
350 | 393 | $db->begin( 'SIO::updatePageData' ); |
351 | | - if ( count( $idsForDeletion ) > 0 ) { |
352 | | - $idsString = '(' . implode ( ', ', $idsForDeletion ) . ')'; |
353 | | - $db->delete( 'smw_rels2', array( "(s_id IN $idsString) OR (o_id IN $idsString)" ), 'SIO::deleteRels2Data' ); |
354 | | - $db->delete( 'smw_atts2', array( "s_id IN $idsString" ), 'SIO::deleteAtts2Data' ); |
355 | | - $db->delete( 'smw_text2', array( "s_id IN $idsString" ), 'SIO::deleteText2Data' ); |
356 | | - // handle the sm_coords table only if the Semantic |
357 | | - // Maps extension is installed and uses sm_coords |
358 | | - if ( defined( 'SM_VERSION' ) && version_compare( SM_VERSION, '0.6' ) >= 0 ) { |
359 | | - $db->delete( 'sm_coords', array( "s_id IN $idsString" ), 'SIO::deleteCoordsData' ); |
360 | | - } |
361 | | - } |
362 | 394 | |
363 | 395 | if ( count( $allRels2Inserts ) > 0 ) { |
364 | 396 | $db->insert( 'smw_rels2', $allRels2Inserts, 'SIO::updateRels2Data' ); |