diff --git a/CHANGELOG.md b/CHANGELOG.md index a34a724..867e0ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Fixed +- Fixed first save of settings on install + ## 1.0.0 - 2018-04-04 + ### Added - Initial release diff --git a/src/Audit.php b/src/Audit.php index c4af843..2254c18 100644 --- a/src/Audit.php +++ b/src/Audit.php @@ -95,6 +95,22 @@ public function init() $this->controllerNamespace = 'superbig\audit\console\controllers'; } + Event::on( + Plugins::class, + Plugins::EVENT_AFTER_INSTALL_PLUGIN, + function(PluginEvent $event) { + if ($event->plugin === $this) { + $settings = $this->getSettings(); + + if (empty($settings->updateAuthKey)) { + $settings->updateAuthKey = StringHelper::randomString(16); + + Craft::$app->getPlugins()->savePluginSettings($this, $settings->toArray()); + } + } + } + ); + /** * Install our event listeners. We do it only after we receive the event * EVENT_AFTER_LOAD_PLUGINS so that any pending db migrations can be run @@ -110,22 +126,6 @@ function() { $this->initLogEvents(); }); } - - Event::on( - Plugins::class, - Plugins::EVENT_AFTER_INSTALL_PLUGIN, - function(PluginEvent $event) { - if ($event->plugin === $this) { - $settings = $this->getSettings(); - - if (empty($settings->updateAuthKey)) { - $settings->updateAuthKey = StringHelper::randomString(16); - - Craft::$app->getPlugins()->savePluginSettings($this, $settings->toArray()); - } - } - } - ); } Event::on(