PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Framework / Migrations / Actions / ManuallyRunMigration.php

ManuallyRunMigration.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Framework/Migrations/Actions/ManuallyRunMigration.php

73 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\Migrations\Actions;
4
5 use Exception;
6 use Give\Framework\Migrations\Contracts\Migration;
7 use Give\Framework\Migrations\MigrationsRunner;
8
9 class ManuallyRunMigration
10 {
11 /**
12 * Manually runs the migration and then marks the migration as finished if successful
13 *
14 * @since 2.9.2
15 *
16 * @param Migration $migration
17 *
18 */
19 public function __invoke(Migration $migration)
20 {
21 global $wpdb;
22
23 $wpdb->query('START TRANSACTION');
24
25 try {
26 $migration->run();
27 } catch (Exception $exception) {
28 $wpdb->query('ROLLBACK');
29
30 give_record_log('Migration Failed', print_r($exception, true), 0, 'update');
31 give()->notices->register_notice(
32 [
33 'id' => 'migration-failure',
34 'description' => sprintf(
35 '%1$s <a href="https://givewp.com/support/">https://givewp.com/support</a>',
36 esc_html__(
37 'There was a problem running the migrations. Please reach out to GiveWP support for assistance:',
38 'give'
39 )
40 ),
41 ]
42 );
43
44 throw $exception;
45 }
46
47 // Commit transaction if successful
48 $wpdb->query('COMMIT');
49
50 $this->updateMigrationsSetting($migration::id());
51 }
52
53 /**
54 * Updates the completed migrations to include the migration if not yet included
55 *
56 * @since 2.9.2
57 *
58 * @param string $migrationId
59 */
60 private function updateMigrationsSetting($migrationId)
61 {
62 $completedMigrations = get_option(MigrationsRunner::MIGRATION_OPTION);
63
64 if (in_array($migrationId, $completedMigrations, true)) {
65 return;
66 }
67
68 $completedMigrations[] = $migrationId;
69
70 update_option(MigrationsRunner::MIGRATION_OPTION, $completedMigrations);
71 }
72 }
73