Skip to content

Commit

Permalink
Fixed first save of settings on install
Browse files Browse the repository at this point in the history
  • Loading branch information
sjelfull committed Apr 4, 2018
1 parent b16033a commit fc5688d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 16 additions & 16 deletions src/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit fc5688d

Please sign in to comment.