Skip to content

Commit

Permalink
Issue 376 (#392)
Browse files Browse the repository at this point in the history
* Initial ftp log. Fixes #376

* Bunny cdn fix
  • Loading branch information
bwmarkle authored Oct 13, 2020
1 parent bb4e25c commit 0136fec
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions admin/remote/class-boldgrid-backup-admin-ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -1098,32 +1098,48 @@ 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(
// translators: 1 The filepath to a backup file.
__( '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':
Expand All @@ -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();

Expand All @@ -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;
}
}

0 comments on commit 0136fec

Please sign in to comment.