# give/4.16.9/src/Framework/Migrations/Actions/ManuallyRunMigration.php

GiveWP – Donation Plugin and Fundraising Platform, version 4.16.9. 73 lines.

- Page: https://pluginprobe.com/plugins/give/4.16.9/code/src/Framework/Migrations/Actions/ManuallyRunMigration.php
- Raw: https://pluginprobe.com/plugins/give/4.16.9/raw/src/Framework/Migrations/Actions/ManuallyRunMigration.php
- Modified: 2021-11-23T23:55:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.16.9/code/src/Framework/Migrations/Actions/ManuallyRunMigration.php#L10-L20`.

```php
<?php

namespace Give\Framework\Migrations\Actions;

use Exception;
use Give\Framework\Migrations\Contracts\Migration;
use Give\Framework\Migrations\MigrationsRunner;

class ManuallyRunMigration
{
    /**
     * Manually runs the migration and then marks the migration as finished if successful
     *
     * @since 2.9.2
     *
     * @param Migration $migration
     *
     */
    public function __invoke(Migration $migration)
    {
        global $wpdb;

        $wpdb->query('START TRANSACTION');

        try {
            $migration->run();
        } catch (Exception $exception) {
            $wpdb->query('ROLLBACK');

            give_record_log('Migration Failed', print_r($exception, true), 0, 'update');
            give()->notices->register_notice(
                [
                    'id' => 'migration-failure',
                    'description' => sprintf(
                        '%1$s <a href="https://givewp.com/support/">https://givewp.com/support</a>',
                        esc_html__(
                            'There was a problem running the migrations. Please reach out to GiveWP support for assistance:',
                            'give'
                        )
                    ),
                ]
            );

            throw $exception;
        }

        // Commit transaction if successful
        $wpdb->query('COMMIT');

        $this->updateMigrationsSetting($migration::id());
    }

    /**
     * Updates the completed migrations to include the migration if not yet included
     *
     * @since 2.9.2
     *
     * @param string $migrationId
     */
    private function updateMigrationsSetting($migrationId)
    {
        $completedMigrations = get_option(MigrationsRunner::MIGRATION_OPTION);

        if (in_array($migrationId, $completedMigrations, true)) {
            return;
        }

        $completedMigrations[] = $migrationId;

        update_option(MigrationsRunner::MIGRATION_OPTION, $completedMigrations);
    }
}

```
