Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Disable plugin after first run

first-time

Solved by pamtbaau View solution

Started by ariel 6 years ago · 2 replies · 691 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 blu3prince, 4 days ago
1 85 17 hours ago
Support · by complanar, 1 week ago
6 167 2 days ago
Support · by Rick Beebe, 1 week ago
2 124 4 days ago
Support · by alex, 6 days ago
2 108 5 days ago
Support · by Marcel, 2 weeks ago
1 158 5 days ago