From 627a66453e2187cccaa581c192fa7609a8315e18 Mon Sep 17 00:00:00 2001
From: James Nylen
Date: Thu, 24 Oct 2019 15:17:16 -0500
Subject: [PATCH] Handle existing composer.json better
Change the "conflicting files check" from an error to a warning, and
include a bit more information about what is actually going on.
Closes #61.
---
lib/admin-page.php | 35 ++++++++++++-----------------------
lib/check-core-files.php | 21 ---------------------
lib/update.php | 3 +--
3 files changed, 13 insertions(+), 46 deletions(-)
diff --git a/lib/admin-page.php b/lib/admin-page.php
index d226d81..75deae1 100644
--- a/lib/admin-page.php
+++ b/lib/admin-page.php
@@ -503,38 +503,28 @@ function classicpress_check_can_migrate() {
echo "\n
\n";
echo "\n";
- // Check: Conflicting files
- $conflicting_files = classicpress_check_conflicting_files();
- if ( count( $conflicting_files ) > 0 ) {
- $preflight_checks['conflicting_files'] = false;
- echo "\n$icon_preflight_fail | \n\n";
- } else {
- $preflight_checks['conflicting_files'] = true;
- echo " |
\n$icon_preflight_pass | \n\n";
- }
- echo " \n";
- if ( $preflight_checks['conflicting_files'] ) {
+ // Check: Existing `composer.json` file
+ $composer_json_exists = file_exists( ABSPATH . 'composer.json' );
+ if ( $composer_json_exists ) {
+ echo " |
\n$icon_preflight_warn | \n\n";
+ echo " \n";
_e(
- 'No conflicting files were found.',
+ 'An existing composer.json file was detected on your site. This file will be overwritten during migration.',
'switch-to-classicpress'
);
- } else {
+ echo " \n";
_e(
- 'Conflicting files detected. These are files that would be unexpectedly overwritten during migration.',
+ 'If you have previously installed ClassicPress on this site, then you can ignore this warning.',
'switch-to-classicpress'
);
echo " \n";
_e(
- 'If you have JavaScript enabled, you can see a list of conflicting files in your browser console.',
+ 'If you are using composer.json to manage dependencies for this site, then you should back up this file before continuing, and restore it after the migration.',
'switch-to-classicpress'
);
- echo "\n";
+ echo "\n \n";
+ echo " |
\n";
}
- echo "\n\n";
- echo "\n";
// Check: Core files checksums
$modified_files = classicpress_check_core_files();
@@ -611,8 +601,7 @@ function classicpress_check_can_migrate() {
if (
$preflight_checks['wp_version'] &&
$preflight_checks['php_version'] &&
- $preflight_checks['wp_http_supports_ssl'] &&
- $preflight_checks['conflicting_files']
+ $preflight_checks['wp_http_supports_ssl']
) {
update_option( 'classicpress_preflight_checks', $preflight_checks, false );
return true;
diff --git a/lib/check-core-files.php b/lib/check-core-files.php
index 44d79e2..5f83559 100644
--- a/lib/check-core-files.php
+++ b/lib/check-core-files.php
@@ -42,24 +42,3 @@ function classicpress_check_core_files( $locale = 'en_US' ) {
}
return $modified;
}
-
-/**
- * Check for known conflicting files.
- *
- * @since 1.0.0
- *
- * @return array An array of conflicting filenames (empty if no conflits).
- */
-function classicpress_check_conflicting_files() {
- $files = array(
- 'composer.json',
- );
-
- $conflict = array();
- foreach ( $files as $file ) {
- if ( file_exists( ABSPATH . $file ) ) {
- $conflict[] = $file;
- }
- }
- return $conflict;
-}
diff --git a/lib/update.php b/lib/update.php
index 320f427..cc88ceb 100644
--- a/lib/update.php
+++ b/lib/update.php
@@ -241,8 +241,7 @@ function classicpress_override_upgrade_page() {
! is_array( $preflight_checks ) ||
empty( $preflight_checks['wp_version'] ) ||
empty( $preflight_checks['php_version'] ) ||
- empty( $preflight_checks['wp_http_supports_ssl'] ) ||
- empty( $preflight_checks['conflicting_files'] )
+ empty( $preflight_checks['wp_http_supports_ssl'] )
) {
return;
}