| 1 |
<?php |
| 2 |
|
| 3 |
require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
| 4 |
require_once(FLUENTMAIL_PLUGIN_PATH.'database/migrations/EmailLogs.php'); |
| 5 |
|
| 6 |
class FluentMailDBMigrator |
| 7 |
{ |
| 8 |
public static function run($network_wide = false) |
| 9 |
{ |
| 10 |
global $wpdb; |
| 11 |
|
| 12 |
if ($network_wide ) { |
| 13 |
if (function_exists('get_sites') && function_exists('get_current_network_id')) { |
| 14 |
$site_ids = get_sites(['fields' => 'ids', 'network_id' => get_current_network_id(), 'number' => 0]); |
| 15 |
} else { |
| 16 |
$site_ids = $wpdb->get_col( |
| 17 |
$wpdb->prepare( |
| 18 |
"SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d", |
| 19 |
$wpdb->siteid |
| 20 |
) |
| 21 |
); |
| 22 |
} |
| 23 |
|
| 24 |
// Install the plugin for all these sites. |
| 25 |
foreach ($site_ids as $site_id) { |
| 26 |
switch_to_blog($site_id); |
| 27 |
self::migrate(); |
| 28 |
restore_current_blog(); |
| 29 |
} |
| 30 |
} else { |
| 31 |
self::migrate(); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
public static function migrate() |
| 36 |
{ |
| 37 |
\FluentMailMigrations\EmailLogs::migrate(); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
if (!isset($network_wide)) { |
| 42 |
$network_wide = false; |
| 43 |
} |
| 44 |
|
| 45 |
FluentMailDBMigrator::run($network_wide); |
| 46 |
|