Skip to content

Commit

Permalink
Fixed migrations with/without schema version
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Croker committed May 7, 2021
1 parent c1e2ff5 commit 9bfacfc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.0.5 - Unreleased
### Fixed
- Fixed a bug in which config changes could be made twice if the plugin was installed via project config ([#15](https://github.com/putyourlightson/craft-snaptcha/issues/15)).

## 3.0.4 - 2021-05-06
### Changed
- Excluded requests to the GraphQL API from being validated ([#17](https://github.com/putyourlightson/craft-snaptcha/issues/17)).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "putyourlightson/craft-snaptcha",
"description": "Automatically validates forms and prevents spam bots from submitting to your site.",
"version": "3.0.4",
"version": "3.0.5",
"type": "craft-plugin",
"homepage": "https://putyourlightson.com/plugins/snaptcha",
"license": "proprietary",
Expand Down
7 changes: 7 additions & 0 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public function safeUp(): bool
Craft::$app->db->schema->refresh();
}

// Don't make the same config changes twice
$schemaVersion = Craft::$app->projectConfig->get('plugins.snaptcha.schemaVersion', true);

if ($schemaVersion !== null) {
return true;
}

// Create and save default settings
$settings = Snaptcha::$plugin->settings;
$settings->salt = StringHelper::randomString(16);
Expand Down
6 changes: 3 additions & 3 deletions src/migrations/m210217_120000_add_value_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class m210217_120000_add_value_column extends Migration
*/
public function safeUp(): bool
{
$schemaVersion = Craft::$app->projectConfig
->get('plugins.snaptcha.schemaVersion', true);
$schemaVersion = Craft::$app->projectConfig->get('plugins.snaptcha.schemaVersion', true);

if (!version_compare($schemaVersion, '3.0.0', '<')) {
// Ensure schema version exists to help prevent https://github.com/putyourlightson/craft-snaptcha/issues/15
if ($schemaVersion && !version_compare($schemaVersion, '3.0.0', '<')) {
return true;
}

Expand Down

0 comments on commit 9bfacfc

Please sign in to comment.