| 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 |
|