Skip to content

Commit c7c915b

Browse files
committed
Fix install bug if tables already exist
Fixes #46
1 parent 9273952 commit c7c915b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Fixed an error that could occur when calling `craft\webhooks\Plugin::getRequestData()` if an invalid request ID was passed.
2020
- Fixed an exception that could occur when retrying webhook requests, if the queue driver didn’t support delayed jobs.
2121
- Fixed an exception that could occur when sending webhook requests, if Guzzle wasn’t able to connect to the server.
22+
- Fixed an error during install, if the database tables already existed. ([#46](https://github.com/craftcms/webhooks/issues/46))
2223

2324
## 2.3.3 - 2021-04-01
2425

src/migrations/Install.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class Install extends Migration
1717
*/
1818
public function safeUp(): bool
1919
{
20+
// Cleanup
21+
$this->_dropTables();
22+
2023
// Create the webhookgroups table
2124
$this->createTable('{{%webhookgroups}}', [
2225
'id' => $this->primaryKey(),
@@ -84,11 +87,14 @@ public function safeUp(): bool
8487
*/
8588
public function safeDown(): bool
8689
{
87-
// Drop the DB table
90+
$this->_dropTables();
91+
return true;
92+
}
93+
94+
private function _dropTables(): void
95+
{
8896
$this->dropTableIfExists('{{%webhookrequests}}');
8997
$this->dropTableIfExists('{{%webhooks}}');
9098
$this->dropTableIfExists('{{%webhookgroups}}');
91-
92-
return true;
9399
}
94100
}

0 commit comments

Comments
 (0)