Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Disable plugin after first run

first-time

Solved by pamtbaau View solution

Started by ariel 7 years ago · 2 replies · 819 views
7 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

7 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 TomW, 2 weeks ago
8 231 12 hours ago
Support · by alex, 2 months ago
8 667 1 day ago
Support · by Supple, 6 days ago
1 98 2 days ago
Support · by TomW, 1 week ago
3 160 3 days ago
Support · by TomW, 6 days ago
2 108 6 days ago