| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\Database; |
| 4 |
|
| 5 |
use FluentBoards\Database\Migrations\AttachmentMigrator; |
| 6 |
use FluentBoards\Database\Migrations\BoardMigrator; |
| 7 |
use FluentBoards\Database\Migrations\BoardTermMigrator; |
| 8 |
use FluentBoards\Database\Migrations\CommentsMigrator; |
| 9 |
use FluentBoards\Database\Migrations\TaskMigrator; |
| 10 |
use FluentBoards\Database\Migrations\TaskMetaMigrator; |
| 11 |
use FluentBoards\Database\Migrations\NotificationMigrator; |
| 12 |
use FluentBoards\Database\Migrations\NotificationUserMigrator; |
| 13 |
use FluentBoards\Database\Migrations\MetaMigrator; |
| 14 |
use FluentBoards\Database\Migrations\ActivityMigrator; |
| 15 |
use FluentBoards\Database\Migrations\RelationMigrator; |
| 16 |
use FluentBoards\Database\Migrations\TeamMigrator; |
| 17 |
|
| 18 |
class DBMigrator |
| 19 |
{ |
| 20 |
public static function run($network_wide = false) |
| 21 |
{ |
| 22 |
global $wpdb; |
| 23 |
|
| 24 |
if ( $network_wide ) { |
| 25 |
// Retrieve all site IDs from this network (WordPress >= 4.6 provides easy to use functions for that). |
| 26 |
if ( function_exists( 'get_sites' ) && function_exists( 'get_current_network_id' ) ) { |
| 27 |
$site_ids = get_sites( array( 'fields' => 'ids', 'network_id' => get_current_network_id() ) ); |
| 28 |
} else { |
| 29 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Retrieving site IDs for multisite migration |
| 30 |
$site_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs WHERE site_id = $wpdb->siteid;" ); |
| 31 |
} |
| 32 |
// Install the plugin for all these sites. |
| 33 |
foreach ( $site_ids as $site_id ) { |
| 34 |
switch_to_blog( $site_id ); |
| 35 |
self::migrate(false); |
| 36 |
restore_current_blog(); |
| 37 |
} |
| 38 |
} else { |
| 39 |
self::migrate(false); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
public static function migrate($isForced = false) |
| 44 |
{ |
| 45 |
BoardMigrator::migrate($isForced); |
| 46 |
BoardTermMigrator::migrate($isForced); |
| 47 |
TaskMigrator::migrate($isForced); |
| 48 |
TaskMetaMigrator::migrate($isForced); |
| 49 |
NotificationMigrator::migrate($isForced); |
| 50 |
NotificationUserMigrator::migrate($isForced); |
| 51 |
MetaMigrator::migrate($isForced); |
| 52 |
ActivityMigrator::migrate($isForced); |
| 53 |
RelationMigrator::migrate($isForced); |
| 54 |
CommentsMigrator::migrate($isForced); |
| 55 |
AttachmentMigrator::migrate($isForced); |
| 56 |
TeamMigrator::migrate($isForced); |
| 57 |
} |
| 58 |
|
| 59 |
public static function handle_new_site($new_site) |
| 60 |
{ |
| 61 |
if (!is_plugin_active_for_network('fluent-boards/fluent-boards.php')) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
switch_to_blog($new_site->blog_id); |
| 66 |
self::migrate(false); |
| 67 |
restore_current_blog(); |
| 68 |
} |
| 69 |
} |
| 70 |
|