15, 'backupdir' => $backups_dir, 'backupsyncnodelete' => true );
}
/**
* @inheritdoc
*/
public function edit_tab( $jobid ) {
?>
isDot()
|| $file->isDir()
|| $file->isLink()
|| in_array( $file->getFilename(), $not_allowed_files, true )
) {
continue;
}
if ( $file->isReadable() ) {
//file list for backups
$files[ $filecounter ]['folder'] = $backup_folder;
$files[ $filecounter ]['file'] = str_replace( '\\', '/', $file->getPathname() );
$files[ $filecounter ]['filename'] = $file->getFilename();
$files[ $filecounter ]['downloadurl'] = add_query_arg(
array(
'page' => 'backwpupbackups',
'action' => 'downloadfolder',
'file' => $file->getFilename(),
'local_file' => $file->getFilename(),
'jobid' => $jobid,
),
network_admin_url( 'admin.php' )
);
$files[ $filecounter ]['filesize'] = $file->getSize();
$files[ $filecounter ]['time'] = $file->getMTime() + ( get_option( 'gmt_offset' ) * 3600 );
$filecounter ++;
}
}
}
$files = array_filter( $files );
return $files;
}
/**
* @inheritdoc
*/
public function job_run_archive( BackWPup_Job $job_object ) {
$job_object->substeps_todo = 1;
if ( ! empty( $job_object->job['jobid'] ) ) {
BackWPup_Option::update(
$job_object->job['jobid'],
'lastbackupdownloadurl',
add_query_arg(
array(
'page' => 'backwpupbackups',
'action' => 'downloadfolder',
'file' => basename( $job_object->backup_file ),
'jobid' => $job_object->job['jobid'],
),
network_admin_url( 'admin.php' )
)
);
}
// Delete old Backupfiles.
$backupfilelist = array();
$files = array();
if ( is_writable( $job_object->backup_folder ) ) { //make file list
try {
$dir = new BackWPup_Directory( $job_object->backup_folder );
foreach ( $dir as $file ) {
if ( $file->isDot() || $file->isDir() || $file->isLink() || ! $file->isWritable() ) {
continue;
}
$is_backup_archive = $this->is_backup_archive( $file->getFilename() );
$is_owned_by_job = $this->is_backup_owned_by_job( $file->getFilename(), $job_object->job['jobid'] );
if ( $is_backup_archive && $is_owned_by_job ) {
$backupfilelist[ $file->getMTime() ] = clone $file;
}
}
} catch ( UnexpectedValueException $e ) {
$job_object->log(
sprintf(
esc_html__( 'Could not open path: %s', 'backwpup' ),
$e->getMessage()
),
E_USER_WARNING
);
}
}
if ( $job_object->job['maxbackups'] > 0 ) {
if ( count( $backupfilelist ) > $job_object->job['maxbackups'] ) {
ksort( $backupfilelist );
$numdeltefiles = 0;
while ( $file = array_shift( $backupfilelist ) ) {
if ( count( $backupfilelist ) < $job_object->job['maxbackups'] ) {
break;
}
unlink( $file->getPathname() );
foreach ( $files as $key => $filedata ) {
if ( $filedata['file'] === $file->getPathname() ) {
unset( $files[ $key ] );
}
}
$numdeltefiles ++;
}
if ( $numdeltefiles > 0 ) {
$job_object->log( sprintf(
_n( 'One backup file deleted', '%d backup files deleted', $numdeltefiles, 'backwpup' ),
$numdeltefiles
),
E_USER_NOTICE );
}
}
}
$job_object->substeps_done ++;
return true;
}
/**
* @inheritdoc
*/
public function can_run( array $job_settings ) {
if ( empty( $job_settings['backupdir'] ) || $job_settings['backupdir'] == '/' ) {
return false;
}
return true;
}
}