Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A basic check for known-conflicting files #53

Merged
merged 4 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion lib/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,39 @@ 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'] ) {
_e(
'No conflicting files were found.',
'switch-to-classicpress'
);
} else {
_e(
'Conflicting files detected. These are files that would be <strong class="cp-emphasis">unexpectedly overwritten</strong> during migration.',
'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>.',
'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";

// Check: Core files checksums
$modified_files = classicpress_check_core_files();
if ( $modified_files === false || ! empty( $modified_files ) ) {
Expand Down Expand Up @@ -524,7 +557,8 @@ function classicpress_check_can_migrate() {
if (
$preflight_checks['wp_version'] &&
$preflight_checks['php_version'] &&
$preflight_checks['wp_http_supports_ssl']
$preflight_checks['wp_http_supports_ssl'] &&
$preflight_checks['conflicting_files']
) {
update_option( 'classicpress_preflight_checks', $preflight_checks, false );
return true;
Expand Down
21 changes: 21 additions & 0 deletions lib/check-core-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,24 @@ function classicpress_check_core_files( $locale = 'en_US' ) {
}
return $modified;
}

/**
* Check for known conflicting files.
*
* @since 0.6.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;
}