@@ -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 ' ) ) ) {
0 commit comments