Plugin Directory

Changeset 2821526


Ignore:
Timestamp:
11/21/2022 12:55:33 PM (3 years ago)
Author:
ploudapp
Message:

New version published 1.0.4

Location:
pcloud-wp-backup
Files:
24 added
8 edited

Legend:

Unmodified
Added
Removed
  • pcloud-wp-backup/trunk/classes/class-wp2pclouddbbackup.php

    r2732482 r2821526  
    7272            $dump->start( $this->save_file );
    7373
    74             WP2pCloudDebugger::log( 'db_backup->start() - Success!' );
     74            WP2pCloudDebugger::log( 'db_backup->start() - process succeeded!' );
    7575            WP2pCloudLogger::info( "<span class='pcl_transl' data-i10nk='db_backup_finished'>Database Backup Finished</span>" );
    7676
     
    8383
    8484        return $this->save_file;
    85 
    8685    }
    8786}
  • pcloud-wp-backup/trunk/classes/class-wp2pclouddebugger.php

    r2781798 r2821526  
    3535        $log = WP2pCloudFuncs::get_storred_val( PCLOUD_DBG_LOG );
    3636
     37        if ( strlen( $log ) > 50000 ) {
     38            $log = substr( $log, 20000 );
     39            WP2pCloudFuncs::set_storred_val( PCLOUD_DBG_LOG, $log );
     40        }
     41
    3742        if ( $as_json ) {
    3843            return wp_json_encode( array( 'log' => $log ) );
     
    6974
    7075        WP2pCloudFuncs::set_storred_val( PCLOUD_DBG_LOG, $current_data );
    71 
    7276    }
    7377}
  • pcloud-wp-backup/trunk/classes/class-wp2pcloudfilebackup.php

    r2781798 r2821526  
    145145            WP2pCloudDebugger::log( 'Start creating ZIP archive!' );
    146146
    147             for ( $try = 0; $try < 2; $try++ ) {
     147            for ( $try = 0; $try < 5; $try++ ) {
    148148
    149149                WP2pCloudDebugger::log( 'Attempt [ ' . ( $try + 1 ) . ' ] to create the ZIP archive!' );
     
    152152                if ( $zipping_successfull ) {
    153153                    break;
     154                } else {
     155
     156                    $operation             = WP2pCloudFuncs::get_operation();
     157                    $operation['failures'] = 0;
     158                    WP2pCloudFuncs::set_operation( $operation );
     159
     160                    WP2pCloudFuncs::add_item_for_async_update( 'failures', 0 );
     161
     162                    WP2pCloudDebugger::log( 'Closing ZIP archive with attempt: ' . ( $try + 1 ) . ' failed, retrying!' );
     163
     164                    $files = self::find_all_files( $rootdir );
    154165                }
    155166            }
     
    320331        $zip->setArchiveComment( 'Wordpress2pCloud-' . gmdate( 'd.m.Y H:i:s' ) );
    321332
     333        $num_files = count( $files );
     334
    322335        foreach ( $files as $file ) {
    323336            if ( file_exists( $file ) && is_readable( $file ) ) {
     
    326339        }
    327340
    328         WP2pCloudDebugger::log( 'ZIP entries added [ ' . count( $files ) . ' ] ' );
     341        if ( $num_files > 500000 ) {
     342            WP2pCloudFuncs::set_storred_val( PCLOUD_MAX_NUM_FAILURES_NAME, 15000 );
     343        } elseif ( $num_files > 100000 ) {
     344            WP2pCloudFuncs::set_storred_val( PCLOUD_MAX_NUM_FAILURES_NAME, 6000 );
     345        } elseif ( $num_files > 40000 ) {
     346            WP2pCloudFuncs::set_storred_val( PCLOUD_MAX_NUM_FAILURES_NAME, 2000 );
     347        } elseif ( $num_files > 10000 ) {
     348            WP2pCloudFuncs::set_storred_val( PCLOUD_MAX_NUM_FAILURES_NAME, 500 );
     349        }
     350
     351        WP2pCloudDebugger::log( 'ZIP entries added [ ' . count( $files ) . ' ]' );
    329352
    330353        if ( ! empty( $this->sql_backup_file ) ) {
     
    335358        }
    336359
    337         WP2pCloudDebugger::log( 'ZIP archive - filling-up and closing ' );
     360        WP2pCloudDebugger::log( 'ZIP archive - filling-up and closing' );
    338361
    339362        if ( $zip->close() ) {
     
    370393        $response = new stdClass();
    371394
    372         $api_response = wp_remote_get( $this->apiep . '/createfolder?path=' . $dir_name . '&name=' . trim( $dir_name, '/' ) . '&access_token=' . $this->authkey );
    373         if ( is_array( $api_response ) && ! is_wp_error( $api_response ) ) {
    374             $response_raw = wp_remote_retrieve_body( $api_response );
    375             if ( is_string( $response_raw ) && ! is_wp_error( $response_raw ) ) {
    376                 $response_json = json_decode( $response_raw );
    377                 if ( ! is_bool( $response_json ) ) {
    378                     $response = $response_json;
    379                     WP2pCloudDebugger::log( 'make_directory() - OK' );
     395        for ( $i = 1; $i < 4; $i++ ) {
     396
     397            $api_response = wp_remote_get( $this->apiep . '/createfolder?path=' . $dir_name . '&name=' . trim( $dir_name, '/' ) . '&access_token=' . $this->authkey );
     398            if ( is_array( $api_response ) && ! is_wp_error( $api_response ) ) {
     399                $response_raw = wp_remote_retrieve_body( $api_response );
     400                if ( is_string( $response_raw ) && ! is_wp_error( $response_raw ) ) {
     401                    $response_json = json_decode( $response_raw );
     402                    if ( ! is_bool( $response_json ) ) {
     403                        $response = $response_json;
     404                        WP2pCloudDebugger::log( 'make_directory() - OK' );
     405                        break;
     406                    } else {
     407                        WP2pCloudDebugger::log( 'make_directory() - failed to convert the response JSON to object! Will retry!' );
     408                    }
    380409                } else {
    381                     WP2pCloudDebugger::log( 'make_directory() - failed to convert the response JSON to object!' );
     410                    WP2pCloudDebugger::log( 'make_directory() - no response body detected! Will retry!' );
    382411                }
    383412            } else {
    384                 WP2pCloudDebugger::log( 'make_directory() - no response body detected!' );
    385             }
    386         } else {
    387             $error = '';
    388             if ( is_wp_error( $api_response ) ) {
    389                 $error = $api_response->get_error_message();
    390             }
    391             WP2pCloudDebugger::log( 'make_directory() - api call failed ! [ ' . $error . ' ]' );
     413                $error = '';
     414                if ( is_wp_error( $api_response ) ) {
     415                    $error = $api_response->get_error_message();
     416                }
     417                WP2pCloudDebugger::log( 'make_directory() - api call failed ! [ ' . $error . ' ] Will retry!' );
     418            }
     419
     420            sleep( 5 * $i );
    392421        }
    393422
     
    405434        $response = new stdClass();
    406435
    407         $api_response = wp_remote_get( $this->apiep . '/listfolder?path=/' . PCLOUD_BACKUP_DIR . '&access_token=' . $this->authkey );
    408         if ( is_array( $api_response ) && ! is_wp_error( $api_response ) ) {
    409             $response_raw = wp_remote_retrieve_body( $api_response );
    410             if ( is_string( $response_raw ) && ! is_wp_error( $response_raw ) ) {
    411                 $response_json = json_decode( $response_raw );
    412                 if ( ! is_bool( $response_json ) ) {
    413                     $response = $response_json;
     436        $folder_id = 0;
     437        for ( $i = 1; $i < 4; $i++ ) {
     438
     439            $api_response = wp_remote_get( $this->apiep . '/listfolder?path=/' . PCLOUD_BACKUP_DIR . '&access_token=' . $this->authkey );
     440            if ( is_array( $api_response ) && ! is_wp_error( $api_response ) ) {
     441                $response_raw = wp_remote_retrieve_body( $api_response );
     442                if ( is_string( $response_raw ) && ! is_wp_error( $response_raw ) ) {
     443                    $response_json = json_decode( $response_raw );
     444                    if ( ! is_bool( $response_json ) ) {
     445                        $response = $response_json;
     446                    } else {
     447                        WP2pCloudDebugger::log( 'get_upload_dir_id() - failed to convert the response JSON to object!' );
     448                    }
    414449                } else {
    415                     WP2pCloudDebugger::log( 'get_upload_dir_id() - failed to convert the response JSON to object!' );
     450                    WP2pCloudDebugger::log( 'get_upload_dir_id() - no response body detected!' );
    416451                }
    417452            } else {
    418                 WP2pCloudDebugger::log( 'get_upload_dir_id() - no response body detected!' );
    419             }
    420         } else {
    421 
    422             if ( is_wp_error( $api_response ) ) {
    423                 $error = $api_response->get_error_message();
    424             }
     453
     454                if ( is_wp_error( $api_response ) ) {
     455                    $error .= $api_response->get_error_message();
     456                }
     457                WP2pCloudDebugger::log( 'get_upload_dir_id() - api call failed ! [ ' . $error . ' ]' );
     458            }
     459
     460            if ( ! property_exists( $response, 'result' ) && 2005 === $response->result ) {
     461
     462                $folders = explode( '/', PCLOUD_BACKUP_DIR );
     463                WP2pCloudLogger::info( "<span class='pcl_transl' data-i10nk='backup_in_fld'>Backup will be in folder:</span> " . PCLOUD_BACKUP_DIR );
     464
     465                self::make_directory( '/' . $folders[0] );
     466                $res       = self::make_directory( '/' . $folders[0] . '/' . $folders[1] );
     467                $folder_id = $res->metadata->folderid;
     468
     469            } else {
     470
     471                if ( ! property_exists( $response, 'metadata' ) ) {
     472                    WP2pCloudDebugger::log( 'get_upload_dir_id() - response from the API does not contain the needed info!' );
     473                } else {
     474                    $folder_id = $response->metadata->folderid;
     475                }
     476            }
     477
     478            if ( 0 < $folder_id ) {
     479                break;
     480            }
     481
     482            sleep( 5 * $i );
     483        }
     484
     485        if ( 0 === $folder_id ) {
     486
    425487            WP2pCloudDebugger::log( 'get_upload_dir_id() - api call failed ! [ ' . $error . ' ]' );
    426488
    427489            WP2pCloudLogger::info( "<span class='pcl_transl' data-i10nk='invalid_resp_from_server'>Invalid response from the server:</span> " . $error . "\n" );
     490            WP2pCloudFuncs::set_operation( array() );
    428491            die();
    429         }
    430 
    431         if ( ! property_exists( $response, 'result' ) && 2005 === $response->result ) {
    432 
    433             $folders = explode( '/', PCLOUD_BACKUP_DIR );
    434             WP2pCloudLogger::info( "<span class='pcl_transl' data-i10nk='backup_in_fld'>Backup will be in folder:</span> " . PCLOUD_BACKUP_DIR );
    435 
    436             self::make_directory( '/' . $folders[0] );
    437             $res       = self::make_directory( '/' . $folders[0] . '/' . $folders[1] );
    438             $folder_id = $res->metadata->folderid;
    439 
    440         } else {
    441 
    442             if ( ! property_exists( $response, 'metadata' ) ) {
    443                 WP2pCloudDebugger::log( 'get_upload_dir_id() - response from the API does not contain the needed info!' );
    444                 WP2pCloudLogger::info( "<span class='pcl_transl' data-i10nk='invalid_resp_srv'>Invalid response from the server:</span> " . $response );
    445                 die();
    446             } else {
    447                 $folder_id = $response->metadata->folderid;
    448             }
    449492        }
    450493
     
    652695        $response = new stdClass();
    653696
    654         $api_response = wp_remote_get( $this->apiep . '/upload_create?access_token=' . $this->authkey );
    655         if ( is_array( $api_response ) && ! is_wp_error( $api_response ) ) {
    656             $response_raw = wp_remote_retrieve_body( $api_response );
    657             if ( is_string( $response_raw ) && ! is_wp_error( $response_raw ) ) {
    658                 $response_json = json_decode( $response_raw );
    659                 if ( ! is_bool( $response_json ) ) {
    660                     $response = $response_json;
    661                     WP2pCloudDebugger::log( 'create_upload() - OK' );
     697        for ( $i = 1; $i < 4; $i++ ) {
     698
     699            $api_response = wp_remote_get( $this->apiep . '/upload_create?access_token=' . $this->authkey );
     700            if ( is_array( $api_response ) && ! is_wp_error( $api_response ) ) {
     701                $response_raw = wp_remote_retrieve_body( $api_response );
     702                if ( is_string( $response_raw ) && ! is_wp_error( $response_raw ) ) {
     703                    $response_json = json_decode( $response_raw );
     704                    if ( ! is_bool( $response_json ) ) {
     705                        $response = $response_json;
     706                        WP2pCloudDebugger::log( 'create_upload() - OK' );
     707                        break;
     708                    } else {
     709                        WP2pCloudDebugger::log( 'create_upload() - failed to convert the response JSON to object! Will retry!' );
     710                    }
    662711                } else {
    663                     WP2pCloudDebugger::log( 'create_upload() - failed to convert the response JSON to object!' );
     712                    WP2pCloudDebugger::log( 'create_upload() - no response body detected! Will retry!' );
    664713                }
    665714            } else {
    666                 WP2pCloudDebugger::log( 'create_upload() - no response body detected!' );
    667             }
    668         } else {
    669             $error = '';
    670             if ( is_wp_error( $api_response ) ) {
    671                 $error = $api_response->get_error_message();
    672             }
    673             WP2pCloudDebugger::log( 'create_upload() - api call failed ! [ ' . $error . ' ]' );
     715                $error = '';
     716                if ( is_wp_error( $api_response ) ) {
     717                    $error = $api_response->get_error_message();
     718                }
     719                WP2pCloudDebugger::log( 'create_upload() - api call failed ! [ ' . $error . ' ]! Will retry!' );
     720            }
     721
     722            sleep( 5 * $i );
    674723        }
    675724
  • pcloud-wp-backup/trunk/classes/class-wp2pcloudfilerestore.php

    r2781798 r2821526  
    3232        if ( ! is_dir( $this->restore_path ) ) {
    3333            WP2pCloudLogger::info( "<span class='pcl_transl' data-i10nk='err_temp_folder_fail2mk'>ERROR: Temporary folder can not be created!</span> [" . $this->restore_path . ']' );
     34            WP2pCloudDebugger::log( 'Failed to create Temporary folder!' );
     35            WP2pCloudFuncs::set_operation( array() );
    3436            die();
    3537        }
  • pcloud-wp-backup/trunk/classes/class-wp2pcloudfuncs.php

    r2781798 r2821526  
    150150        }
    151151
     152        $waiting_async_items = self::get_storred_val( PCLOUD_ASYNC_UPDATE_VAL );
     153        if ( ! empty( $waiting_async_items ) ) {
     154
     155            $items_to_update = json_decode( $waiting_async_items, true );
     156            if ( is_array( $items_to_update ) ) {
     157                foreach ( $items_to_update as $k => $v ) {
     158                    $operation_data[ $k ] = $v;
     159                }
     160            }
     161
     162            self::set_storred_val( PCLOUD_ASYNC_UPDATE_VAL, '' ); // Maximum number of failures.
     163        }
     164
    152165        $json_data = wp_json_encode( $operation_data );
    153166
    154167        self::set_storred_val( PCLOUD_OPERATION, $json_data );
     168    }
     169
     170    /**
     171     * Add item for async update as a setting.
     172     *
     173     * @param string $key Key of the setting.
     174     * @param mixed  $value The value of the setting.
     175     *
     176     * @return void
     177     */
     178    public static function add_item_for_async_update( $key, $value ) {
     179
     180        if ( empty( $key ) ) {
     181            return;
     182        }
     183
     184        $items_to_update = array();
     185
     186        $waiting_items = self::get_storred_val( PCLOUD_ASYNC_UPDATE_VAL );
     187        if ( ! empty( $waiting_items ) ) {
     188            $items_to_update = json_decode( $waiting_items, true );
     189        }
     190
     191        $items_to_update[ $key ] = $value;
     192
     193        $json_data = wp_json_encode( $items_to_update );
     194
     195        self::set_storred_val( PCLOUD_ASYNC_UPDATE_VAL, $json_data );
    155196    }
    156197
  • pcloud-wp-backup/trunk/pcloud-wp-backup.php

    r2781798 r2821526  
    1010 * Summary: pCloud WP Backup plugin
    1111 * Description: pCloud WP Backup has been created to make instant backups of your blog and its data, regularly.
    12  * Version: 1.0.3
     12 * Version: 1.0.4
    1313 * Author: pCloud
    1414 * URI: https://www.pcloud.com
     
    5656    define( 'PCLOUD_USEDQUOTA', 'wp2pcl_usedquota' );
    5757}
    58 if ( ! defined( 'PCLOUD_MAX_NUM_FAILURES' ) ) {
    59     define( 'PCLOUD_MAX_NUM_FAILURES', 120 );
     58if ( ! defined( 'PCLOUD_MAX_NUM_FAILURES_NAME' ) ) {
     59    define( 'PCLOUD_MAX_NUM_FAILURES_NAME', 'wp2pcl_max_num_failures' );
     60}
     61if ( ! defined( 'PCLOUD_ASYNC_UPDATE_VAL' ) ) {
     62    define( 'PCLOUD_ASYNC_UPDATE_VAL', 'wp2pcl_async_upd_item' );
    6063}
    6164if ( ! defined( 'PCLOUD_OAUTH_CLIENT_ID' ) ) {
     
    7780 */
    7881function pcl_wb_bkup_timeout_extend() {
    79     return 120;
     82    return 180;
    8083}
    8184
     
    99102require_once $plugin_path . '/class-wp2pcloudfilerestore.php';
    100103require_once $plugin_path . '/class-wp2pclouddebugger.php';
     104
     105$num_failures = WP2pCloudFuncs::get_storred_val( PCLOUD_MAX_NUM_FAILURES_NAME );
     106if ( empty( $num_failures ) ) {
     107    WP2pCloudFuncs::set_storred_val( PCLOUD_MAX_NUM_FAILURES_NAME, 120 );
     108}
    101109
    102110/**
     
    337345        $result['memlimitini'] = ini_get( 'memory_limit' );
    338346        $result['failures']    = isset( $operation['failures'] ) ? $operation['failures'] : 0;
     347        $result['maxfailures'] = WP2pCloudFuncs::get_storred_val( PCLOUD_MAX_NUM_FAILURES_NAME );
    339348
    340349    } elseif ( 'check_can_restore' === $m ) {
     
    430439                WP2pCloudFuncs::set_operation( $operation );
    431440
    432                 if ( $operation['failures'] > PCLOUD_MAX_NUM_FAILURES ) {
    433 
    434                     WP2pCloudDebugger::log( '== ERROR == Too many failures ( ' . $operation['failures'] . '/ ' . PCLOUD_MAX_NUM_FAILURES . ' ), leaving.. !' );
     441                $max_num_failures = WP2pCloudFuncs::get_storred_val( PCLOUD_MAX_NUM_FAILURES_NAME );
     442
     443                if ( $operation['failures'] > $max_num_failures ) {
     444
     445                    WP2pCloudDebugger::log( '== ERROR == Too many failures ( ' . $operation['failures'] . ' / ' . $max_num_failures . ' ), leaving.. !' );
    435446
    436447                    WP2pCloudLogger::info( "<span class='pcl_transl' data-i10nk='too_many_failures'>ERROR: Too many failures, try to disable/enable the plugin !</span>" );
     
    514525                    WP2pCloudFuncs::set_operation( $operation );
    515526
    516                     if ( $operation['failures'] > PCLOUD_MAX_NUM_FAILURES ) {
     527                    $num_failures = WP2pCloudFuncs::get_storred_val( PCLOUD_MAX_NUM_FAILURES_NAME );
     528
     529                    if ( $operation['failures'] > $num_failures ) {
    517530
    518531                        WP2pCloudLogger::info( "<span class='pcl_transl' data-i10nk='too_many_failures'>ERROR: Too many failures, try to disable/enable the plugin !</span>" );
     
    729742    if ( $lastbackupdt_tm > 0 ) {
    730743
     744        if ( '2_minute' === $freq ) {
     745            if ( $lastbackupdt_tm > ( time() - 120 ) ) {
     746                $rejected = true;
     747            }
     748        }
    731749        if ( '1_hour' === $freq ) {
    732750            if ( $lastbackupdt_tm > ( time() - 3600 ) ) {
     
    885903        'cron_schedules',
    886904        function ( $schedules ) {
    887             $schedules['10_sec']  = array(
     905            $schedules['10_sec']   = array(
    888906                'interval' => 10,
    889907                'display'  => __( '10 seconds' ),
    890908            );
    891             $schedules['1_hour']  = array(
     909            $schedules['2_minute'] = array(
     910                'interval' => 120,
     911                'display'  => __( '2 minute' ),
     912            );
     913            $schedules['1_hour']   = array(
    892914                'interval' => 3600,
    893915                'display'  => __( '1 hour' ),
    894916            );
    895             $schedules['4_hours'] = array(
     917            $schedules['4_hours']  = array(
    896918                'interval' => 3600 * 4,
    897919                'display'  => __( '4 hours' ),
     
    921943    delete_option( PCLOUD_HAS_ACTIVITY );
    922944    delete_option( PCLOUD_LAST_BACKUPDT );
     945    delete_option( PCLOUD_MAX_NUM_FAILURES_NAME );
    923946    delete_option( PCLOUD_QUOTA );
    924947    delete_option( PCLOUD_USEDQUOTA );
     
    939962
    940963    $new_schedules = array(
    941         '10_sec'  => array(
     964        '10_sec'   => array(
    942965            'interval' => 10,
    943966            'display'  => __( '10 seconds' ),
    944967        ),
    945         '1_hour'  => array(
     968        '2_minute' => array(
     969            'interval' => 120,
     970            'display'  => __( '2 minute' ),
     971        ),
     972        '1_hour'   => array(
    946973            'interval' => 3600,
    947974            'display'  => __( '1 hour' ),
    948975        ),
    949         '4_hours' => array(
     976        '4_hours'  => array(
    950977            'interval' => 3600 * 4,
    951978            'display'  => __( '4 hours' ),
    952979        ),
    953         'daily'   => array(
     980        'daily'    => array(
    954981            'interval' => 86400,
    955982            'display'  => __( 'Daily' ),
    956983        ),
    957         'weekly'  => array(
     984        'weekly'   => array(
    958985            'interval' => 604800,
    959986            'display'  => __( 'Weekly' ),
    960987        ),
    961         'monthly' => array(
     988        'monthly'  => array(
    962989            'interval' => 2592000,
    963990            'display'  => __( 'Monthly' ),
  • pcloud-wp-backup/trunk/readme.txt

    r2781798 r2821526  
    33Tags: backup, pCloud
    44Requires at least: 5.0
    5 Tested up to: 6.0.2
     5Tested up to: 6.1.1
    66Requires PHP: 5.6
    7 Stable tag: 1.0.3
     7Stable tag: 1.0.4
    88License: GPLv3 or later
    99
     
    5858
    5959== Changelog ==
     60= 1.0.4 =
     61* Increased number of failures for blogs with higher number of assets.
     62* The plugin will retry more than once in case of bad response from the pCloud server.
     63
    6064= 1.0.3 =
    61 * Added an option to choose whether to include a database snapshot in the backup archive or not. 
     65* Added an option to choose whether to include a database snapshot in the backup archive or not.
    6266* Much more debugging is added in order to determine the Zipping process issues.
    6367
  • pcloud-wp-backup/trunk/views/wp2pcl-config.php

    r2781798 r2821526  
    1818if ( PCLOUD_DEBUG ) {
    1919    $freg = array(
    20         't'       => 'Test',
    21         '1_hour'  => '1 Hour',
    22         '4_hours' => '4 Hours',
    23         'daily'   => '1 day',
    24         'weekly'  => '1 week',
    25         'monthly' => '1 month',
     20        't'        => 'Test',
     21        '2_minute' => '2 Minute',
     22        '1_hour'   => '1 Hour',
     23        '4_hours'  => '4 Hours',
     24        'daily'    => '1 day',
     25        'weekly'   => '1 week',
     26        'monthly'  => '1 month',
    2627    );
    2728} else {
Note: See TracChangeset for help on using the changeset viewer.