]> sipb.mit.edu Git - ikiwiki.git/commitdiff
po: delete translations of deleted master pages
authorintrigeri <intrigeri@boum.org>
Tue, 30 Dec 2008 23:38:47 +0000 (00:38 +0100)
committerintrigeri <intrigeri@boum.org>
Wed, 31 Dec 2008 10:47:18 +0000 (11:47 +0100)
Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/po.pm
doc/plugins/po.mdwn

index e25532a0abd322e9cc264e508cb024750b72f2cd..515809f70dfd99ad334cb32d32db7cc8d22c6fd5 100644 (file)
@@ -389,26 +389,9 @@ sub change(@) { #{{{
        }
 
        if ($updated_po_files) {
-               # Check staged changes in.
-               if ($config{rcs}) {
-                       IkiWiki::disable_commit_hook();
-                       IkiWiki::rcs_commit_staged(gettext("updated PO files"),
-                               "IkiWiki::Plugin::po::change", "127.0.0.1");
-                       IkiWiki::enable_commit_hook();
-                       IkiWiki::rcs_update();
-               }
-               # Reinitialize module's private variables.
-               resetalreadyfiltered();
-               resettranslationscache();
-               flushmemoizecache();
-               # Trigger a wiki refresh.
-               require IkiWiki::Render;
-               # without preliminary saveindex/loadindex, refresh()
-               # complains about a lot of uninitialized variables
-               IkiWiki::saveindex();
-               IkiWiki::loadindex();
-               IkiWiki::refresh();
-               IkiWiki::saveindex();
+               commit_and_refresh(
+                       gettext("updated PO files"),
+                       "IkiWiki::Plugin::po::change");
        }
 } #}}}
 
@@ -792,7 +775,53 @@ sub homepageurl (;$) { #{{{
 sub deletetranslations ($) { #{{{
        my $deletedmasterfile=shift;
 
-       debug "po(deletetranslations): TODO: delete translations of $deletedmasterfile";
+       my $deletedmasterpage=pagename($deletedmasterfile);
+       my @todelete;
+       map {
+               my $file = newpagefile($deletedmasterpage.'.'.$_, 'po');
+               my $absfile = "$config{srcdir}/$file";
+               if (-e $absfile && ! -l $absfile && ! -d $absfile) {
+                       push @todelete, $file;
+               }
+       } keys %{$config{po_slave_languages}};
+
+       map {
+               if ($config{rcs}) {
+                       IkiWiki::rcs_remove($_);
+               }
+               else {
+                       IkiWiki::prune("$config{srcdir}/$_");
+               }
+       } @todelete;
+
+       if (scalar @todelete) {
+               commit_and_refresh(
+                       gettext("removed obsolete PO files"),
+                       "IkiWiki::Plugin::po::deletetranslations");
+       }
+} #}}}
+
+sub commit_and_refresh ($$) { #{{{
+       my ($msg, $author) = (shift, shift);
+
+       if ($config{rcs}) {
+               IkiWiki::disable_commit_hook();
+               IkiWiki::rcs_commit_staged($msg, $author, "127.0.0.1");
+               IkiWiki::enable_commit_hook();
+               IkiWiki::rcs_update();
+       }
+       # Reinitialize module's private variables.
+       resetalreadyfiltered();
+       resettranslationscache();
+       flushmemoizecache();
+       # Trigger a wiki refresh.
+       require IkiWiki::Render;
+       # without preliminary saveindex/loadindex, refresh()
+       # complains about a lot of uninitialized variables
+       IkiWiki::saveindex();
+       IkiWiki::loadindex();
+       IkiWiki::refresh();
+       IkiWiki::saveindex();
 } #}}}
 
 # ,----
index ea1e89278f968a2e2f5160e77bc0c6b2e4b40d01..722a7c66c08dc851c5bfae42acb164a81a483e22 100644 (file)
@@ -562,11 +562,9 @@ Creating new pages on the web
 
 See [[contrib/po|contrib/po]].
 
-Deleting/renaming pages
------------------------
+Renaming pages
+--------------
 
-- When a master page is renamed or deleted, its translations (and the
-  pot file?) must be renamed or deleted accordingly.
 - Renaming a translation should be forbidden.
 
 Robustness tests
@@ -596,16 +594,17 @@ Robustness tests
 
 ### Deleting pages
 
-- removing a master page via RCS
+- removing a master page via RCS: **OK**
 - removing a translation via RCS: **OK**
-- removing a master page via CGI
+- removing a master page via CGI: **OK**
 - removing a translation via CGI: **OK**
 
 ### Renaming pages
 
-- renaming a master page via RCS 
-- renaming a master page and its translations via RCS
-- renaming a master page via CGI
+- renaming a master page via RCS: **OK** (but the old translations
+  are lost, because not all RCS track file renaming)
+- renaming a master page and its translations via RCS: **OK**
+- renaming a master page via CGI: **OK**
 - renaming a translation via RCS
 - renaming a translation via CGI