From 0136fec9e99b70ef679fcb92222db82e8d5ea25c Mon Sep 17 00:00:00 2001 From: bwmarkle Date: Tue, 13 Oct 2020 13:41:48 -0400 Subject: [PATCH] Issue 376 (#392) * Initial ftp log. Fixes #376 * Bunny cdn fix --- .../class-boldgrid-backup-admin-ftp.php | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/admin/remote/class-boldgrid-backup-admin-ftp.php b/admin/remote/class-boldgrid-backup-admin-ftp.php index 63f50210..a2541654 100644 --- a/admin/remote/class-boldgrid-backup-admin-ftp.php +++ b/admin/remote/class-boldgrid-backup-admin-ftp.php @@ -301,7 +301,7 @@ public function create_backup_dir() { } $contents = $this->get_contents(); - if ( ! $contents || ! is_array( $contents ) ) { + if ( ! is_array( $contents ) ) { $this->errors[] = __( 'Unable to get a directory listing from FTP server.', 'boldgrid-backup' ); return false; } elseif ( in_array( $this->get_folder_name(), $contents, true ) ) { @@ -1098,6 +1098,11 @@ public function is_uploaded( $filepath ) { * @return bool */ public function upload( $filepath ) { + $logger = new Boldgrid_Backup_Admin_Log( $this->core ); + $logger->init( 'ftp.log' ); + $logger->add_separator(); + $logger->add( 'Beginning ' . __METHOD__ . '...' ); + // Make sure our backup file exists. if ( ! $this->core->wp_filesystem->exists( $filepath ) ) { $this->last_error = sprintf( @@ -1105,25 +1110,36 @@ public function upload( $filepath ) { __( 'Archive does not exist: $1$s', 'boldgrid-backup' ), $filepath ); + $logger->add( $this->last_error ); return false; } $remote_file = $this->get_folder_name() . '/' . basename( $filepath ); + $logger->add( 'Local path: ' . $filepath . ' / ' . $this->core->wp_filesystem->size( $filepath ) ); + $logger->add( 'Remote path: ' . $remote_file ); + $timestamp = filemtime( $filepath ); + $logger->add( 'Connecting...' ); $this->connect(); + $logger->add( 'Logging in...' ); $this->log_in(); if ( ! $this->logged_in ) { - $this->errors[] = __( 'Unable to log in to ftp server.', 'boldgrid-backup' ); + $error = __( 'Unable to log in to ftp server.', 'boldgrid-backup' ); + $this->errors[] = $error; + $logger->add( $error ); return false; } $has_remote_dir = $this->create_backup_dir(); if ( ! $has_remote_dir ) { + $logger->add( 'Unable to create backup directory on remote host.' ); return false; } + $logger->add( 'Beginning upload...' ); + switch ( $this->type ) { case 'ftp': case 'ftpes': @@ -1148,6 +1164,8 @@ public function upload( $filepath ) { break; } + $logger->add( 'Upload status: ' . print_r( $uploaded,1 ) ); //phpcs:ignore + if ( ! $uploaded ) { $last_error = error_get_last(); @@ -1165,8 +1183,15 @@ public function upload( $filepath ) { return false; } + $logger->add( 'Enforcing retention...' ); $this->enforce_retention(); + $logger->add( 'Retention enforcement complete!' ); + + $logger->add( 'Getting remote contents...' ); + $contents = $this->get_contents( true, $this->get_folder_name() ); + $logger->add( 'Remote contents: ' . print_r( $contents, 1 ) ); // phpcs:ignore + $logger->add( 'Completed ' . __METHOD__ . '!' ); return true; } }