Show
Ignore:
Timestamp:
05/18/06 14:32:00 (6 years ago)
Author:
nick
Message:

Support for preserving internal_links when doing a drop+recreate

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/Database.pm

    r288 r290  
    2525        my %metadatas; 
    2626        my %contents; 
     27        my @internal_links; 
    2728        my %ids; 
    2829 
     
    8586        } 
    8687 
     88        # Grab all the internal links 
     89        $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links"); 
     90        $sth->execute; 
     91        while( my($link_from,$link_to) = $sth->fetchrow_array) { 
     92                my %il; 
     93                $il{'link_from'} = $link_from; 
     94                $il{'link_to'} = $link_to; 
     95                push @internal_links, \%il; 
     96        } 
     97 
    8798        print "done\n"; 
    8899 
    89100        # Return it all 
    90         return (\%nodes,\%contents,\%metadatas,\%ids); 
     101        return (\%nodes,\%contents,\%metadatas,\@internal_links,\%ids); 
    91102} 
    92103# Fetch from schema version 8, and upgrade to version 9 
     
    96107        my %metadatas; 
    97108        my %contents; 
     109        my @internal_links; 
    98110 
    99111        print "Grabbing and upgrading old data... "; 
     
    140152        } 
    141153 
     154        # Grab all the internal links 
     155        $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links"); 
     156        $sth->execute; 
     157        while( my($link_from,$link_to) = $sth->fetchrow_array) { 
     158                my %il; 
     159                $il{'link_from'} = $link_from; 
     160                $il{'link_to'} = $link_to; 
     161                push @internal_links, \%il; 
     162        } 
     163 
    142164        print "done\n"; 
    143165 
    144166        # Return it all 
    145         return (\%nodes,\%contents,\%metadatas); 
     167        return (\%nodes,\%contents,\%metadatas,\@internal_links); 
    146168} 
    147169 
     
    183205# Put the latest data into the latest database structure 
    184206sub bulk_data_insert { 
    185         my ($dbh, $nodesref, $contentsref, $metadataref) = @_; 
     207        my ($dbh, $nodesref, $contentsref, $metadataref, $internallinksref) = @_; 
    186208 
    187209        print "Bulk inserting upgraded data... "; 
     
    212234        } 
    213235 
    214         # Add metadata 
    215         $sth = $dbh->prepare("INSERT INTO metadata (node_id,version,metadata_type,metadata_value) VALUES (?,?,?,?)"); 
    216         foreach my $key (keys %$metadataref) { 
    217                 my %metadata = %{$metadataref->{$key}}; 
    218                 $sth->execute($metadata{'node_id'}, 
     236    # Add metadata 
     237    $sth = $dbh->prepare("INSERT INTO metadata (node_id,version,metadata_type,metadata_value) VALUES (?,?,?,?)"); 
     238    foreach my $key (keys %$metadataref) { 
     239        my %metadata = %{$metadataref->{$key}}; 
     240        $sth->execute($metadata{'node_id'}, 
    219241                      $metadata{'version'}, 
    220242                      $metadata{'metadata_type'}, 
    221243                      $metadata{'metadata_value'}); 
    222         } 
    223  
    224         print "done\n"; 
    225 } 
     244    } 
     245 
     246    # Add internal links 
     247    $sth = $dbh->prepare("INSERT INTO internal_links (link_from,link_to) VALUES (?,?)"); 
     248    foreach my $ilr (@$internallinksref) { 
     249        my %il = %{$ilr}; 
     250        $sth->execute($il{'link_from'}, 
     251                      $il{'link_to'}); 
     252    } 
     253 
     254    print "done\n"; 
     255}