aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2010-07-26 16:24:17 -0400
committerJoey Hess <joey@kitenet.net>2010-07-26 16:33:42 -0400
commitc401b6958af7e12c1c2c46f870691bfb0a998fd3 (patch)
treeea0d991a16d08022209bb71d9202f1e4127c849b /IkiWiki
parentb300bc9650a40885cd8c6e0a646436539aed95c1 (diff)
downloadikiwiki-c401b6958af7e12c1c2c46f870691bfb0a998fd3.tar
ikiwiki-c401b6958af7e12c1c2c46f870691bfb0a998fd3.tar.gz
Add new disable hook, allowing plugins to perform cleanup after they have been disabled.
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/skeleton.pm.example5
-rw-r--r--IkiWiki/Setup.pm24
2 files changed, 29 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example
index c3a3b0c01..a57a2c8fe 100644
--- a/IkiWiki/Plugin/skeleton.pm.example
+++ b/IkiWiki/Plugin/skeleton.pm.example
@@ -41,6 +41,7 @@ sub import {
hook(type => "rename", id => "skeleton", call => \&rename);
hook(type => "savestate", id => "skeleton", call => \&savestate);
hook(type => "genwrapper", id => "skeleton", call => \&genwrapper);
+ hook(type => "disable", id => "skeleton", call => \&disable);
}
sub getopt () {
@@ -254,4 +255,8 @@ sub genwrapper () {
debug("skeleton plugin running in genwrapper");
}
+sub savestate () {
+ debug("skeleton plugin running in disable");
+}
+
1
diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm
index 7af744f6a..f34571bcf 100644
--- a/IkiWiki/Setup.pm
+++ b/IkiWiki/Setup.pm
@@ -124,6 +124,28 @@ sub merge ($) {
}
}
+sub disabled_plugins (@) {
+ # Handles running disable hooks of plugins that were enabled
+ # previously, but got disabled when a new setup file was loaded.
+ if (exists $config{setupfile} && @_) {
+ # Fork a child to load the disabled plugins.
+ my $pid=fork();
+ if ($pid == 0) {
+ foreach my $plugin (@_) {
+ print STDERR "** plugin $plugin disabled\n";
+ eval { IkiWiki::loadplugin($plugin, 1) };
+ if (exists $IkiWiki::hooks{disable}{$plugin}{call}) {
+ eval { $IkiWiki::hooks{disable}{$plugin}{call}->() };
+ }
+ }
+ exit(0);
+ }
+ else {
+ waitpid $pid, 0;
+ }
+ }
+}
+
sub getsetup () {
# Gets all available setup data from all plugins. Returns an
# ordered list of [plugin, setup] pairs.
@@ -134,6 +156,7 @@ sub getsetup () {
$config{syslog}=undef;
# Load all plugins, so that all setup options are available.
+ my %original_loaded_plugins=%IkiWiki::loaded_plugins;
my @plugins=IkiWiki::listplugins();
foreach my $plugin (@plugins) {
eval { IkiWiki::loadplugin($plugin, 1) };
@@ -141,6 +164,7 @@ sub getsetup () {
my @s=eval { $IkiWiki::hooks{checkconfig}{$plugin}{call}->() };
}
}
+ %IkiWiki::loaded_plugins=%original_loaded_plugins;
my %sections;
foreach my $plugin (@plugins) {