Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

Disable plugin after first run

first-time

Solved by pamtbaau View solution

Started by ariel 6 years ago · 2 replies · 649 views
6 years ago

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

6 years ago Solution

@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.

PHP
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

Suggested topics

Topic Participants Replies Views Activity
Support · by Paul Hodges, 4 weeks ago
19 491 6 days ago
Support · by Lauw, 1 week ago
2 107 1 week ago
Support · by Anna, 3 weeks ago
4 431 1 week ago
Support · by gtx, 4 weeks ago
4 380 3 weeks ago
Support · by Anna, 1 month ago
9 487 4 weeks ago