Skip to content

Commit

Permalink
Newer backup is being replaced instead of older one
Browse files Browse the repository at this point in the history
  • Loading branch information
lesterchan committed Jan 17, 2020
1 parent 2415adf commit c691b28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@ Donate link: http://lesterchan.net/site/donation/
Tags: database, manage, wp-dbmanager, manager, table, optimize, backup, queries, query, drop, empty, tables, table, run, repair, cron, schedule, scheduling, automatic
Requires at least: 4.0
Tested up to: 5.3
Stable tag: 2.80.1
Stable tag: 2.80.2

Manages your WordPress database.

Expand Down Expand Up @@ -43,6 +43,9 @@ Allows you to optimize database, repair database, backup database, restore datab

## Changelog

### Version 2.80.2
* FIXED: Newer backup is being replaced instead of older backup

### Version 2.80.1
* FIXED: 1970 date issues.
* FIXED: Sorting order of backup files.
Expand Down
27 changes: 13 additions & 14 deletions wp-dbmanager.php
Expand Up @@ -3,15 +3,15 @@
Plugin Name: WP-DBManager
Plugin URI: https://lesterchan.net/portfolio/programming/php/
Description: Manages your WordPress database. Allows you to optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. Supports automatic scheduling of backing up, optimizing and repairing of database.
Version: 2.80.1
Version: 2.80.2
Author: Lester 'GaMerZ' Chan
Author URI: https://lesterchan.net
Text Domain: wp-dbmanager
*/


/*
Copyright 2019 Lester Chan (email : lesterchan@gmail.com)
Copyright 2020 Lester Chan (email : lesterchan@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -411,30 +411,29 @@ function is_emtpy_folder($folder){

### Function: Make Sure Maximum Number Of Database Backup Files Does Not Exceed
function check_backup_files() {
$backup_options = get_option('dbmanager_options');
$backup_options = get_option( 'dbmanager_options' );
$database_files = array();
if(!is_emtpy_folder($backup_options['path'])) {
if ($handle = opendir($backup_options['path'])) {
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) {
$database_files[] = $file;
if ( ! is_emtpy_folder( $backup_options['path'] ) ) {
if ( $handle = opendir($backup_options['path'] ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file !== '.' && $file !== '..' && ( file_ext( $file ) === 'sql' || file_ext( $file ) === 'gz' ) ) {
$database_files[ filemtime( $backup_options['path'] . '/' . $file ) ] = $file;
}
}
closedir($handle);
sort($database_files);
closedir( $handle );
ksort( $database_files );
}
}
if(sizeof($database_files) >= $backup_options['max_backup']) {
@unlink($backup_options['path'].'/'.$database_files[0]);
if ( sizeof( $database_files ) >= $backup_options['max_backup'] ) {
@unlink( $backup_options['path'] . '/' . $database_files[ array_key_first( $database_files ) ] );
}
}


### Function: DBManager Default Options
function dbmanager_default_options( $option_name )
{
switch( $option_name )
{
switch( $option_name ) {
case 'backup_email_from':
return get_option( 'admin_email' );
break;
Expand Down

0 comments on commit c691b28

Please sign in to comment.