Tables
1 year ago
GeneralMigration.php
1 year ago
MigrationsServiceProvider.php
3 months ago
ProductPageMigrationService.php
1 year ago
RewriteRulesMigrationService.php
1 year ago
Table.php
3 years ago
ThemeMigrationService.php
3 months ago
UpdateMigrationServiceProvider.php
3 weeks ago
UserMetaMigrationsService.php
3 years ago
VersionMigration.php
1 year ago
WebhookMigrationsService.php
1 year ago
WebhookMigrationsService.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Database; |
| 4 | |
| 5 | use SureCart\Models\RegisteredWebhook; |
| 6 | |
| 7 | /** |
| 8 | * Run this migration when version changes or for new installations. |
| 9 | */ |
| 10 | class WebhookMigrationsService extends VersionMigration { |
| 11 | /** |
| 12 | * The key for the migration. |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | protected $migration_key = 'surecart_webhook_migration_version'; |
| 17 | |
| 18 | /** |
| 19 | * Run the migration. |
| 20 | * |
| 21 | * @return void |
| 22 | */ |
| 23 | public function run(): void { |
| 24 | error_log( 'webhook' ); |
| 25 | // Get the registered webhooks. |
| 26 | $webhook = RegisteredWebhook::get(); |
| 27 | |
| 28 | // Stop if webhook is not found or there is some sort of error. |
| 29 | if ( ! $webhook || is_wp_error( $webhook ) || empty( $webhook->id ) || empty( $webhook->url ) ) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | // Update the webhook. This will update the events on the server. |
| 34 | try { |
| 35 | RegisteredWebhook::update(); |
| 36 | } catch ( \Exception $exception ) { |
| 37 | wp_die( 'Webhook migration failed. Error: ' . esc_attr( $exception->getMessage() ) ); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 |