From dcd267be235b5f1a7a89cc1e67c8ea01c6733807 Mon Sep 17 00:00:00 2001 From: Elvis Morales Date: Wed, 9 Nov 2022 22:43:33 -0800 Subject: [PATCH 1/2] Replaces insert_blog() with wp_insert_site() & replaces rename() with exec() --- .../commands/class-mu-migration-import.php | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/includes/commands/class-mu-migration-import.php b/includes/commands/class-mu-migration-import.php index 3f077fc..7d01973 100644 --- a/includes/commands/class-mu-migration-import.php +++ b/includes/commands/class-mu-migration-import.php @@ -571,7 +571,17 @@ private function move_and_activate_plugins( $plugins_dir, $plugins, $blog_plugin if ( ! file_exists( $installed_plugins . '/' . $plugin_folder ) ) { WP_CLI::log( sprintf( __( 'Moving %s to plugins folder' ), $plugin_name ) ); - rename( $fullPluginPath, $installed_plugins . '/' . $plugin_folder ); + + /** + * PHP has a core bug that prevents rename() from working reliably across filesystems. + * We'll disable and replace rename() by exec() calls. + * + * @link https://stackoverflow.com/a/35503748/2209086 + * @link https://bugs.php.net/bug.php?id=54097 + */ + // rename( $fullPluginPath, $installed_plugins . '/' . $plugin_folder ); + + exec("mv " . escapeshellarg($fullPluginPath) . " " . escapeshellarg($installed_plugins . '/' . $plugin_folder)); } if ( $check_plugins && in_array( $plugin_name, $blog_plugins, true ) ) { @@ -619,7 +629,18 @@ private function move_themes( $themes_dir ) { if ( ! file_exists( $installed_themes . '/' . $theme->getFilename() ) ) { WP_CLI::log( sprintf( __( 'Moving %s to themes folder' ), $theme->getFilename() ) ); - rename( $fullPluginPath, $installed_themes . '/' . $theme->getFilename() ); + + /** + * PHP has a core bug that prevents rename() from working reliably across filesystems. + * We'll disable and replace rename() by exec() calls. + * + * @link https://stackoverflow.com/a/35503748/2209086 + * @link https://bugs.php.net/bug.php?id=54097 + */ + // rename( $fullPluginPath, $installed_themes . '/' . $theme->getFilename() ); + + exec("mv " . escapeshellarg($fullPluginPath) . " " . escapeshellarg($installed_themes . '/' . $theme->getFilename())); + Helpers\runcommand( 'theme enable', [ $theme->getFilename() ] ); } @@ -644,7 +665,22 @@ private function create_new_site( $meta_data ) { return false; } - $blog_id = insert_blog( $parsed_url['host'], $parsed_url['path'], $site_id ); + $now = current_time( 'mysql', true ); + $new_site_meta = array( + 'domain' => $parsed_url['host'], + 'path' => $parsed_url['path'], + 'network_id' => get_current_network_id(), + 'registered' => $now, + 'last_updated' => $now, + 'public' => 1, + 'archived' => 0, + 'mature' => 0, + 'spam' => 0, + 'deleted' => 0, + 'lang_id' => 0, + ); + + $blog_id = wp_insert_site( $new_site_meta ); if ( ! $blog_id ) { return false; From 4c538fa636af340fea271217026b5d5835f97091 Mon Sep 17 00:00:00 2001 From: Elvis Morales Date: Wed, 9 Nov 2022 22:49:07 -0800 Subject: [PATCH 2/2] Uses already existing $site_id value --- includes/commands/class-mu-migration-import.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/commands/class-mu-migration-import.php b/includes/commands/class-mu-migration-import.php index 7d01973..c416aa8 100644 --- a/includes/commands/class-mu-migration-import.php +++ b/includes/commands/class-mu-migration-import.php @@ -669,7 +669,7 @@ private function create_new_site( $meta_data ) { $new_site_meta = array( 'domain' => $parsed_url['host'], 'path' => $parsed_url['path'], - 'network_id' => get_current_network_id(), + 'network_id' => $site_id, 'registered' => $now, 'last_updated' => $now, 'public' => 1,