| 24 | | my $dbh = shift; |
| 25 | | my %nodes; |
| 26 | | my %metadatas; |
| 27 | | my %contents; |
| 28 | | my @internal_links; |
| 29 | | my %ids; |
| 30 | | |
| 31 | | print "Grabbing and upgrading old data... "; |
| 32 | | |
| 33 | | # Grab all the nodes, and give them an ID |
| 34 | | my $sth = $dbh->prepare("SELECT name,version,text,modified FROM node"); |
| 35 | | $sth->execute; |
| 36 | | my $id = 0; |
| 37 | | while( my($name,$version,$text,$modified) = $sth->fetchrow_array) { |
| 38 | | my %node; |
| 39 | | $id++; |
| 40 | | $node{'name'} = $name; |
| 41 | | $node{'version'} = $version; |
| 42 | | $node{'text'} = $text; |
| 43 | | $node{'modified'} = $modified; |
| 44 | | $node{'id'} = $id; |
| 45 | | $node{'moderate'} = 0; |
| 46 | | $nodes{$name} = \%node; |
| 47 | | $ids{$name} = $id; |
| 48 | | } |
| 49 | | print " read $id nodes... "; |
| 50 | | |
| 51 | | # Grab all the content, and upgrade to ID from name |
| 52 | | $sth = $dbh->prepare("SELECT name,version,text,modified,comment FROM content"); |
| 53 | | $sth->execute; |
| 54 | | while ( my($name,$version,$text,$modified,$comment) = $sth->fetchrow_array) { |
| 55 | | my $id = $ids{$name}; |
| 56 | | if($id) { |
| 57 | | my %content; |
| 58 | | $content{'node_id'} = $id; |
| 59 | | $content{'version'} = $version; |
| 60 | | $content{'text'} = $text; |
| 61 | | $content{'modified'} = $modified; |
| 62 | | $content{'comment'} = $comment; |
| 63 | | $content{'moderated'} = 1; |
| 64 | | $contents{$id."-".$version} = \%content; |
| 65 | | } else { |
| 66 | | warn("There was no node entry for content with name '$name', unable to migrate it!"); |
| 67 | | } |
| 68 | | } |
| 69 | | print " read ".(scalar keys %contents)." contents... "; |
| 70 | | |
| 71 | | # Grab all the metadata, and upgrade to ID from node |
| 72 | | $sth = $dbh->prepare("SELECT node,version,metadata_type,metadata_value FROM metadata"); |
| 73 | | $sth->execute; |
| 74 | | my $i = 0; |
| 75 | | while( my($node,$version,$metadata_type,$metadata_value) = $sth->fetchrow_array) { |
| 76 | | my $id = $ids{$node}; |
| 77 | | if($id) { |
| 78 | | my %metadata; |
| 79 | | $metadata{'node_id'} = $id; |
| 80 | | $metadata{'version'} = $version; |
| 81 | | $metadata{'metadata_type'} = $metadata_type; |
| 82 | | $metadata{'metadata_value'} = $metadata_value; |
| 83 | | $metadatas{$id."-".($i++)} = \%metadata; |
| 84 | | } else { |
| 85 | | warn("There was no node entry for metadata with name (node) '$node', unable to migrate it!"); |
| 86 | | } |
| 87 | | } |
| 88 | | |
| 89 | | # Grab all the internal links |
| 90 | | $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links"); |
| 91 | | $sth->execute; |
| 92 | | while( my($link_from,$link_to) = $sth->fetchrow_array) { |
| 93 | | my %il; |
| 94 | | $il{'link_from'} = $link_from; |
| 95 | | $il{'link_to'} = $link_to; |
| 96 | | push @internal_links, \%il; |
| 97 | | } |
| 98 | | |
| 99 | | print "done\n"; |
| 100 | | |
| 101 | | # Return it all |
| 102 | | return (\%nodes,\%contents,\%metadatas,\@internal_links,\%ids); |
| | 24 | my $dbh = shift; |
| | 25 | my %nodes; |
| | 26 | my %metadatas; |
| | 27 | my %contents; |
| | 28 | my @internal_links; |
| | 29 | my %ids; |
| | 30 | |
| | 31 | print "Grabbing and upgrading old data... "; |
| | 32 | |
| | 33 | # Grab all the nodes, and give them an ID |
| | 34 | my $sth = $dbh->prepare("SELECT name,version,text,modified FROM node"); |
| | 35 | $sth->execute; |
| | 36 | my $id = 0; |
| | 37 | while( my($name,$version,$text,$modified) = $sth->fetchrow_array) { |
| | 38 | my %node; |
| | 39 | $id++; |
| | 40 | $node{'name'} = $name; |
| | 41 | $node{'version'} = $version; |
| | 42 | $node{'text'} = $text; |
| | 43 | $node{'modified'} = $modified; |
| | 44 | $node{'id'} = $id; |
| | 45 | $node{'moderate'} = 0; |
| | 46 | $nodes{$name} = \%node; |
| | 47 | $ids{$name} = $id; |
| | 48 | } |
| | 49 | print " read $id nodes... "; |
| | 50 | |
| | 51 | # Grab all the content, and upgrade to ID from name |
| | 52 | $sth = $dbh->prepare("SELECT name,version,text,modified,comment FROM content"); |
| | 53 | $sth->execute; |
| | 54 | while ( my($name,$version,$text,$modified,$comment) = $sth->fetchrow_array) { |
| | 55 | my $id = $ids{$name}; |
| | 56 | if($id) { |
| | 57 | my %content; |
| | 58 | $content{'node_id'} = $id; |
| | 59 | $content{'version'} = $version; |
| | 60 | $content{'text'} = $text; |
| | 61 | $content{'modified'} = $modified; |
| | 62 | $content{'comment'} = $comment; |
| | 63 | $content{'moderated'} = 1; |
| | 64 | $contents{$id."-".$version} = \%content; |
| | 65 | } else { |
| | 66 | warn("There was no node entry for content with name '$name', unable to migrate it!"); |
| | 67 | } |
| | 68 | } |
| | 69 | print " read ".(scalar keys %contents)." contents... "; |
| | 70 | |
| | 71 | # Grab all the metadata, and upgrade to ID from node |
| | 72 | $sth = $dbh->prepare("SELECT node,version,metadata_type,metadata_value FROM metadata"); |
| | 73 | $sth->execute; |
| | 74 | my $i = 0; |
| | 75 | while( my($node,$version,$metadata_type,$metadata_value) = $sth->fetchrow_array) { |
| | 76 | my $id = $ids{$node}; |
| | 77 | if($id) { |
| | 78 | my %metadata; |
| | 79 | $metadata{'node_id'} = $id; |
| | 80 | $metadata{'version'} = $version; |
| | 81 | $metadata{'metadata_type'} = $metadata_type; |
| | 82 | $metadata{'metadata_value'} = $metadata_value; |
| | 83 | $metadatas{$id."-".($i++)} = \%metadata; |
| | 84 | } else { |
| | 85 | warn("There was no node entry for metadata with name (node) '$node', unable to migrate it!"); |
| | 86 | } |
| | 87 | } |
| | 88 | |
| | 89 | # Grab all the internal links |
| | 90 | $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links"); |
| | 91 | $sth->execute; |
| | 92 | while( my($link_from,$link_to) = $sth->fetchrow_array) { |
| | 93 | my %il; |
| | 94 | $il{'link_from'} = $link_from; |
| | 95 | $il{'link_to'} = $link_to; |
| | 96 | push @internal_links, \%il; |
| | 97 | } |
| | 98 | |
| | 99 | print "done\n"; |
| | 100 | |
| | 101 | # Return it all |
| | 102 | return (\%nodes,\%contents,\%metadatas,\@internal_links,\%ids); |
| 107 | | my $dbh = shift; |
| 108 | | my %nodes; |
| 109 | | my %metadatas; |
| 110 | | my %contents; |
| 111 | | my @internal_links; |
| 112 | | |
| 113 | | print "Grabbing and upgrading old data... "; |
| 114 | | |
| 115 | | # Grab all the nodes |
| 116 | | my $sth = $dbh->prepare("SELECT id,name,version,text,modified FROM node"); |
| 117 | | $sth->execute; |
| 118 | | while( my($id,$name,$version,$text,$modified) = $sth->fetchrow_array) { |
| 119 | | my %node; |
| 120 | | $node{'name'} = $name; |
| 121 | | $node{'version'} = $version; |
| 122 | | $node{'text'} = $text; |
| 123 | | $node{'modified'} = $modified; |
| 124 | | $node{'id'} = $id; |
| 125 | | $node{'moderate'} = 0; |
| 126 | | $nodes{$name} = \%node; |
| 127 | | } |
| 128 | | |
| 129 | | # Grab all the content |
| 130 | | $sth = $dbh->prepare("SELECT node_id,version,text,modified,comment FROM content"); |
| 131 | | $sth->execute; |
| 132 | | while ( my($node_id,$version,$text,$modified,$comment) = $sth->fetchrow_array) { |
| 133 | | my %content; |
| 134 | | $content{'node_id'} = $node_id; |
| 135 | | $content{'version'} = $version; |
| 136 | | $content{'text'} = $text; |
| 137 | | $content{'modified'} = $modified; |
| 138 | | $content{'comment'} = $comment; |
| 139 | | $content{'moderated'} = 1; |
| 140 | | $contents{$node_id."-".$version} = \%content; |
| 141 | | } |
| 142 | | |
| 143 | | # Grab all the metadata |
| 144 | | $sth = $dbh->prepare("SELECT node_id,version,metadata_type,metadata_value FROM metadata"); |
| 145 | | $sth->execute; |
| 146 | | my $i = 0; |
| 147 | | while( my($node_id,$version,$metadata_type,$metadata_value) = $sth->fetchrow_array) { |
| 148 | | my %metadata; |
| 149 | | $metadata{'node_id'} = $node_id; |
| 150 | | $metadata{'version'} = $version; |
| 151 | | $metadata{'metadata_type'} = $metadata_type; |
| 152 | | $metadata{'metadata_value'} = $metadata_value; |
| 153 | | $metadatas{$node_id."-".($i++)} = \%metadata; |
| 154 | | } |
| 155 | | |
| 156 | | # Grab all the internal links |
| 157 | | $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links"); |
| 158 | | $sth->execute; |
| 159 | | while( my($link_from,$link_to) = $sth->fetchrow_array) { |
| 160 | | my %il; |
| 161 | | $il{'link_from'} = $link_from; |
| 162 | | $il{'link_to'} = $link_to; |
| 163 | | push @internal_links, \%il; |
| 164 | | } |
| 165 | | |
| 166 | | print "done\n"; |
| 167 | | |
| 168 | | # Return it all |
| 169 | | return (\%nodes,\%contents,\%metadatas,\@internal_links); |
| | 107 | my $dbh = shift; |
| | 108 | my %nodes; |
| | 109 | my %metadatas; |
| | 110 | my %contents; |
| | 111 | my @internal_links; |
| | 112 | |
| | 113 | print "Grabbing and upgrading old data... "; |
| | 114 | |
| | 115 | # Grab all the nodes |
| | 116 | my $sth = $dbh->prepare("SELECT id,name,version,text,modified FROM node"); |
| | 117 | $sth->execute; |
| | 118 | while( my($id,$name,$version,$text,$modified) = $sth->fetchrow_array) { |
| | 119 | my %node; |
| | 120 | $node{'name'} = $name; |
| | 121 | $node{'version'} = $version; |
| | 122 | $node{'text'} = $text; |
| | 123 | $node{'modified'} = $modified; |
| | 124 | $node{'id'} = $id; |
| | 125 | $node{'moderate'} = 0; |
| | 126 | $nodes{$name} = \%node; |
| | 127 | } |
| | 128 | |
| | 129 | # Grab all the content |
| | 130 | $sth = $dbh->prepare("SELECT node_id,version,text,modified,comment FROM content"); |
| | 131 | $sth->execute; |
| | 132 | while ( my($node_id,$version,$text,$modified,$comment) = $sth->fetchrow_array) { |
| | 133 | my %content; |
| | 134 | $content{'node_id'} = $node_id; |
| | 135 | $content{'version'} = $version; |
| | 136 | $content{'text'} = $text; |
| | 137 | $content{'modified'} = $modified; |
| | 138 | $content{'comment'} = $comment; |
| | 139 | $content{'moderated'} = 1; |
| | 140 | $contents{$node_id."-".$version} = \%content; |
| | 141 | } |
| | 142 | |
| | 143 | # Grab all the metadata |
| | 144 | $sth = $dbh->prepare("SELECT node_id,version,metadata_type,metadata_value FROM metadata"); |
| | 145 | $sth->execute; |
| | 146 | my $i = 0; |
| | 147 | while( my($node_id,$version,$metadata_type,$metadata_value) = $sth->fetchrow_array) { |
| | 148 | my %metadata; |
| | 149 | $metadata{'node_id'} = $node_id; |
| | 150 | $metadata{'version'} = $version; |
| | 151 | $metadata{'metadata_type'} = $metadata_type; |
| | 152 | $metadata{'metadata_value'} = $metadata_value; |
| | 153 | $metadatas{$node_id."-".($i++)} = \%metadata; |
| | 154 | } |
| | 155 | |
| | 156 | # Grab all the internal links |
| | 157 | $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links"); |
| | 158 | $sth->execute; |
| | 159 | while( my($link_from,$link_to) = $sth->fetchrow_array) { |
| | 160 | my %il; |
| | 161 | $il{'link_from'} = $link_from; |
| | 162 | $il{'link_to'} = $link_to; |
| | 163 | push @internal_links, \%il; |
| | 164 | } |
| | 165 | |
| | 166 | print "done\n"; |
| | 167 | |
| | 168 | # Return it all |
| | 169 | return (\%nodes,\%contents,\%metadatas,\@internal_links); |
| 207 | | my ($dbh, $nodesref, $contentsref, $metadataref, $internallinksref) = @_; |
| 208 | | |
| 209 | | print "Bulk inserting upgraded data... "; |
| 210 | | |
| 211 | | # Add nodes |
| 212 | | my $sth = $dbh->prepare("INSERT INTO node (id,name,version,text,modified,moderate) VALUES (?,?,?,?,?,?)"); |
| 213 | | foreach my $name (keys %$nodesref) { |
| 214 | | my %node = %{$nodesref->{$name}}; |
| 215 | | $sth->execute($node{'id'}, |
| | 207 | my ($dbh, $nodesref, $contentsref, $metadataref, $internallinksref) = @_; |
| | 208 | |
| | 209 | print "Bulk inserting upgraded data... "; |
| | 210 | |
| | 211 | # Add nodes |
| | 212 | my $sth = $dbh->prepare("INSERT INTO node (id,name,version,text,modified,moderate) VALUES (?,?,?,?,?,?)"); |
| | 213 | foreach my $name (keys %$nodesref) { |
| | 214 | my %node = %{$nodesref->{$name}}; |
| | 215 | $sth->execute($node{'id'}, |
| 221 | | } |
| 222 | | print "added ".(scalar keys %$nodesref)." nodes... "; |
| 223 | | |
| 224 | | # Add content |
| 225 | | $sth = $dbh->prepare("INSERT INTO content (node_id,version,text,modified,comment,moderated) VALUES (?,?,?,?,?,?)"); |
| 226 | | foreach my $key (keys %$contentsref) { |
| 227 | | my %content = %{$contentsref->{$key}}; |
| 228 | | $sth->execute($content{'node_id'}, |
| | 221 | } |
| | 222 | print "added ".(scalar keys %$nodesref)." nodes... "; |
| | 223 | |
| | 224 | # Add content |
| | 225 | $sth = $dbh->prepare("INSERT INTO content (node_id,version,text,modified,comment,moderated) VALUES (?,?,?,?,?,?)"); |
| | 226 | foreach my $key (keys %$contentsref) { |
| | 227 | my %content = %{$contentsref->{$key}}; |
| | 228 | $sth->execute($content{'node_id'}, |