Disable plugin after first run

Hi,
so, I think the title says it all…

I wrote a simple plugin that uses the AWS SDK, fetches some resources from s3.
these actions are done in onPluginsInitialized event.
as I don’t need the plugin to run more than once, how and where should I disable it?

I am open to suggestions in case what I’m doing is a total abomination in the grav world.

thx
Ariel

@ariel, I presume you mean the plugin doesn’t need to run anymore for any request unless switched on again?

When the variable “enabled” in the config file for the plugin is set to ‘false’, Grav will no longer call the plugin. So, you could override the settings of the plugin after it has finished its job.

use Grav\Common\Yaml;
...
$config = $this->config->get('plugins.myplugin');
$config['enabled'] = false;

$configFile = $this->grav['locator']->base.'/user/config/plugins/myplugin.yaml';
// or use: $configFile = __DIR__.'/myplugin.yaml';
file_put_contents($configFile, YAML::dump($config));

Hope this helps…

1 Like

@ pamtbaau
Thank you very much, that is exactly what I needed!