Skip to content

Commit

Permalink
Pro release 4.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Honemo committed Jul 5, 2024
1 parent 6917660 commit 8288e6c
Show file tree
Hide file tree
Showing 189 changed files with 111,532 additions and 459 deletions.
19 changes: 13 additions & 6 deletions backwpup.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* Description: WordPress Backup Plugin
* Author: BackWPup – WordPress Backup & Restore Plugin
* Author URI: https://backwpup.com
* Version: 4.1.2
* Version: 4.1.3
* Requires at least: 3.9
* Requires PHP: 7.2
* Requires PHP: 7.4
* Text Domain: backwpup
* Domain Path: /languages/
* Network: true
Expand Down Expand Up @@ -156,10 +156,17 @@ private function __construct()
$admin = new BackWPup_Admin($settings);
$admin->init();

if (get_site_option('backwpup_cfg_showadminbar')) {
$adminBar = new BackWPup_Adminbar($admin);
add_action('init', [$adminBar, 'init']);
}
/**
* Filter whether BackWPup will show the plugins in the admin bar or not.
*
* @param bool $is_in_admin_bar Whether the admin link will be shown in the admin bar or not.
*/
$is_in_admin_bar = (bool) apply_filters( 'backwpup_is_in_admin_bar', (bool) get_site_option( 'backwpup_cfg_showadminbar' ) );

if ( true === $is_in_admin_bar ) {
$admin_bar = new BackWPup_Adminbar( $admin );
add_action( 'init', [ $admin_bar, 'init' ] );
}

new BackWPup_EasyCron();
}
Expand Down
12 changes: 12 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
== Changelog ==
= 4.1.3 =
Release date: Jul 05, 2024

* Changed: Upgraded minimum version to PHP 7.4
* Fixed: Evaluate notice doesn't dismiss
* Removed: General tab on settings page
** Admin bar: enabled by default, can be disabled with a filter (backwpup_is_in_admin_bar)
** Folder sizes: disabled by default, can be enabled with a filter (backwpup_show_folder_size)
** Protect folders: we protect your folders by default can be disabled with a filter (backwpup_protect_folders)
** Plugin data: we delete all plugin data after its delation by default
* Fixed: Fix S3 uploads over 5 Gb

= 4.1.2 =
Release date: Jun 27, 2024

Expand Down
5 changes: 3 additions & 2 deletions inc/Notice/EvaluateNotice.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Inpsyde\BackWPup\Notice;
namespace Inpsyde\BackWPup\Notice; // phpcs:ignore

use BackWPup_Option;
use BackWPup;
Expand Down Expand Up @@ -53,7 +53,8 @@ protected function isScreenAllowed(): bool {
*/
protected function shouldDisplay(): bool {
// Check if the notice has been dismissed.
$option = new DismissibleNoticeOption( false );
$site_wide = is_multisite() ? true : false;
$option = new DismissibleNoticeOption( $site_wide );
if ( $option->is_dismissed( static::ID ) ) {
return false;
}
Expand Down
21 changes: 14 additions & 7 deletions inc/Notice/Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,20 @@ public function init(string $type = self::TYPE_BACKWPUP): void
}
if ($type === self::TYPE_BACKWPUP) {
add_action('backwpup_admin_messages', function (): void {
$this->notice();
}, 20);
} elseif ($type === static::TYPE_ADMIN) {
add_action('admin_notices', function (): void {
$this->notice();
}, 20);
} else {
$this->notice();
},
20
);
} elseif ( static::TYPE_ADMIN === $type ) {
$action_name = is_multisite() ? 'network_admin_notices' : 'admin_notices';
add_action(
$action_name,
function (): void {
$this->notice();
},
20
);
} else {
throw new \InvalidArgumentException(
__('Invalid notice type specified', 'backwpup')
);
Expand Down
6 changes: 3 additions & 3 deletions inc/Notice/PhpNotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class PhpNotice extends EnvironmentNotice
*/
protected function getConstraints(): array
{
return [
new PhpConstraint('7.2'),
];
return [
new PhpConstraint( '7.4' ),
];
}

/**
Expand Down
14 changes: 8 additions & 6 deletions inc/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,14 @@ private function admin_init_pro()
add_action('wp_ajax_encrypt_key_handler', [$ajax_encryption_key_handler, 'handle']);
}

private function init_notices()
{
// Show notice if PHP < 7.2
$phpNotice = new PhpNotice(
new NoticeView(PhpNotice::ID)
);
/**
* Init the plugin notices.
*/
private function init_notices() {
// Show notice if PHP < 7.4.
$phpNotice = new PhpNotice( //phpcs:ignore
new NoticeView( PhpNotice::ID )
);
$phpNotice->init(PhpNotice::TYPE_ADMIN);

// Show notice if WordPress < 5.0
Expand Down
31 changes: 18 additions & 13 deletions inc/class-destination-s3.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
// phpcs:ignoreFile
// Amazon S3 SDK v3.93.7
// http://aws.amazon.com/de/sdkforphp2/
// https://github.com/aws/aws-sdk-php
Expand Down Expand Up @@ -896,7 +897,16 @@ public function job_run_archive(BackWPup_Job $job_object): bool
$job_object->log(__('Starting upload to S3 Service&#160;&hellip;', 'backwpup'));
}

if (!$aws_destination->supportsMultipart() || $job_object->backup_filesize < 1048576 * 6) {
//Calculate chunk size for S3 uploads. Limits see: https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html
$chunk_size = 1024 * 1024 * 5;
if (1000 < ceil($job_object->backup_filesize / $chunk_size)) {
$chunk_size = $chunk_size * 2;
}
if (10000 < ceil($job_object->backup_filesize / $chunk_size)) {
$chunk_size = (int) ceil($job_object->backup_filesize / 10000);
}

if (!$aws_destination->supportsMultipart() || $job_object->backup_filesize <= $chunk_size) {
// Prepare Upload
if (!$up_file_handle = fopen($job_object->backup_folder . $job_object->backup_file, 'rb')) {
$job_object->log(__('Can not open source file for transfer.', 'backwpup'), E_USER_ERROR);
Expand Down Expand Up @@ -980,24 +990,25 @@ public function job_run_archive(BackWPup_Job $job_object): bool
}

while (!feof($file_handle)) {
$part_number = $job_object->steps_data[$job_object->step_working]['Part'];
$chunk_upload_start = microtime(true);
$part_data = fread($file_handle, 1048576 * 5); //5MB Minimum part size
$part_data = fread($file_handle, $chunk_size);
$part = $s3->uploadPart([
'Bucket' => $job_object->job['s3bucket'],
'UploadId' => $job_object->steps_data[$job_object->step_working]['UploadId'],
'Key' => $job_object->job['s3dir'] . $job_object->backup_file,
'PartNumber' => $job_object->steps_data[$job_object->step_working]['Part'],
'PartNumber' => $part_number,
'Body' => $part_data,
]);
$chunk_upload_time = microtime(true) - $chunk_upload_start;
$job_object->substeps_done = $job_object->substeps_done + strlen(
$part_data
);
$job_object->steps_data[$job_object->step_working]['Parts'][] = [
$job_object->steps_data[$job_object->step_working]['Parts'][$part_number - 1] = [
'ETag' => $part->get('ETag'),
'PartNumber' => $job_object->steps_data[$job_object->step_working]['Part'],
'PartNumber' => $part_number,
];
++$job_object->steps_data[$job_object->step_working]['Part'];
$job_object->steps_data[$job_object->step_working]['Part']++;
$time_remaining = $job_object->do_restart_time();
if ($time_remaining < $chunk_upload_time) {
$job_object->do_restart_time(true);
Expand All @@ -1006,17 +1017,11 @@ public function job_run_archive(BackWPup_Job $job_object): bool
gc_collect_cycles();
}

$parts = $s3->listParts([
'Bucket' => $job_object->job['s3bucket'],
'Key' => $job_object->job['s3dir'] . $job_object->backup_file,
'UploadId' => $job_object->steps_data[$job_object->step_working]['UploadId'],
]);

$s3->completeMultipartUpload([
'Bucket' => $job_object->job['s3bucket'],
'UploadId' => $job_object->steps_data[$job_object->step_working]['UploadId'],
'MultipartUpload' => [
'Parts' => $parts['Parts'],
'Parts' => $job_object->steps_data[$job_object->step_working]['Parts'],
],
'Key' => $job_object->job['s3dir'] . $job_object->backup_file,
]);
Expand Down
69 changes: 48 additions & 21 deletions inc/class-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,31 @@ public static function is_in_open_basedir($file)
return false;
}

/**
* get size of files in folder.
*
* @param string $folder the folder to calculate
* @param bool $deep went thrue suborders
*
* @return int folder size in byte
*/
public static function get_folder_size($folder)
{
$files_size = 0;

if (!is_readable($folder)) {
return $files_size;
}
/**
* Get size of files in folder if enabled
*
* @param string $folder the folder to calculate.
*
* @return string folder size formated in human readable format
*/
public static function get_folder_size( $folder ) {

/**
* Filter whether BackWPup will show the folder size.
*
* @param bool $show_folder_size whether BackWPup will show the folder size or not.
*/
$show_folder_size = (bool) apply_filters( 'backwpup_show_folder_size', (bool) get_site_option( 'backwpup_cfg_showfoldersize' ) );

if ( ! $show_folder_size ) {
return '';
}

$files_size = 0;

if ( ! is_readable( $folder ) ) {
return self::format_size( $files_size );
}

$iterator = new RecursiveIteratorIterator(new BackWPup_Recursive_Directory($folder, FilesystemIterator::SKIP_DOTS));

Expand All @@ -89,8 +99,19 @@ public static function get_folder_size($folder)
}
}

return $files_size;
}
return self::format_size( $files_size );
}

/**
* Format size in human readable format.
*
* @param int $size
*
* @return string
*/
protected static function format_size( $size ): string {
return ' (' . size_format( $size, 2 ) . ')';
}

/**
* Get an absolute path if it is relative.
Expand Down Expand Up @@ -166,10 +187,16 @@ public static function check_folder(string $folder, bool $donotbackup = false):
return sprintf(__('Folder "%1$s" is not writable', 'backwpup'), $childFolder);
}

//create files for securing folder
if (get_site_option('backwpup_cfg_protectfolders')) {
self::protect_folder($childFolder);
}
// create files for securing folder.
/**
* Filter whether BackWPup will protect the folders.
*
* @param bool $protect_folders Whether the folder will be protect or not.
*/
$protect_folders = (bool) apply_filters( 'backwpup_protect_folders', (bool) get_site_option( 'backwpup_cfg_protectfolders' ) );
if ( $protect_folders ) {
self::protect_folder( $childFolder ); // phpcs:ignore
}

//Create do not backup file for this folder
if ($donotbackup) {
Expand Down
13 changes: 7 additions & 6 deletions inc/class-jobtype-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,12 @@ private function get_exclude_dirs($folder, $excludedir = [])
private function show_folder($id, $jobid, $path)
{
$folder = realpath(BackWPup_Path_Fixer::fix_path($path));
$folder_size = 0;
if ($folder) {
$folder = untrailingslashit(str_replace('\\', '/', $folder));
$folder_size = (get_site_option('backwpup_cfg_showfoldersize')) ? ' (' . size_format(BackWPup_File::get_folder_size($folder), 2) . ')' : '';
} ?>
$folder_size = 0;
if ( $folder ) {
$folder = untrailingslashit( str_replace( '\\', '/', $folder ) );
$folder_size = BackWPup_File::get_folder_size( $folder );
}
?>
<input class="checkbox"
type="checkbox"<?php checked(BackWPup_Option::get($jobid, 'backup' . $id)); ?>
name="backup<?php echo esc_attr($id); ?>" id="idbackup<?php echo esc_attr($id); ?>" value="1" /> <code title="<?php echo esc_attr(sprintf(__('Path as set by user (symlink?): %s', 'backwpup'), $path)); ?>"><?php echo esc_attr($folder); ?></code><?php echo esc_html($folder_size); ?>
Expand All @@ -532,7 +533,7 @@ private function show_folder($id, $jobid, $path)
// List only the folders without thoses listed by auto exclude!
if ( ! $file->isDot() && $file->isDir() && ! in_array( trailingslashit( $file->getPathname() ), $this->get_exclude_dirs( $folder, $dir::get_auto_exclusion_plugins_folders() ), true ) ) {
$donotbackup = file_exists( $file->getPathname() . '/.donotbackup' );
$folder_size = ( get_site_option( 'backwpup_cfg_showfoldersize' ) ) ? ' (' . size_format( BackWPup_File::get_folder_size( $file->getPathname() ), 2 ) . ')' : '';
$folder_size = BackWPup_File::get_folder_size( $file->getPathname() );
$title = '';
if ( $donotbackup ) {
$excludes[] = $file->getFilename();
Expand Down
54 changes: 28 additions & 26 deletions inc/class-option.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,36 @@ final class BackWPup_Option
{
/**
* add filter for Site option defaults.
*/
public static function default_site_options()
{
//global
add_site_option('backwpup_version', '0.0.0');
//job default
add_site_option('backwpup_jobs', []);
//general
add_site_option('backwpup_cfg_showadminbar', false);
add_site_option('backwpup_cfg_showfoldersize', false);
add_site_option('backwpup_cfg_protectfolders', true);
//job
add_site_option('backwpup_cfg_jobmaxexecutiontime', 30);
add_site_option('backwpup_cfg_jobstepretry', 3);
add_site_option('backwpup_cfg_jobrunauthkey', BackWPup::get_generated_hash(8));
add_site_option('backwpup_cfg_loglevel', 'normal_translated');
add_site_option('backwpup_cfg_jobwaittimems', 0);
add_site_option('backwpup_cfg_jobdooutput', 0);
add_site_option('backwpup_cfg_windows', 0);
//Logs
add_site_option('backwpup_cfg_maxlogs', 30);
add_site_option('backwpup_cfg_gzlogs', 0);
$upload_dir = wp_upload_dir(null, false, true);
$logs_dir = trailingslashit(str_replace(
'\\',
*/
public static function default_site_options() {
// global.
add_site_option( 'backwpup_version', '0.0.0' );
// job default.
add_site_option( 'backwpup_jobs', [] );
// general.
add_site_option( 'backwpup_cfg_showadminbar', true );
add_site_option( 'backwpup_cfg_showfoldersize', false );
add_site_option( 'backwpup_cfg_protectfolders', true );
add_site_option( 'backwpup_cfg_keepplugindata', false );
// job.
add_site_option( 'backwpup_cfg_jobmaxexecutiontime', 30 );
add_site_option( 'backwpup_cfg_jobstepretry', 3 );
add_site_option( 'backwpup_cfg_jobrunauthkey', BackWPup::get_generated_hash( 8 ) );
add_site_option( 'backwpup_cfg_loglevel', 'normal_translated' );
add_site_option( 'backwpup_cfg_jobwaittimems', 0 );
add_site_option( 'backwpup_cfg_jobdooutput', 0 );
add_site_option( 'backwpup_cfg_windows', 0 );
// Logs.
add_site_option( 'backwpup_cfg_maxlogs', 30 );
add_site_option( 'backwpup_cfg_gzlogs', 0 );
$upload_dir = wp_upload_dir( null, false, true );
$logs_dir = trailingslashit(
str_replace(
'\\',
'/',
$upload_dir['basedir']
)) . 'backwpup/' . BackWPup::get_plugin_data( 'hash' ) . '/logs/';
)
) . 'backwpup/' . BackWPup::get_plugin_data( 'hash' ) . '/logs/';
$content_path = trailingslashit( str_replace( '\\', '/', (string) WP_CONTENT_DIR ) );
$logs_dir = str_replace( $content_path, '', $logs_dir );
add_site_option( 'backwpup_cfg_logfolder', $logs_dir );
Expand Down
Loading

0 comments on commit 8288e6c

Please sign in to comment.