]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/aggregate.pm
Add aggregateinternal mode to ikiwiki-transition.
[ikiwiki.git] / IkiWiki / Plugin / aggregate.pm
index b3d4a5eec84d5a46f5b8b3c485cd0d73430c62a2..9da619375df515ec4e8d236d10ce7b7b5b2c2130 100644 (file)
@@ -113,6 +113,49 @@ sub launchaggregation () { #{{{
        return 1;
 } #}}}
 
+sub migrate_to_internal { #{{{
+
+       if (! lockaggregate()) {
+               error("an aggregation process is already running");
+               return;
+       }
+
+       IkiWiki::lockwiki();
+       loadstate();
+
+       foreach my $data (values %guids) {
+               next unless $data->{page};
+
+               $config{aggregateinternal} = 0;
+               my $oldname = pagefile($data->{page});
+
+               $config{aggregateinternal} = 1;
+               my $newname = pagefile($data->{page});
+
+               print "I: $oldname -> $newname\n";
+               if (-e $newname) {
+                       if (-e $oldname) {
+                               error("$newname already exists");
+                       }
+                       else {
+                               print STDERR 
+                                       "W: already renamed to $newname?\n";
+                       }
+               }
+               elsif (-e $oldname) {
+                       rename($oldname, $newname) || error("$!");
+               }
+               else {
+                       print "W: $oldname not found\n";
+               }
+       }
+
+       savestate();
+       IkiWiki::unlockwiki;
+
+       unlockaggregate();
+} #}}}
+
 sub needsbuild (@) { #{{{
        my $needsbuild=shift;