r75928 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75927‎ | r75928 | r75929 >
Date:13:52, 3 November 2010
Author:yaron
Status:deferred
Tags:
Comment:
Added back handling of deletion of pages (unintentionally removed in 0.6.1); rearranged some functions; added more comments
Modified paths:
  • /trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php
@@ -106,9 +106,12 @@
107107 * protected, and thus can't be accessed externally.
108108 */
109109 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();
112114
 115+ // Get the set of IDs for internal objects to be deleted.
113116 $iw = '';
114117 $db = wfGetDB( DB_SLAVE );
115118 $res = $db->select(
@@ -118,11 +121,30 @@
119122 'SIO::getSMWPageObjectIDs'
120123 );
121124 while ( $row = $db->fetchObject( $res ) ) {
122 - $ids[] = $row->smw_id;
 125+ $idsForDeletion[] = $row->smw_id;
123126 }
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+ }
125143 }
126144
 145+ /**
 146+ * Returns the set of SQL values needed to insert the data for this
 147+ * internal object into the database.
 148+ */
127149 function getStorageSQL( $internalObject ) {
128150 $ioID = $this->makeSMWPageID( $internalObject->getName(), $internalObject->getNamespace(), '' );
129151 $upRels2 = array();
@@ -232,6 +254,10 @@
233255 static $mInternalObjects = array();
234256 static $mHandledPages = array();
235257
 258+ /**
 259+ * Called with the 'ParserClearState' hook, when more than one page
 260+ * is parsed in a single action.
 261+ */
236262 public static function clearState( &$parser ) {
237263 // For some reason, the #set_internal calls on a page are
238264 // sometimes called twice (or more?). Ideally, there would
@@ -248,6 +274,9 @@
249275 return true;
250276 }
251277
 278+ /**
 279+ * Handle the #set_internal parser function.
 280+ */
252281 public static function doSetInternal( &$parser ) {
253282 $title = $parser->getTitle();
254283 $mainPageFullName = $title->getText();
@@ -294,6 +323,9 @@
295324 self::$mInternalObjects[] = $internalObject;
296325 }
297326
 327+ /**
 328+ * Handle the #set_internal_recurring_event parser function.
 329+ */
298330 public static function doSetInternalRecurringEvent( &$parser ) {
299331 $params = func_get_args();
300332 array_shift( $params ); // We already know the $parser ...
@@ -320,6 +352,19 @@
321353 }
322354 }
323355
 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+ */
324369 public static function updateData( $sqlStore, $data ) {
325370 $sioSQLStore = new SIOSQLStore();
326371 // Find all "pages" in the SMW IDs table that are internal
@@ -328,9 +373,7 @@
329374 // Then save the current contents of the $mInternalObjects
330375 // array.
331376 $subject = $data->getSubject();
332 - $pageName = $subject->getDBKey();
333 - $namespace = $subject->getNamespace();
334 - $idsForDeletion = SIOSQLStore::getIDsForDeletion( $pageName, $namespace );
 377+ SIOSQLStore::deleteDataForPage( $subject );
335378
336379 $allRels2Inserts = array();
337380 $allAtts2Inserts = array();
@@ -347,17 +390,6 @@
348391 // now save everything to the database, in a single transaction
349392 $db = wfGetDB( DB_MASTER );
350393 $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 - }
362394
363395 if ( count( $allRels2Inserts ) > 0 ) {
364396 $db->insert( 'smw_rels2', $allRels2Inserts, 'SIO::updateRels2Data' );

Status & tagging log