Changeset 3124649
- Timestamp:
- 07/24/2024 02:00:48 PM (20 months ago)
- Location:
- wp-database-backup/tags/6.12
- Files:
-
- 6 edited
-
includes/admin/class-wpdb-admin.php (modified) (25 diffs)
-
includes/admin/class-wpdbbkp-restore.php (modified) (1 diff)
-
includes/admin/cron-create-full-backup.php (modified) (9 diffs)
-
includes/admin/mb-helper-functions.php (modified) (1 diff)
-
includes/class-wpdbfullbackuplog.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-database-backup/tags/6.12/includes/admin/class-wpdb-admin.php
r3124584 r3124649 147 147 if ( 1 === $wp_db_remove_local_backup ) { 148 148 if ( file_exists( $args[1] ) ) { 149 unlink( $args[1] );// File path.149 wp_delete_file( $args[1] );// File path. 150 150 } 151 151 } … … 234 234 $path_info = wp_upload_dir(); 235 235 if ( file_exists( $path_info['basedir'] . '/db-backup/.htaccess' ) ) { 236 unlink( $path_info['basedir'] . '/db-backup/.htaccess' );236 wp_delete_file( $path_info['basedir'] . '/db-backup/.htaccess' ); 237 237 } 238 238 } … … 311 311 // If $file is NOT a directory remove it. 312 312 if ( ! is_dir( $file ) ) { 313 unlink( $dir . $file );313 wp_delete_file( $dir . $file ); 314 314 } 315 315 } … … 349 349 chdir($file_directory); 350 350 if ( isset($options[ $index ]['filename']) && file_exists( $options[ $index ]['filename'] ) ) { 351 unlink( $options[ $index ]['filename'] );351 wp_delete_file( $options[ $index ]['filename'] ); 352 352 } 353 353 if(isset($options[ $index ]['filename'])){ 354 354 $file_sql = explode( '.', $options[ $index ]['filename'] ); 355 355 if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) { 356 unlink( $file_sql[0] . '.sql' );356 wp_delete_file( $file_sql[0] . '.sql' ); 357 357 } 358 358 } 359 359 360 360 chdir($actual_working_directory); 361 $newoptions = wpdbbkp_filter_unique_filenames( $newoptions ); 361 362 update_option( 'wp_db_backup_backups', $newoptions , false); 362 363 $nonce = wp_create_nonce( 'wp-database-backup' ); … … 382 383 foreach($files as $file) { 383 384 if(is_file($file)){ 384 unlink($file);385 wp_delete_file($file); 385 386 } 386 387 } … … 417 418 if ( ! ( in_array( $file, $backup_check_list, true ) ) ) { 418 419 if ( file_exists( $wp_db_backup_path . '/' . $file ) ) { 419 unlink( $wp_db_backup_path . '/' . $file );420 wp_delete_file( $wp_db_backup_path . '/' . $file ); 420 421 } 421 422 $delete_message .= ' ' . $file; … … 553 554 if ( isset( $options[ $index ]['sqlfile'] ) && file_exists( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0. 554 555 if ( file_exists( $options[ $index ]['sqlfile'] ) ) { 555 unlink( $options[ $index ]['sqlfile'] );556 wp_delete_file( $options[ $index ]['sqlfile'] ); 556 557 } 557 558 } else { … … 562 563 $database_file = ( $file_sql[0] . '.sql' ); 563 564 if ( file_exists( $database_file ) ) { 564 unlink( $database_file );565 wp_delete_file( $database_file ); 565 566 } 566 567 … … 631 632 632 633 $options = get_option( 'wp_db_backup_backups' ); 633 $options = $this->wpdbbkp_filter_unique_filenames( $options );634 $options = wpdbbkp_filter_unique_filenames( $options ); 634 635 $settings = get_option( 'wp_db_backup_options' ); 635 636 $wp_db_log = get_option( 'wp_db_log' ); ?> … … 1903 1904 $wpdb->flush(); 1904 1905 /* BEGIN : Prevent saving backup plugin settings in the database dump */ 1906 $options_backup = wpdbbkp_filter_unique_filenames( $options_backup ); 1905 1907 add_option( 'wp_db_backup_backups', $options_backup ); 1906 1908 add_option( 'wp_db_backup_options', $settings_backup ); … … 1925 1927 1926 1928 // Initialize the file with table creation statement if it doesn't exist 1927 $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore 1929 1930 $table = esc_sql( $table ); 1931 $row2 = $wpdb->get_row( "SHOW CREATE TABLE `{$table}`", ARRAY_N ); // phpcs:ignore 1928 1932 $initial_output = "\n\n" . $row2[1] . ";\n\n"; 1929 1933 … … 1977 1981 1978 1982 $sub_limit = 500; 1979 $check_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" ); // phpcs:ignore 1983 // phpcs:ignore 1984 $check_count = $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" ); 1980 1985 $check_count = intval( $check_count ); 1981 1986 … … 1985 1990 for ( $sub_i = 0; $sub_i < $t_sub_queries; $sub_i++ ) { 1986 1991 $sub_offset = $sub_i * $sub_limit; 1987 $sub_result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM ` $table` LIMIT %d OFFSET %d", array( $sub_limit, $sub_offset ) ), ARRAY_A ); // phpcs:ignore1992 $sub_result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$table}` LIMIT %d OFFSET %d", array( $sub_limit, $sub_offset ) ), ARRAY_A ); // phpcs:ignore 1988 1993 1989 1994 if ( $sub_result ) { … … 2011 2016 } 2012 2017 } else { 2013 $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `$table`" ), ARRAY_A ); // phpcs:ignore2018 $result = $wpdb->get_results( "SELECT * FROM `{$table}`", ARRAY_A ); // phpcs:ignore 2014 2019 2015 2020 $output = ''; … … 2278 2283 if ( $this->get_errors( $this->get_mysqldump_method() ) && file_exists( $sql_filename ) ) { 2279 2284 if ( file_exists( $sql_filename ) ) { 2280 unlink( $sql_filename );2285 wp_delete_file( $sql_filename ); 2281 2286 } 2282 2287 } … … 2285 2290 if ( 0 === filesize( $sql_filename ) ) { 2286 2291 if ( file_exists( $sql_filename ) ) { 2287 unlink( $sql_filename );2292 wp_delete_file( $sql_filename ); 2288 2293 } 2289 2294 } … … 2399 2404 foreach($tables as $table){ 2400 2405 if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) { 2401 $this->wp_db_backup_create_mysql_backup_new($table, $path_info['basedir'] . '/db-backup/' . $sql_filename );2406 $this->wp_db_backup_create_mysql_backup_new($table, $path_info['basedir'] . '/db-backup/' . $sql_filename ); 2402 2407 } 2403 2408 } … … 2405 2410 } 2406 2411 /* BEGIN : Prevent saving backup plugin settings in the database dump */ 2412 $options_backup = wpdbbkp_filter_unique_filenames( $options_backup ); 2407 2413 add_option( 'wp_db_backup_backups', $options_backup ); 2408 2414 add_option( 'wp_db_backup_options', $settings_backup ); … … 2484 2490 $index = $i; 2485 2491 if ( isset($options[ $index ]['dir']) && file_exists( $options[ $index ]['dir'] ) ) { 2486 unlink( $options[ $index ]['dir'] );2492 wp_delete_file( $options[ $index ]['dir'] ); 2487 2493 } 2488 2494 $file_sql = explode( '.', $options[ $index ]['dir'] ); 2489 2495 if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) { 2490 unlink( $file_sql[0] . '.sql' );2496 wp_delete_file( $file_sql[0] . '.sql' ); 2491 2497 } 2492 2498 } … … 2496 2502 $newoptions[] = $options[ $index ]; 2497 2503 } 2504 $newoptions = wpdbbkp_filter_unique_filenames( $newoptions ); 2498 2505 2499 2506 update_option( 'wp_db_backup_backups', $newoptions , false); … … 2502 2509 2503 2510 if ( file_exists( $path_info['basedir'] . '/db-backup/' . $sql_filename ) ) { 2504 unlink( $path_info['basedir'] . '/db-backup/' . $sql_filename );2511 wp_delete_file( $path_info['basedir'] . '/db-backup/' . $sql_filename ); 2505 2512 } 2506 2513 return $upload_path; … … 2585 2592 ); 2586 2593 if ( 1 !== (int) $wp_db_remove_local_backup ) { 2594 $options = wpdbbkp_filter_unique_filenames( $options ); 2587 2595 update_option( 'wp_db_backup_backups', $options , false); 2588 2596 } … … 2914 2922 $filename = $FileName . '.sql'; 2915 2923 $WPDBFileName = $FileName . '.zip'; 2916 @unlink($this->wp_db_backup_wp_config_path() . '/' . $filename);2917 @unlink($this->wp_db_backup_wp_config_path() . '/wp_installer.php');2924 wp_delete_file($this->wp_db_backup_wp_config_path() . '/' . $filename); 2925 wp_delete_file($this->wp_db_backup_wp_config_path() . '/wp_installer.php'); 2918 2926 @$filesize = filesize($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName); 2919 2927 … … 3152 3160 // If there are errors delete the backup file. 3153 3161 if ($this->get_errors($this->get_archive_method()) && file_exists($WPDBFileName)) 3154 unlink($WPDBFileName);3162 wp_delete_file($WPDBFileName); 3155 3163 3156 3164 // If the archive file still exists assume it's good … … 3249 3257 } 3250 3258 3251 private function wpdbbkp_filter_unique_filenames($backups) {3252 $unique_filenames = [];3253 $filtered_backups = [];3254 if(!empty($backups)){3255 foreach ($backups as $backup) {3256 if (isset($backup['filename']) && !in_array($backup['filename'], $unique_filenames)) {3257 $unique_filenames[] = $backup['filename'];3258 $filtered_backups[] = $backup;3259 }3260 }3261 }3262 return $filtered_backups;3263 }3264 3265 3259 } 3266 3260 -
wp-database-backup/tags/6.12/includes/admin/class-wpdbbkp-restore.php
r3124584 r3124649 165 165 } 166 166 167 @unlink($file_path);167 wp_delete_file($file_path); 168 168 } 169 169 -
wp-database-backup/tags/6.12/includes/admin/cron-create-full-backup.php
r3124590 r3124649 233 233 234 234 235 235 $options_backup = wpdbbkp_filter_unique_filenames($options_backup); 236 236 update_option('wp_db_backup_backups',$options_backup, false); 237 237 update_option('wp_db_backup_options',$settings_backup, false); … … 372 372 $filename = $FileName . '.sql'; 373 373 $path_info = wp_upload_dir(); 374 $filepath = $path_info['basedir'] . '/db-backup/' . $filename; 374 375 global $wpdb; 375 376 … … 395 396 $output = ''; 396 397 $sub_limit = 500; 398 $table = esc_sql($table); 397 399 //phpcs:ignore -- need to get all tables 398 $check_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM `{$table}`"));400 $check_count = $wpdb->get_var("SELECT COUNT(*) FROM `{$table}`"); 399 401 $check_count = intval($check_count); 400 402 … … 412 414 } else { 413 415 // phpcs:ignore -- need to get all data for selected table 414 $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM `{$table}`"), ARRAY_A);416 $result = $wpdb->get_results("SELECT * FROM `{$table}`", ARRAY_A); 415 417 $output .= wpdbbkp_create_sql_insert_statements($table, $result); 416 418 } … … 418 420 419 421 // phpcs:ignore -- Get table structure for backup 420 $row2 = $wpdb->get_row( $wpdb->prepare("SHOW CREATE TABLE `{$table}`"), ARRAY_N);422 $row2 = $wpdb->get_row("SHOW CREATE TABLE `{$table}`", ARRAY_N); 421 423 $output = "\n\n" . $row2[1] . ";\n\n" . $output; 422 424 … … 427 429 $use_php_methods = $total_size > 10 * $chunk_size; // Use PHP methods for large files 428 430 429 $append_content = function($new_content) use ($file name, $wp_filesystem, $use_php_methods) {431 $append_content = function($new_content) use ($filepath, $wp_filesystem, $use_php_methods) { 430 432 if ($use_php_methods) { 431 433 //phpcs:ignore -- Use PHP methods for large files 432 file_put_contents($file name, $new_content, FILE_APPEND);434 file_put_contents($filepath, $new_content, FILE_APPEND); 433 435 } else { 434 if (!$wp_filesystem->exists($file name)) {435 $wp_filesystem->put_contents($file name, $new_content, FS_CHMOD_FILE);436 if (!$wp_filesystem->exists($filepath)) { 437 $wp_filesystem->put_contents($filepath, $new_content, FS_CHMOD_FILE); 436 438 } else { 437 $current_contents = $wp_filesystem->get_contents($file name);439 $current_contents = $wp_filesystem->get_contents($filepath); 438 440 if ($current_contents === false) { 439 441 return false; 440 442 } 441 443 $updated_contents = $current_contents . $new_content; 442 $wp_filesystem->put_contents($file name, $updated_contents, FS_CHMOD_FILE);444 $wp_filesystem->put_contents($filepath, $updated_contents, FS_CHMOD_FILE); 443 445 } 444 446 } … … 574 576 if (get_option('wp_db_backup_backup_type') == 'Database' || get_option('wp_db_backup_backup_type') == 'complete') { 575 577 $filename = $FileName . '.sql'; 576 $zip->addFile($path_info['basedir'] . '/db-backup/' . $filename, $filename); 578 //phpcs:ignore -- check if file exists 579 if(file_exists( $path_info['basedir'] . '/db-backup/' . $filename )){ 580 $zip->addFile($path_info['basedir'] . '/db-backup/' . $filename, $filename); 581 } 577 582 } 578 583 $zip->close(); … … 814 819 $index = $i; 815 820 if ( isset($options[ $index ]['dir']) && file_exists( $options[ $index ]['dir'] ) ) { 816 unlink( $options[ $index ]['dir'] );821 wp_delete_file( $options[ $index ]['dir'] ); 817 822 } 818 823 $file_sql = explode( '.', $options[ $index ]['dir'] ); 819 824 if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) { 820 unlink( $file_sql[0] . '.sql' );825 wp_delete_file( $file_sql[0] . '.sql' ); 821 826 } 822 827 } … … 924 929 } 925 930 931 $new_options = wpdbbkp_filter_unique_filenames( $new_options ); 932 933 926 934 update_option( 'wp_db_backup_backups', $new_options, false ); 927 935 -
wp-database-backup/tags/6.12/includes/admin/mb-helper-functions.php
r3124584 r3124649 268 268 return $wp_filesystem->exists( $file ); 269 269 } 270 271 /** 272 * Filters an array of backup files to ensure only unique filenames are included. 273 * 274 * @param array $backups Array of backup files. 275 * @return array Filtered array of backup files with unique filenames. 276 */ 277 function wpdbbkp_filter_unique_filenames( $backups ) { 278 $unique_filenames = []; 279 $filtered_backups = []; 280 281 if ( ! empty( $backups ) ) { 282 foreach ( $backups as $backup ) { 283 if ( isset( $backup['filename'] ) && ! in_array( $backup['filename'], $unique_filenames ) ) { 284 $unique_filenames[] = $backup['filename']; 285 $filtered_backups[] = $backup; 286 } 287 } 288 } 289 290 return $filtered_backups; 291 } 292 -
wp-database-backup/tags/6.12/includes/class-wpdbfullbackuplog.php
r3124584 r3124649 39 39 } 40 40 41 $new_options = wpdbbkp_filter_unique_filenames( $new_options ); 42 41 43 // Update the options 42 44 update_option( 'wp_db_backup_backups', $new_options, false ); -
wp-database-backup/tags/6.12/readme.txt
r3124584 r3124649 203 203 == Upgrade Notice == 204 204 * Sanitised multiple inputs and escape output to remove further risk of cross site script security. 205 206 == Credits == 207 208 === This plugin uses the following third-party libraries: === 209 210 1. === Google APIs Client Library for PHP === 211 - Author: Google 212 - URL: https://github.com/googleapis/google-api-php-client 213 - License: Apache License, Version 2.0 (the "License") 214 - License URL: http://www.apache.org/licenses/LICENSE-2.0 215 216 2. === PHP Secure Communications Library === 217 - Author: phpseclib 218 - URL:https://github.com/phpseclib/phpseclib 219 - License: MIT License (or any other applicable license) 220 - License URL: http://opensource.org/licenses/MIT 221 222 3. === PhpConcept Library - Zip Module === 223 - Author: Vincent Blavet 224 - URL:http://www.phpconcept.net 225 - License: License GNU/LGPL 226 227 4. === phpFileTree === 228 - Author: Cory S.N. LaViska's 229 - URL: https://www.abeautifulsite.net/blog/2007/06/php-file-tree/
Note: See TracChangeset
for help on using the changeset viewer.