Skip to content

Commit e3bbc65

Browse files
committed
Latest changes
1 parent 84e6b77 commit e3bbc65

6 files changed

Lines changed: 53 additions & 27 deletions

File tree

admin/class-boldgrid-backup-admin-core.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,9 +1582,7 @@ public function archive_files( &$info ) {
15821582
);
15831583
$this->logger->add_memory();
15841584

1585-
Boldgrid_Backup_Admin_In_Progress_Data::set_arg( 'status', esc_html__( 'Wrapping things up...', 'boldgrid-backup' ) );
1586-
Boldgrid_Backup_Admin_In_Progress_Data::set_arg( 'percentage', 100 );
1587-
1585+
// Log size of all files archived. Also handled in V2\Archiver\Steps\Discovery::files().
15881586
$info['total_size'] += $this->filelist->get_total_size( $filelist );
15891587

15901588
if ( true === $status && ! $archive_exists ) {
@@ -1596,17 +1594,6 @@ public function archive_files( &$info ) {
15961594
return $status;
15971595
}
15981596

1599-
$info['lastmodunix'] = $this->wp_filesystem->mtime( $info['filepath'] );
1600-
1601-
// Modify the archive file permissions to help protect from public access.
1602-
$this->wp_filesystem->chmod( $info['filepath'], 0600 );
1603-
1604-
// Add some statistics to the return.
1605-
$info['filesize'] = $this->wp_filesystem->size( $info['filepath'] );
1606-
1607-
// Delete the temporary database dump file.
1608-
$this->wp_filesystem->delete( $this->db_dump_filepath, false, 'f' );
1609-
16101597
return $info;
16111598
}
16121599

includes/class-boldgrid-backup-archiver.php

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class Boldgrid_Backup_Archiver {
5555
*/
5656
private static $is_archiving = false;
5757

58+
/**
59+
*
60+
*/
61+
private $is_resuming = false;
62+
5863
/**
5964
* An instance of Boldgrid_Backup_Admin_Task.
6065
*
@@ -75,15 +80,25 @@ class Boldgrid_Backup_Archiver {
7580
* @since SINCEVERSION
7681
*/
7782
public function __construct( $id = null ) {
78-
$this->core = apply_filters( 'boldgrid_backup_get_core', null );
79-
$this->format = $this->core->settings->get_setting( 'format' );
83+
$this->is_resuming = ! is_null( $id );
84+
$this->core = apply_filters( 'boldgrid_backup_get_core', null );
85+
$this->format = $this->core->settings->get_setting( 'format' );
8086

8187
if ( 'one' === $this->format ) {
8288
$this->info = new \Boldgrid\Backup\Archiver\Info( 'one', array() );
8389
} else {
8490
$this->backup_process = \BoldGrid\Backup\V2\Archiver\Factory::run( $id );
8591
$this->info = new \Boldgrid\Backup\Archiver\Info( 'many', $this->backup_process );
8692
$this->resumer = new \Boldgrid\Backup\V2\Archiver\Resumer();
93+
94+
if ( $this->is_resuming ) {
95+
// Normally, task is initialized in init(). Initialize task now as init() won't be ran.
96+
$this->task = new Boldgrid_Backup_Admin_Task();
97+
$this->task->init_by_id( $this->info->get_key( 'task_id' ) );
98+
99+
// Initialize the logger. Mainly for logging done within self::complete().
100+
$this->core->logger->init( $this->info->get_key( 'log_filename' ) );
101+
}
87102
}
88103
}
89104

@@ -93,6 +108,21 @@ public function __construct( $id = null ) {
93108
* @since SINCEVERSION
94109
*/
95110
public function complete() {
111+
Boldgrid_Backup_Admin_In_Progress_Data::set_arg( 'status', esc_html__( 'Wrapping things up...', 'boldgrid-backup' ) );
112+
Boldgrid_Backup_Admin_In_Progress_Data::set_arg( 'percentage', 100 );
113+
114+
$filepath = $this->info->get_key( 'filepath' );
115+
116+
// Add some statistics to the return.
117+
$this->info->set_key( 'lastmodunix', $this->core->wp_filesystem->mtime( $filepath ) );
118+
$this->info->set_key( 'filesize', $this->core->wp_filesystem->size( $filepath ) );
119+
120+
// Modify the archive file permissions to help protect from public access.
121+
$this->core->wp_filesystem->chmod( $filepath, 0600 );
122+
123+
// Delete the temporary database dump file.
124+
$this->core->wp_filesystem->delete( $this->info->get_key( 'db_dump_filepath' ), false, 'f' );
125+
96126
// Calculate duration.
97127
$this->info->set_key( 'duration', number_format( ( microtime( true ) - $this->info->get_key( 'time_start' ) ), 2, '.', '' ) );
98128
$this->info->set_key( 'db_duration', number_format( ( $this->info->get_key( 'db_time_stop' ) - $this->info->get_key( 'time_start' ) ), 2, '.', '' ) );
@@ -218,6 +248,7 @@ public function init() {
218248
$this->task->init( [ 'type' => 'backup' ] );
219249
}
220250
$this->task->start();
251+
$this->info->set_key( 'task_id', $this->task->get_id() );
221252

222253
self::$is_archiving = true;
223254

@@ -355,11 +386,11 @@ public static function is_archiving() {
355386
/**
356387
*
357388
*/
358-
public function is_init_incomplete() {
389+
public function is_init_complete() {
359390
$start = $this->info->get_key( 'time_start' );
360391
$end = $this->info->get_key( 'init_time_end' );
361392

362-
return ! empty( $start ) && empty( $end );
393+
return ! empty( $start ) && ! empty( $end );
363394
}
364395

365396
/**
@@ -370,11 +401,10 @@ public function is_init_incomplete() {
370401
* @since SINCEVERSION
371402
*/
372403
public function run() {
373-
// Todo. If resuming, do we run init again?
374-
if ( $this->is_init_incomplete() ) {
375-
$this->info->set_key( 'error', __( 'Unable to initialize backup. Previous init was incomplete.', 'boldgrid-backup' ) );
376-
} else {
404+
if ( ! $this->is_resuming ) {
377405
$this->init();
406+
} elseif ( ! $this->is_init_complete() ) {
407+
$this->info->set_key( 'error', __( 'Unable to initialize backup. Previous init was incomplete.', 'boldgrid-backup' ) );
378408
}
379409

380410
if ( empty( $this->info->get_key( 'error' ) ) ) {

includes/v2/archiver/class-archiver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function run() {
7575

7676
if ( ! $step_success ) {
7777
// Failed to create zip. todo: cleanup?
78+
$this->log( 'ERROR: Step failed.' );
7879
return false;
7980
}
8081
}

includes/v2/archiver/steps/archive_files/class-part.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ public function add_batch( $batch_filelist_filepath ) {
122122

123123
$archive_command = 'cd ' . ABSPATH . '; zip ' . $this->filepath . ' ' . $j . ' -@ < ' . $batch_filelist_filepath;
124124

125-
// error_log( '$archive_command = ' . getmypid() . ' ' . $archive_command );
126-
127125
$this->archive_files->get_core()->execute_command( $archive_command, $success, $return );
128126

129127
$new_size = $this->get_size();
130128

131-
return ( $original_size !== $new_size ) && $success;
129+
if ( $success && $original_size === $new_size ) {
130+
$this->archive_files->log( 'WARNING: Archive filesize did not change after adding files. It could be that this is not the first attempt, but the first attempt DID finish archiving but DID NOT finish completing the step.' );
131+
}
132+
133+
return $success;
132134
}
133135

134136
/**

includes/v2/archiver/steps/class-archive-files.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ private function get_next_batch() {
176176
*
177177
* The additional spacing added to make it easier to read in the log.
178178
*/
179+
// Additional log data availalbe if needed.
180+
/*
179181
$part_size = $part->get_size();
180182
$batch_zize = $max_batch_size - $remaining_size;
181183
$log_data = array(
@@ -191,6 +193,7 @@ private function get_next_batch() {
191193
'part remaining size ' => size_format( $remaining_size, 2 ) . ' / ' . $remaining_size,
192194
);
193195
$this->log( 'New batch created and needs processing: ' . print_r( $log_data, 1 ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
196+
*/
194197

195198
return $success ? $batch_info : false;
196199
}

includes/v2/archiver/steps/class-discovery.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ private function database() {
5656
private function files() {
5757
$filelist_creator = new \Boldgrid\Backup\V2\Filelist\Create();
5858
$files = $filelist_creator->run();
59+
$total_size = $filelist_creator->get_total_size();
5960

60-
\Boldgrid_Backup_Admin_In_Progress_Data::set_arg( 'total_size_archived', $filelist_creator->get_total_size() );
61-
\Boldgrid_Backup_Admin_In_Progress_Data::set_arg( 'total_size_archived_size_format', size_format( $filelist_creator->get_total_size(), 2 ) );
61+
\Boldgrid_Backup_Admin_In_Progress_Data::set_arg( 'total_size_archived', $total_size );
62+
\Boldgrid_Backup_Admin_In_Progress_Data::set_arg( 'total_size_archived_size_format', size_format( $total_size, 2 ) );
63+
64+
$this->info->set_key( 'total_size', $total_size );
6265

6366
$filelists = array();
6467

0 commit comments

Comments
 (0)