Add mCascadingDeletes and mCleanupTriggers properties to Database*, use accessor...
authorGreg Sabino Mullane <greg@users.mediawiki.org>
Mon, 17 Jul 2006 00:54:40 +0000 (00:54 +0000)
committerGreg Sabino Mullane <greg@users.mediawiki.org>
Mon, 17 Jul 2006 00:54:40 +0000 (00:54 +0000)
includes/Article.php
includes/Database.php
includes/DatabasePostgres.php

index 6416889..f5d1de6 100644 (file)
@@ -1910,29 +1910,35 @@ class Article {
                );
 
                # Now that it's safely backed up, delete it
-               $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
                $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__);
 
-               if ($wgUseTrackbacks)
-                       $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
+               # If using cascading deletes, we can skip some explicit deletes
+               if ( !$dbw->cascadingDeletes() ) {
+
+                       $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
 
-               # Clean up recentchanges entries...
-               $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__ );
+                       if ($wgUseTrackbacks)
+                               $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
+
+                       # Delete outgoing links
+                       $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
+                       $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
+                       $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
+                       $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
+                       $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
+                       $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
+               }
 
-               # Finally, clean up the link tables
-               $t = $this->mTitle->getPrefixedDBkey();
+               # If using cleanup triggers, we can skip some manual deletes
+               if ( !$dbw->cleanupTriggers() ) {
+
+                       # Clean up recentchanges entries...
+                       $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__ );
+               }
 
                # Clear caches
                Article::onArticleDelete( $this->mTitle );
 
-               # Delete outgoing links
-               $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
-               $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
-               $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
-               $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
-               $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
-               $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
-
                # Log the deletion
                $log = new LogPage( 'delete' );
                $log->addEntry( 'delete', $this->mTitle, $reason );
index 79de313..7ffa294 100644 (file)
@@ -244,6 +244,8 @@ class Database {
        protected $mTrxLevel = 0;
        protected $mErrorCount = 0;
        protected $mLBInfo = array();
+       protected $mCascadingDeletes = false;
+       protected $mCleanupTriggers = false;
 
 #------------------------------------------------------------------------------
 # Accessors
@@ -334,6 +336,20 @@ class Database {
                }
        }
 
+       /**
+        * Returns true if this database supports (and uses) cascading deletes
+        */
+       function cascadingDeletes() {
+               return $this->mCascadingDeletes;
+       }
+
+       /**
+        * Returns true if this database supports (and uses) triggers (e.g. on the page table)
+        */
+       function cleanupTriggers() {
+               return $this->mCleanupTriggers;
+       }
+
        /**#@+
         * Get function
         */
index f9c1def..b0dfb74 100644 (file)
@@ -30,8 +30,9 @@ class DatabasePostgres extends Database {
                }
                $this->mOut =& $wgOut;
                $this->mFailFunction = $failFunction;
+               $this->mCascadingDeletes = true;
+               $this->mCleanupTriggers = true;
                $this->mFlags = $flags;
-
                $this->open( $server, $user, $password, $dbName);
 
        }