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 · 506 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 Water Science, 3 weeks ago
11 165 4 hours ago
Support · by Duc , 19 hours ago
1 43 19 hours ago
Support · by Thomas, 1 week ago
3 116 1 day ago
Support · by Anna, 4 days ago
2 109 2 days ago
Support · by Justin Young, 2 days ago
1 86 2 days ago