Skip to content

Commit

Permalink
Handle existing composer.json better
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nylen committed Oct 24, 2019
1 parent 6ce1192 commit 627a664
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 46 deletions.
35 changes: 12 additions & 23 deletions lib/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,38 +503,28 @@ function classicpress_check_can_migrate() {
echo "\n</p>\n";
echo "</td></tr>\n";

// Check: Conflicting files
$conflicting_files = classicpress_check_conflicting_files();
if ( count( $conflicting_files ) > 0 ) {
$preflight_checks['conflicting_files'] = false;
echo "<tr>\n<td>$icon_preflight_fail</td>\n<td>\n";
} else {
$preflight_checks['conflicting_files'] = true;
echo "<tr>\n<td>$icon_preflight_pass</td>\n<td>\n";
}
echo "<p>\n";
if ( $preflight_checks['conflicting_files'] ) {
// Check: Existing `composer.json` file
$composer_json_exists = file_exists( ABSPATH . 'composer.json' );
if ( $composer_json_exists ) {
echo "<tr>\n<td>$icon_preflight_warn</td>\n<td>\n";
echo "<p>\n";
_e(
'No conflicting files were found.',
'An existing <code>composer.json</code> file was detected on your site. This file will be <strong class="cp-emphasis">overwritten</strong> during migration.',
'switch-to-classicpress'
);
} else {
echo "<br>\n";
_e(
'Conflicting files detected. These are files that would be <strong class="cp-emphasis">unexpectedly overwritten</strong> during migration.',
'If you have previously installed ClassicPress on this site, then you can ignore this warning.',
'switch-to-classicpress'
);
echo "<br>\n";
_e(
'If you have JavaScript enabled, you can see a list of conflicting files <strong>in your browser console</strong>.',
'If you are using <code>composer.json</code> to manage dependencies for this site, then you should <strong class="cp-emphasis">back up this file</strong> before continuing, and restore it after the migration.',
'switch-to-classicpress'
);
echo "\n<script>console.log(";
echo "\n'conflicting files, remove them and refresh in order to proceed:',\n";
echo wp_json_encode( $conflicting_files );
echo "\n);</script>";
echo "\n</p>\n";
echo "</td></tr>\n";
}
echo "\n</p>\n";
echo "</td></tr>\n";

// Check: Core files checksums
$modified_files = classicpress_check_core_files();
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 0 additions & 21 deletions lib/check-core-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 1 addition & 2 deletions lib/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 627a664

Please sign in to comment.