Skip to content

Commit

Permalink
Merge pull request #402 from mainwp/mainwp-child-merging
Browse files Browse the repository at this point in the history
Update for version 5.0.1
  • Loading branch information
thanghv authored Apr 9, 2024
2 parents d32d062 + a3b6589 commit 2fe9017
Show file tree
Hide file tree
Showing 24 changed files with 267 additions and 1,269 deletions.
32 changes: 16 additions & 16 deletions class/class-mainwp-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ public function create_full_backup(
} elseif ( $this->check_zip_support() ) {
$success = $this->create_zip_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
} elseif ( $this->check_zip_console() ) {
$success = $this->create_zip_console_full_backup();
$success = $this->create_zip_console_full_backup(); // NOSONAR .
} else {
$success = $this->create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
}

return ( $success ) ? array(
'timestamp' => $timestamp,
'file' => $fileurl,
'filesize' => filesize( $filepath ),
'filesize' => filesize( $filepath ), // NOSONAR .
) : false;
}

Expand All @@ -265,7 +265,7 @@ public function backup_poll() {

$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
$backupdir = $dirs[0];
$result = glob( $backupdir . $backupFile . '*' );
$result = glob( $backupdir . $backupFile . '*' ); // NOSONAR .

// Check if archive, set $archiveFile = $file & break.
$archiveFile = false;
Expand All @@ -288,7 +288,7 @@ public function backup_poll() {
$backupFile = 'dbBackup-' . $fileNameUID . '-*.sql.php';
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
$backupdir = $dirs[0];
$result = glob( $backupdir . $backupFile . '*' );
$result = glob( $backupdir . $backupFile . '*' ); // NOSONAR .

if ( 0 === count( $result ) ) {
MainWP_Helper::write( array() );
Expand Down Expand Up @@ -598,12 +598,12 @@ public function backup_db( $fileName = '', $ext = 'zip' ) {

$result = $this->create_backup_db( $filepath_prefix, $ext );

MainWP_Helper::update_option( 'mainwp_child_last_db_backup_size', filesize( $result['filepath'] ) );
MainWP_Helper::update_option( 'mainwp_child_last_db_backup_size', filesize( $result['filepath'] ) ); // NOSONAR .

return ( ! $result ) ? false : array(
'timestamp' => $timestamp,
'file' => basename( $result['filepath'] ),
'filesize' => filesize( $result['filepath'] ),
'filesize' => filesize( $result['filepath'] ), // NOSONAR .
);
}

Expand Down Expand Up @@ -784,7 +784,7 @@ public function create_zip_full_backup(

$return = $this->zip->close();
foreach ( $db_files as $db_file ) {
wp_delete_file( $db_file );
wp_delete_file( $db_file ); // NOSONAR .
}

return true;
Expand Down Expand Up @@ -937,7 +937,7 @@ public function copy_dir( $nodes, $excludes, $backupfolder, $excludenonwp ) {
continue;
}

copy( $node, str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
copy( $node, str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated - // NOSONAR .
}
}
}
Expand Down Expand Up @@ -1019,8 +1019,8 @@ public function create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $
$this->copy_dir( $nodes, $excludes, $backupFolder, $excludenonwp, true );

foreach ( $db_files as $db_file ) {
copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
wp_delete_file( $db_file ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated // NOSONAR .
wp_delete_file( $db_file ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated // NOSONAR.
}

unset( $nodes );
Expand Down Expand Up @@ -1128,7 +1128,7 @@ public function add_file_from_string_to_pcl_zip( $file, $str, $filepath ) {
PCLZIP_OPT_ADD_PATH,
$localpath
);
wp_delete_file( $tmpfilename );
wp_delete_file( $tmpfilename ); // NOSONAR .
if ( ! empty( $add ) ) {
return true;
}
Expand Down Expand Up @@ -1160,13 +1160,13 @@ public function add_file_to_zipp( $path, $zipEntryName ) {
$this->zipArchiveSizeCount += filesize( $path );
++$this->gcCnt;

if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) {
if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) { // NOSONAR .
++$this->zipArchiveFileCount;
$added = $this->zip->add_file( $path, $zipEntryName );
} else {
++$this->zipArchiveFileCount;

$this->testContent = file_get_contents( $path ); //phpcs:ignore WordPress.WP.AlternativeFunctions
$this->testContent = file_get_contents( $path ); //phpcs:ignore WordPress.WP.AlternativeFunctions -- // NOSONAR .
if ( false === $this->testContent ) {
return false;
}
Expand Down Expand Up @@ -1261,7 +1261,7 @@ public function create_backup_db( $filepath_prefix, $archiveExt = false, &$archi
if ( file_exists( $currentfile ) ) {
continue;
}
$fh = fopen( $currentfile . '.tmp', 'w' );
$fh = fopen( $currentfile . '.tmp', 'w' ); // NOSONAR .

$protect_content_string = '<?php exit(); ?>';

Expand Down Expand Up @@ -1302,10 +1302,10 @@ public function create_backup_db( $filepath_prefix, $archiveExt = false, &$archi
$rows = null;
fflush( $fh );
fclose( $fh );
rename( $currentfile . '.tmp', $currentfile );
rename( $currentfile . '.tmp', $currentfile ); // NOSONAR .
}

fclose( fopen( $filepath_prefix . '.sql', 'w' ) );
fclose( fopen( $filepath_prefix . '.sql', 'w' ) ); // NOSONAR .
$db_files[] = $filepath_prefix . '.sql';

$archivefilePath = null;
Expand Down
10 changes: 5 additions & 5 deletions class/class-mainwp-child-back-up-buddy.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ public function delete_backup( $type = 'default', $subsite_mode = false ) {
$deleted_files = array();
foreach ( $item_ids as $item ) {
if ( file_exists( \backupbuddy_core::getBackupDirectory() . $item ) ) {
if ( wp_delete_file( \backupbuddy_core::getBackupDirectory() . $item ) === true ) {
if ( wp_delete_file( \backupbuddy_core::getBackupDirectory() . $item ) === true ) { // NOSONAR .
$deleted_files[] = $item;

// Cleanup any related fileoptions files.
Expand Down Expand Up @@ -1205,7 +1205,7 @@ public function zip_viewer() {
$fileoptions_file = \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '-filetree.txt';

// Purge cache if too old.
if ( file_exists( $fileoptions_file ) && ( ( time() - filemtime( $fileoptions_file ) ) > $max_cache_time ) ) {
if ( file_exists( $fileoptions_file ) && ( ( time() - filemtime( $fileoptions_file ) ) > $max_cache_time ) ) { // NOSONAR .
if ( false === wp_delete_file( $fileoptions_file ) ) {
$alerts[] = 'Error #456765545. Unable to wipe cached fileoptions file `' . $fileoptions_file . '`.';
}
Expand Down Expand Up @@ -1910,7 +1910,7 @@ public function view_log() {
return array( 'error' => 'Error #858733: Log file `' . $logFile . '` not found or access denied.' );
}

$lines = file_get_contents( $logFile ); //phpcs:ignore WordPress.WP.AlternativeFunctions
$lines = file_get_contents( $logFile ); //phpcs:ignore WordPress.WP.AlternativeFunctions -- // NOSONAR .
$lines = explode( "\n", $lines );
ob_start();
?>
Expand Down Expand Up @@ -1938,7 +1938,7 @@ public function view_log() {
<small>Log file: <?php echo $logFile; ?></small>
<br>
<?php
echo '<small>Last modified: ' . \pb_backupbuddy::$format->date( filemtime( $logFile ) ) . ' (' . \pb_backupbuddy::$format->time_ago( filemtime( $logFile ) ) . ' ago)';
echo '<small>Last modified: ' . \pb_backupbuddy::$format->date( filemtime( $logFile ) ) . ' (' . \pb_backupbuddy::$format->time_ago( filemtime( $logFile ) ) . ' ago)'; // NOSONAR .
?>
<br><br>
<?php
Expand Down Expand Up @@ -2547,7 +2547,7 @@ public function remote_send() {
}

if ( '' !== $backup_file ) {
$backup_file_size = filesize( $backup_file );
$backup_file_size = filesize( $backup_file ); // NOSONAR .
} else {
$backup_file_size = 50000;
}
Expand Down
3 changes: 2 additions & 1 deletion class/class-mainwp-child-branding-render.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public function contact_support() {
$from_page = isset( $_GET['from_page'] ) ? rawurldecode( wp_unslash( $_GET['from_page'] ) ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
} else {
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ), 'off' ) ? 'https://' : 'http://';
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? $protocol . esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$fullurl = $protocol . str_replace( array( 'https://', 'http://' ), '', $fullurl );
$from_page = rawurldecode( $fullurl );
}

Expand Down
3 changes: 2 additions & 1 deletion class/class-mainwp-child-branding.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,8 @@ public function add_support_button_in_top_admin_bar( $wp_admin_bar ) {
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' . ( ! empty( $_GET['from_page'] ) ? rawurlencode( esc_url_raw( wp_unslash( $_GET['from_page'] ) ) ) : '' ) );
} else {
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ), 'off' ) ? 'https://' : 'http://';
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? $protocol . esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$fullurl = $protocol . str_replace( array( 'https://', 'http://' ), '', $fullurl );
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' . rawurlencode( $fullurl ) );
}
// phpcs:enable
Expand Down
Loading

0 comments on commit 2fe9017

Please sign in to comment.