From 7820bb78c6a3c4ae30e201a2eda20e1e22343054 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 23 May 2004 06:29:30 +0000 Subject: [PATCH] Fixed moveOverRedirect() -- incorrect link table handling evidenced by duplicate key error --- includes/Title.php | 49 +++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 255cc157bc..966c6d274e 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -935,27 +935,40 @@ class Title { $linksToOld = $this->getLinksTo(); $linksToNew = $nt->getLinksTo(); - # Make function to convert Titles to IDs - $titleToID = create_function('$t', 'return $t->getArticleID();'); - - # Reassign links to old title - if ( count( $linksToOld ) ) { - $sql = "UPDATE links SET l_to=$newid WHERE l_from IN ("; - $sql .= implode( ",", array_map( $titleToID, $linksToOld ) ); - $sql .= ")"; - wfQuery( $sql, DB_WRITE, $fname ); - } - - # Reassign links to new title - if ( count( $linksToNew ) ) { - $sql = "UPDATE links SET l_to=$oldid WHERE l_from IN ("; - $sql .= implode( ",", array_map( $titleToID, $linksToNew ) ); - $sql .= ")"; + # Delete them all + $sql = "DELETE FROM links WHERE l_to=$oldid OR l_to=$newid"; + wfQuery( $sql, DB_WRITE, $fname ); + + # Reinsert + if ( count( $linksToOld ) || count( $linksToNew )) { + $sql = "INSERT INTO links (l_from,l_to) VALUES "; + $first = true; + + # Insert links to old title + foreach ( $linksToOld as $linkTitle ) { + if ( $first ) { + $first = false; + } else { + $sql .= ","; + } + $id = $linkTitle->getArticleID(); + $sql .= "($id,$newid)"; + } + + # Insert links to new title + foreach ( $linksToNew as $linkTitle ) { + if ( $first ) { + $first = false; + } else { + $sql .= ","; + } + $id = $linkTitle->getArticleID(); + $sql .= "($id, $oldid)"; + } + wfQuery( $sql, DB_WRITE, $fname ); } - # Note: the insert below must be after the updates above! - # Now, we record the link from the redirect to the new title. # It should have no other outgoing links... $sql = "DELETE FROM links WHERE l_from={$newid}"; -- 2.20.1