Plugin Directory

Changeset 1709427


Ignore:
Timestamp:
08/07/2017 07:55:26 AM (9 years ago)
Author:
themespond
Message:
  • Rollback when restore or backup is not completed
Location:
tp-backup-automator
Files:
40 added
13 edited

Legend:

Unmodified
Added
Removed
  • tp-backup-automator/trunk/assets/js/admin.js

    r1705516 r1709427  
    126126            var trackBackup = _.bind(this.track, this);
    127127            var progress = _.bind(this.initProgressBar, this);
    128             var done = _.bind(this.done, this);
     128
    129129            Backbone.ajax({
    130130                url: ajaxurl,
     
    135135                success: function (response) {
    136136
    137 
    138 
    139                     if (response.total_count && response.total_count > response.index) {
    140 
    141                         var progressBar = progress.call(this);
    142                         progressBar.setTotal(response.total_count);
    143                         progressBar.update(response.index, response.data);
    144                         trackBackup.call(this, response.index);
    145 
    146                     } else if (response.total_count && response.total_count == response.index) {
    147 
    148                         var progressBar = progress.call(this);
    149                         progressBar.setTotal(response.total_count);
    150                         progressBar.update(response.index, response.data);
    151 
    152                         done.call(this);
    153                     }
     137                    if (_.isObject(response)) {
     138                        if (response.continue) {
     139                            var progressBar = progress.call(this);
     140                            progressBar.setTotal(response.total_count);
     141                            progressBar.update(response.index, response.data);
     142                            trackBackup.call(this, response.index);
     143                        } else {
     144                            if (response.success) {
     145                                progressBar.remove();
     146                                new ShowAlert(tpba_var.done, response.data, 'success');
     147                            } else {
     148                                new ShowAlert(tpba_var.done, response.data, 'warning');
     149                            }
     150                        }
     151                    }
     152
    154153                }
    155154            });
     
    160159            var progressBar = this.progressBar;
    161160            var trackBackup = _.bind(this.track, this);
    162             var done = _.bind(this.done, this);
    163161
    164162            Backbone.ajax({
     
    174172                        var response = data.responseJSON;
    175173
    176                         if (response.index < progressBar.total) {
     174                        if (response.continue) {
    177175                            progressBar.update(response.index, response.data);
    178176                            trackBackup.call(this);
    179                         } else if (response.index == progressBar.total) {
    180                             progressBar.update(response.index, response.data);
     177                        } else {
    181178                            progressBar.remove();
    182                             done.call(this);
     179                            if (response.success) {
     180                                new ShowAlert(tpba_var.done, response.data, 'success');
     181                            } else {
     182                                new ShowAlert(tpba_var.warning, response.data, 'warning');
     183                            }
    183184                        }
    184185
    185                     } else {
     186                    } else if (data.responseText != '' && data.responseText != 0) {
    186187                        new ShowAlert(tpba_var.warning, data.responseText, 'error');
    187188                    }
     
    190191            });
    191192
    192         },
    193         done: function () {
    194 
    195             var progressBar = this.progressBar;
    196 
    197             Backbone.ajax({
    198                 url: ajaxurl,
    199                 type: 'POST',
    200                 data: {
    201                     'action': 'tpba_alldone'
    202                 },
    203                 success: function (res) {
    204                     new ShowAlert(tpba_var.done, progressBar.total + ' ' + tpba_var.file_backup_done, 'success');
    205                 }
    206             });
    207193        }
    208194    });
     
    215201        initialize: function () {
    216202            this.checkCron();
    217 
    218203        },
    219204        initProgressBar: function () {
     
    272257        checkCron: function () {
    273258
    274             var tracResktore = _.bind(this.track, this);
     259            var trackRestore = _.bind(this.track, this);
    275260            var progress = _.bind(this.initProgressBar, this);
    276261
     
    283268                success: function (response) {
    284269
    285                     if (response.total_count && response.total_count > response.index) {
    286                         $('.js-restore').addClass('disabled').attr('disabled', '');
    287                         var progressBar = progress.call(this);
    288                         progressBar.setTotal(response.total_count);
    289                         progressBar.update(response.index, response.data);
    290                         tracResktore.call(this, response.index);
    291 
    292 
    293                     } else if (response.total_count && response.total_count == response.index) {
    294                         $('.js-restore').addClass('disabled').attr('disabled', '');
    295                         var progressBar = progress.call(this);
    296                         progressBar.setTotal(response.total_count);
    297                         progressBar.update(response.index, response.data);
    298                     }
    299                 }
    300             });
    301 
    302         },
    303         track: function () {
    304 
    305             var progressBar = this.progressBar;
    306             var trackBackup = _.bind(this.track, this);
    307             var done = _.bind(this.done, this);
    308 
    309             Backbone.ajax({
    310                 url: ajaxurl,
    311                 type: 'POST',
    312                 data: {
    313                     action: 'tpba_restore_track'
    314                 },
    315                 complete: function (data, status) {
    316 
    317                     if (data.hasOwnProperty('responseJSON')) {
    318 
    319                         var response = data.responseJSON;
    320 
    321                         if (response.index >= 0) {
    322                             if (response.index < progressBar.total) {
    323 
    324                                 progressBar.update(response.index, response.data);
    325                                 trackBackup.call(this);
    326 
    327                             } else if (response.index == progressBar.total) {
    328 
    329                                 progressBar.update(response.index, response.data);
     270                    if (_.isObject(response)) {
     271                        if (response.continue) {
     272
     273                            $('.js-restore').addClass('disabled').attr('disabled', '');
     274                            var progressBar = progress.call(this);
     275                            progressBar.setTotal(response.total_count);
     276                            progressBar.update(response.index, response.data);
     277                            trackRestore.call(this, response.index);
     278
     279                        } else {
     280
     281                            $('.js-restore').removeClass('disabled').removeAttr('disabled');
     282
     283                            if (response.success) {
    330284                                progressBar.remove();
    331 
    332                                 done.call(this);
    333                                 new ShowAlert(tpba_var.done, progressBar.total + ' ' + tpba_var.file_restore_done, 'success');
     285                                new ShowAlert(tpba_var.done, response.data, 'success');
     286                            } else {
     287                                new ShowAlert(tpba_var.warning, response.data, 'warning');
    334288                            }
    335289                        }
    336290                    }
    337                 }
    338             });
    339         },
    340         done: function () {
    341 
    342             Backbone.ajax({
    343                 url: ajaxurl,
    344                 type: 'POST',
    345                 data: {
    346                     'action': 'tpba_alldone'
    347                 },
    348                 success: function (res) {
    349 
     291
     292                }
     293            });
     294
     295        },
     296        track: function () {
     297
     298            var progressBar = this.progressBar;
     299            var trackRestore = _.bind(this.track, this);
     300
     301            Backbone.ajax({
     302                url: ajaxurl,
     303                type: 'POST',
     304                data: {
     305                    action: 'tpba_restore_track'
     306                },
     307                complete: function (data, status) {
     308
     309                    if (data.hasOwnProperty('responseJSON')) {
     310
     311                        var response = data.responseJSON;
     312
     313                        if (response.continue) {
     314                            progressBar.update(response.index, response.data);
     315                            trackRestore.call(this);
     316                        } else {
     317                            if (response.success) {
     318                                progressBar.remove();
     319                                new ShowAlert(tpba_var.done, response.data, 'success');
     320                            } else {
     321                                new ShowAlert(tpba_var.done, response.data, 'warning');
     322                            }
     323                        }
     324
     325                    }
    350326                }
    351327            });
     
    362338
    363339    $('.tpba_abort').on('click', function (e) {
    364        
    365           Backbone.ajax({
    366                 url: ajaxurl,
    367                 type: 'POST',
    368                 data: {
    369                     'action': 'tpba_abort'
    370                 },
    371                 success: function (res) {
    372                     console.log(res);
    373                 }
    374             });
    375        
     340
     341        Backbone.ajax({
     342            url: ajaxurl,
     343            type: 'POST',
     344            data: {
     345                'action': 'tpba_abort'
     346            },
     347            success: function (res) {
     348                console.log(res);
     349            }
     350        });
     351
    376352        e.preventDefault();
    377353    });
  • tp-backup-automator/trunk/includes/class-tpba-ajax.php

    r1705516 r1709427  
    1616            'restore_check_cron' => false,
    1717            'restore_track' => false,
    18             'alldone' => false,
    1918            'register_token' => false,
    2019            'validate_token' => false
     
    5756
    5857    public static function backup_check_cron() {
    59         $message = get_option( 'tpba_cron_message' );
    60         $data = get_option( 'tpba_backup_current' );
    61 
    62 
    63         if ( !empty( $message ) && is_array( $message ) ) {
    64             wp_send_json( array(
    65                 'index' => $message['index'],
    66                 'data' => $message['data'],
    67                 'total_count' => $data['total_count']
    68             ) );
    69         }
    70 
    71 
    72         wp_send_json( array(
    73             'index' => 0,
    74             'data' => '',
    75             'total_count' => 0
    76         ) );
     58
     59        $result = get_option( 'tpba_cron_result' );
     60        $is_cron = get_transient( 'doing_cron' );
     61
     62        if ( !empty( $result ) && is_array( $result ) && !$is_cron ) {
     63            $results = get_option( 'tpba_cron_result' );
     64            $result['continue'] = false;
     65            delete_option( 'tpba_cron_result' );
     66            wp_send_json( $results );
     67        } else if ( $is_cron ) {
     68            $message = get_option( 'tpba_cron_message' );
     69            $data = get_option( 'tpba_backup_current' );
     70
     71            if ( !empty( $message ) && is_array( $message ) ) {
     72                wp_send_json( array(
     73                    'index' => $message['index'],
     74                    'data' => $message['data'],
     75                    'total_count' => $data['total_count'],
     76                    'continue' => true
     77                ) );
     78            }
     79        }
     80
     81        die();
    7782    }
    7883
     
    8287     */
    8388    public static function backup_track() {
     89
    8490        sleep( 1 );
    8591
    86         $message = get_option( 'tpba_cron_message' );
    87 
    88         if ( !empty( $message ) && is_array( $message ) ) {
    89             wp_send_json( array(
    90                 'index' => $message['index'],
    91                 'data' => $message['data'],
    92                 'wp_get_schedule' => wp_get_schedule( 'tpba_cron_backup' ),
    93                 'wp_next_scheduled' => wp_next_scheduled( 'tpba_cron_backup' ),
    94                 '_get_cron_lock' => function_exists( '_get_cron_lock' ) ? _get_cron_lock() : -1
    95             ) );
    96         }
    97 
     92
     93        $result = get_option( 'tpba_cron_result' );
     94       
     95        if ( !empty( $result ) && is_array( $result ) ) {
     96            $result['continue'] = false;
     97            delete_option( 'tpba_cron_result' );
     98            delete_option( 'tpba_cron_message' );
     99            wp_send_json( $result );
     100        } else if ( get_transient( 'doing_cron' ) ) {
     101            $message = get_option( 'tpba_cron_message' );
     102            if ( !empty( $message ) && is_array( $message ) ) {
     103                wp_send_json( array(
     104                    'index' => $message['index'],
     105                    'data' => $message['data'],
     106                    'continue' => true
     107                ) );
     108            }
     109        }
     110       
    98111        wp_send_json( array(
    99             'index' => 0,
    100             'data' => esc_html__( 'Error when backup', 'tp-backup-automator' )
     112            'success' => false,
     113            'data' => esc_html__( 'Error when backup', 'tp-backup-automator' ),
     114            'continue' => false
    101115        ) );
    102116    }
     
    128142
    129143    public static function restore_check_cron() {
    130         $message = get_option( 'tpba_cron_message' );
    131         $data = get_option( 'tpba_restore_current' );
    132 
    133         if ( !empty( $message ) && is_array( $message ) ) {
    134             wp_send_json( array(
    135                 'index' => $message['index'],
    136                 'data' => $message['data'],
    137                 'total_count' => $data['total_count']
    138             ) );
    139         }
    140 
    141 
    142         wp_send_json( array(
    143             'index' => 0,
    144             'data' => '',
    145             'total_count' => 0
    146         ) );
     144
     145        $result = get_option( 'tpba_cron_result' );
     146
     147        if ( !empty( $result ) && is_array( $result ) ) {
     148           
     149            $result['continue'] = false;
     150            delete_option( 'tpba_cron_result' );
     151            wp_send_json( $result );
     152           
     153        } else if ( get_transient( 'doing_cron' ) ) {
     154           
     155            $message = get_option( 'tpba_cron_message' );
     156            $data = get_option( 'tpba_restore_current' );
     157
     158            if ( !empty( $message ) && is_array( $message ) ) {
     159                wp_send_json( array(
     160                    'index' => $message['index'],
     161                    'data' => $message['data'],
     162                    'total_count' => $data['total_count'],
     163                    'continue'=>true
     164                ) );
     165            }
     166        }
     167
     168        die();
    147169    }
    148170
     
    152174     */
    153175    public static function restore_track() {
     176       
    154177        sleep( 1 );
    155         $message = get_option( 'tpba_cron_message' );
    156         if ( !empty( $message ) && is_array( $message ) ) {
    157             wp_send_json( array(
    158                 'index' => $message['index'],
    159                 'data' => $message['data']
    160             ) );
    161         }
     178       
     179        $result = get_option( 'tpba_cron_result' );
     180       
     181        if ( !empty( $result ) && is_array( $result ) ) {
     182            $result['continue'] = false;
     183            delete_option( 'tpba_cron_result' );
     184            wp_send_json( $result );
     185           
     186           
     187        } else if ( get_transient( 'doing_cron' ) ) {
     188           
     189            $message = get_option( 'tpba_cron_message' );
     190            if ( !empty( $message ) && is_array( $message ) ) {
     191                wp_send_json( array(
     192                    'index' => $message['index'],
     193                    'data' => $message['data'],
     194                    'continue' => true
     195                ) );
     196            }
     197        }
     198
     199
    162200
    163201        wp_send_json( array(
    164             'index' => -1,
    165             'data' => esc_html__( 'There is nothing.', 'tp-backup-automator' )
    166         ) );
    167     }
    168 
    169     public static function alldone() {
    170         delete_option( 'tpba_backup_current' );
    171         delete_option( 'tpba_restore_current' );
    172         delete_option( 'tpba_cron_message' );
    173         update_option( 'tpba_alldone', 1 );
    174         wp_send_json_success( esc_html__( 'All done', 'tp-backup-automator' ) );
     202            'success' => false,
     203            'data' => esc_html__( 'Error when restore a file', 'tp-backup-automator' ),
     204            'continue' => false
     205        ) );
     206       
     207       
    175208    }
    176209
     
    283316        ) );
    284317    }
    285    
    286    
    287     public static function abort(){
    288        
    289     }
     318
     319    public static function abort() {
     320       
     321    }
     322
    290323}
    291324
  • tp-backup-automator/trunk/includes/class-tpba-cron.php

    r1705516 r1709427  
    66        add_action( 'tpba_cron_backup', array( __CLASS__, 'do_backup' ) );
    77        add_action( 'tpba_cron_restore', array( __CLASS__, 'do_restore' ) );
     8
     9        add_action( 'delete_transient_doing_cron', array( __CLASS__, 'cron_end' ) );
    810    }
    911
    1012    public static function register_backup() {
    1113        if ( !wp_next_scheduled( 'tpba_cron_backup' ) ) {
    12             wp_schedule_single_event( time() + 1, 'tpba_cron_backup' );
     14            wp_schedule_single_event( time() - 1, 'tpba_cron_backup' );
    1315            self::sendMessage( 0, esc_html__( 'Prepare files...', 'tp-backup-automator' ) );
    1416        }
     
    1719    public static function register_restore() {
    1820        if ( !wp_next_scheduled( 'tpba_cron_restore' ) ) {
    19             wp_schedule_single_event( time() + 1, 'tpba_cron_restore' );
     21            wp_schedule_single_event( time() - 1, 'tpba_cron_restore' );
    2022            self::sendMessage( 0, esc_html__( 'Prepare files...', 'tp-backup-automator' ) );
    2123        }
     
    4143
    4244                $res = self::backup_file( $i, $session_id );
    43                 update_option('test2', 'hihihi');
    44                 self::sendMessage( $i, $res['data']);
    45 
    46                 $i++;
    47             }
    48 
    49             self::sendMessage( $total_count, esc_html__( 'Almost done', 'tp-backup-automator' ) );
    50 
    51             /**
    52              * Backup done
    53              * Remove sql file
    54              */
    55             if ( is_dir( ABSPATH . 'tpba-sql' ) ) {
    56                 $scanner = new TPBA_Scanner();
    57                 $scanner->delete_directory( ABSPATH . 'tpba-sql' );
    58             }
    59 
    60             /**
    61              * Save current locals to master
    62              */
    63             $master = new TPBA_Master();
    64             $master->backup_changed();
    65 
    66             self::sendMessage( $total_count, esc_html__( 'Done', 'tp-backup-automator' ) );
     45
     46                if ( $res ) {
     47                    $i++;
     48                    self::sendMessage( $i, $res['data'] );
     49                } else if ( $res == 0 ) {
     50
     51                    /**
     52                     * If is lost connection
     53                     * Allow reconnect one time
     54                     */
     55                    $res = self::backup_file( $i, $session_id );
     56
     57                    if ( $res ) {
     58                        $i++;
     59                        self::sendMessage( $i, $res['data'] );
     60                    } else {
     61                        self::sendMessage( $total_count, esc_html__( 'The connection has been lost. Don\'t worry about it. Your data will be rolled back.' ) );
     62                        sleep( 2 );
     63                        return false;
     64                    }
     65                } else {
     66                    self::sendMessage( $total_count, esc_html__( 'Some files were deleted during the backup running, please check them. Don\'t worry about it. Your data will be rolled back.' ) );
     67                    sleep( 2 );
     68                    return false;
     69                }
     70            }
     71
     72            self::sendMessage( $total_count, esc_html__( 'Almost done, please wait...', 'tp-backup-automator' ) );
     73
     74            sleep( 2 );
    6775        } else {
    6876            self::sendMessage( 0, esc_html__( 'Data backup is not avaiable.', 'tp-backup-automator' ) );
     
    8088            $service = new TPBA_Services( $session_id );
    8189
    82             $res = $service->backup_file( $log_data['dir'],$log_data['file'], $log_data['checksums'], $log_data['file_status'] );
     90            $res = $service->backup_file( $log_data['dir'], $log_data['file'], $log_data['checksums'], $log_data['file_status'] );
    8391
    8492            if ( !empty( $res['success'] ) ) {
     
    8795                $log->track( $log_data['ID'], $res['data'], 1 );
    8896                $res['success'] = true;
    89             } else if ( $res == 0 ) {
    90                 $log->track( $log_data['ID'], sprintf( esc_html__( 'Cannot remote %s file', 'tp-backup-automator' ), $log_data['file_status'] ), 0 );
     97            } else if ( $res === 0 ) {
     98                $log->track( $log_data['ID'], sprintf( esc_html__( 'File is not exist', 'tp-backup-automator' ), $log_data['file_status'] ), 0 );
     99                return -1;
    91100            } else {
    92                 $log->track( $log_data['ID'], $res['server'], 0 );
     101                //Lost connection
     102                return 0;
    93103            }
    94104        } else {
    95 
    96105            $res['success'] = false;
    97106            $res['data'] = sprintf( esc_html__( '%s not found.', 'tp-backup-automator' ), $log_data['file'] );
    98             $log->track( $log_data['ID'], $res['data'], 0 );
     107            $log->track( $log_data['ID'], $res, 0 );
    99108        }
    100109
     
    102111    }
    103112
     113    public static function backup_done() {
     114
     115        /**
     116         * Backup done
     117         * Remove sql file
     118         */
     119        if ( is_dir( ABSPATH . 'tpba-sql' ) ) {
     120            $scanner = new TPBA_Scanner();
     121            $scanner->delete_directory( ABSPATH . 'tpba-sql' );
     122        }
     123
     124        /**
     125         * Save current locals to master
     126         */
     127        $master = new TPBA_Master();
     128        $master->backup_changed();
     129    }
     130
    104131    public static function do_restore() {
    105132
     
    110137
    111138        $current = get_option( 'tpba_restore_current' );
    112        
     139
    113140        $service = new TPBA_Services();
    114141        $service->remove_cache_activities();
     
    121148
    122149                $res = self::restore_file( $i, $current['session_id'], $current['security'] );
    123 
    124                 self::sendMessage( $i, $res );
    125 
    126                 $i++;
    127             }
    128            
    129             self::sendMessage( $total_count, esc_html__( 'Almost done, Please wait...', 'tp-backup-automator' ) );
    130            
    131             sleep(1);
    132 
    133             /**
    134              * Restore done
    135              */
    136             self::restore_done( $total_count );
     150                if ( $res ) {
     151                    $i++;
     152                    self::sendMessage( $i, $res );
     153                } else {
     154                    /**
     155                     * If is lost connection
     156                     * Allow reconnect one time
     157                     */
     158                    $res = self::restore_file( $i, $current['session_id'], $current['security'] );
     159
     160                    if ( $res ) {
     161                        $i++;
     162                        self::sendMessage( $i, $res );
     163                    } else {
     164                        self::sendMessage( $total_count, esc_html__( 'Some files cannot downloaded during the restore running. Don\'t worry about it. Your data will be rolled back.' ) );
     165                        sleep( 2 );
     166                        return false;
     167                    }
     168                }
     169            }
     170
     171            self::sendMessage( $total_count, esc_html__( 'Almost done, please wait...', 'tp-backup-automator' ) );
     172            sleep( 1 );
    137173        } else {
    138             self::sendMessage( 0, esc_html__( 'Data backup is not avaiable.', 'tp-backup-automator' ) );
     174            self::sendMessage( 0, esc_html__( 'Data to backup is not avaiable.', 'tp-backup-automator' ) );
    139175        }
    140176    }
     
    143179
    144180        $service = new TPBA_Services( $session_id, $security_id );
     181        $scanner = new TPBA_Scanner();
     182        $log = new TPBA_Log();
    145183
    146184        $file = $service->restore_file( $index );
    147185
    148         $file_path = $file['file'];
    149 
    150         $dir = $file['dir'];
    151 
    152         $file_path = str_replace( $dir . '/', '', $file_path );
    153 
    154         if ( $dir == 'root' ) {
    155             $dir = '';
    156         }
    157 
    158         $log = new TPBA_Log();
     186        $short_file = tpba_sanitize_file_from_server( $file );
    159187
    160188        if ( $file['success'] ) {
    161189
    162             $service->scanner->config_dir( untrailingslashit( ABSPATH . 'tpba/' . $dir ) );
    163             $res = $service->scanner->write_file( $file['content'], $file_path );
    164 
    165             $message = sprintf( esc_html__( '%s was not saved. ', 'tp-backup-automator' ), $file_path );
     190            $dir = $file['dir'] == 'root' ? '' : $file['dir'];
     191
     192            $real_file = ABSPATH . 'tpba/' . $dir . '/' . $short_file;
     193
     194            $res = $scanner->write_file( $file['content'], $real_file );
     195
     196            $message = sprintf( esc_html__( '%s was not saved. ', 'tp-backup-automator' ), $short_file );
    166197
    167198            if ( $res ) {
    168                 $message = sprintf( esc_html__( 'Prepare %s was done. ', 'tp-backup-automator' ), $file_path );
    169 
    170                 $log->add_file( $file_path, $file['checksums'], $file['dir'], 'added', 1, $message );
     199                $message = sprintf( esc_html__( 'Prepare %s was done. ', 'tp-backup-automator' ), $short_file );
     200
     201                $log->add_file( $short_file, $file['checksums'], $file['dir'], 'added', 1, $message );
    171202            }
    172203        } else {
    173204            $message = $file['server'];
    174             $log->add_file( $file_path, $file['checksums'], $file['dir'], 'added', 0, $message );
     205            $log->add_file( $short_file, $file['checksums'], $file['dir'], 'added', 0, $message );
     206            return 0;
    175207        }
    176208
     
    178210    }
    179211
    180     public static function restore_done( $total_count ) {
    181 
    182         $check_restore = true;
    183 
     212    public static function restore_done( $total_count, $session_id = '' ) {
     213        /**
     214         * Replace wp-content files
     215         */
    184216        $scanner = new TPBA_Scanner();
    185 
    186         /**
    187          * Replace files
    188          */
    189217        $wp_content = str_replace( ABSPATH, '', WP_CONTENT_DIR );
    190         $check_restore = $scanner->replace_folder( ABSPATH . 'tpba/' . $wp_content, WP_CONTENT_DIR );
    191 
    192         /**
    193          * Restore files done
    194          */
    195         if ( $check_restore ) {
    196 
    197             $list_sql = $scanner->scan_files( ABSPATH . 'tpba/sql' );
    198 
    199             if ( count( $list_sql ) ) {
    200 
    201                 $sql_dump = new TPBA_Sql_dump();
    202 
    203                 foreach ( $list_sql as $sql ) {
    204                     /**
    205                      * Output: array('affected_rows' => 1, 'sql_file' => $sql, 'mysql_cli' => false, 'list_error' => $list_error);
    206                      */
    207                     $sql_dump->import_SQL( $sql, false );
    208                 }
    209             }
    210 
    211             $master = new TPBA_Master();
    212             $master->restore_changed();
    213            
    214             self::sendMessage( $total_count, esc_html__( 'All done', 'tp-backup-automator' ) );
    215         } else {
    216             self::sendMessage( $total_count, esc_html__( 'Have an error while restore progress.', 'tp-backup-automator' ) );
    217         }
     218        $downloaded_folder = ABSPATH . 'tpba/';
     219
     220        $scanner->replace_folder( $downloaded_folder . $wp_content, WP_CONTENT_DIR );
     221
     222        /**
     223         * Replace sql
     224         */
     225        $list_sql = $scanner->scan_files( $downloaded_folder . 'sql' );
     226
     227        if ( count( $list_sql ) ) {
     228
     229            $sql_dump = new TPBA_Sql_dump();
     230
     231            foreach ( $list_sql as $sql ) {
     232                /**
     233                 * Output: array('affected_rows' => 1, 'sql_file' => $sql, 'mysql_cli' => false, 'list_error' => $list_error);
     234                 */
     235                $sql_dump->import_SQL( $sql, false );
     236            }
     237        }
     238
     239        /**
     240         * Remove downloaded folder when all replace
     241         */
     242        $scanner->delete_directory( $downloaded_folder );
     243
     244        /**
     245         * Sync all restored data to master
     246         */
     247        $master = new TPBA_Master();
     248        return $master->restore_changed();
    218249    }
    219250
     
    226257    }
    227258
     259    /**
     260     * Cron end
     261     * @since 1.0.1
     262     * @return void
     263     */
     264    public static function cron_end() {
     265
     266        $backup = get_option( 'tpba_backup_current' );
     267        $restore = get_option( 'tpba_restore_current' );
     268
     269        $res = false;
     270        $data = '';
     271        $log = new TPBA_Log();
     272
     273        if ( !empty( $backup['total_count'] ) && !empty( $backup['session_id'] ) ) {
     274
     275            $total_count = sanitize_text_field( $backup['total_count'] );
     276            $session_id = sanitize_text_field( $backup['session_id'] );
     277            $service = new TPBA_Services( $session_id );
     278
     279            if ( $log->is_done() ) {
     280
     281                self::backup_done( $total_count, $session_id );
     282                $res = true;
     283                $data = esc_html__( 'You have created a backup successfully.', 'tp-backup-automator' );
     284            } else {
     285                $service->rollback();
     286                $data = esc_html__( 'Opps, this backup has not been done. All data will be rolled back.', 'tp-backup-automator' );
     287            }
     288
     289            update_option( 'tpba_cron_result', array( 'type' => 'backup', 'success' => $res, 'data' => $data ) );
     290            $service->remove_cache_activities();
     291            delete_option( 'tpba_backup_current' );
     292        } else if ( !empty( $restore['total_count'] ) && !empty( $restore['session_id'] ) ) {//Resore done
     293            $total_count = sanitize_text_field( $restore['total_count'] );
     294            $session_id = sanitize_text_field( $restore['session_id'] );
     295            $service = new TPBA_Services( $session_id );
     296            $res = false;
     297
     298            if ( $log->is_done() ) {
     299                $res = self::restore_done( $total_count, $session_id );
     300            }
     301
     302            if ( $res ) {
     303                $data = esc_html__( 'Done! Your data has been restored successfully.', 'tp-backup-automator' );
     304            } else {
     305                $service->rollback();
     306                $data = esc_html__( 'Opps, the restoration process cannot be completed now. Dont worry! Your data won\'t be affected.', 'tp-backup-automator' );
     307            }
     308
     309            delete_option( 'tpba_restore_current' );
     310            $service->remove_cache_activities();
     311            update_option( 'tpba_cron_result', array( 'type' => 'restore', 'success' => $res, 'data' => $data ) );
     312        }
     313
     314
     315        delete_option( 'tpba_cron_message' );
     316    }
     317
    228318}
    229319
  • tp-backup-automator/trunk/includes/class-tpba-install.php

    r1705516 r1709427  
    4949        }
    5050    }
    51 
     51   
     52    /**
     53     * Un Install plugin
     54     * @since 1.0.1
     55     */
     56    public static function uninstall(){
     57           
     58        delete_transient('doing_cron');
     59        delete_option('tpba_restore_current');
     60        delete_option('tpba_backup_current');
     61       
     62    }
    5263}
  • tp-backup-automator/trunk/includes/class-tpba-master.php

    r1705516 r1709427  
    201201     * Insert all log to master when restore done
    202202     * @since 1.0.0
    203      * @return void
     203     * @return bool
    204204     */
    205205    public function restore_changed() {
     
    216216                $this->add();
    217217            }
    218         }
     218           
     219            return true;
     220        }
     221       
     222        return false;
    219223    }
    220224   
  • tp-backup-automator/trunk/includes/class-tpba-scanner.php

    r1705516 r1709427  
    2424     */
    2525    public function config_dir( $dir ) {
     26
     27        if ( $dir == 'plugins' ) {
     28            $dir = trailingslashit( WP_PLUGIN_DIR );
     29        } else if ( $dir == 'themes' ) {
     30            $dir = trailingslashit( WP_CONTENT_DIR ) . 'themes/';
     31        } else if ( $dir == 'uploads' ) {
     32            $uploadir = wp_upload_dir();
     33            $dir = trailingslashit( $uploadir['basedir'] );
     34        } else {
     35            $dir = trailingslashit( WP_CONTENT_DIR );
     36        }
     37
    2638        $this->dir = $dir;
    2739    }
     
    296308     *
    297309     * @param String $content File Content
    298      * @param stirng $filename
     310     * @param stirng $filename Real path file
    299311     * @return int File length
    300312     */
    301313    public function write_file( $content, $filename ) {
    302314
    303         $dir = $this->dir . '/' . $this->dir_of_file( $filename );
     315        $dir = $this->dir_of_file( $filename );
    304316
    305317        if ( !is_dir( $dir ) ) {
     
    307319        }
    308320
    309         $file = fopen( $this->dir . '/' . $filename, 'w' ) or die( 'Cannot open file: ' . $filename );
     321        $file = fopen($filename, 'w' ) or die( 'Cannot open file: ' . $filename );
    310322        fwrite( $file, $content );
    311323        return fclose( $file );
     
    333345
    334346        $check_folder = $this->check_exist_folder( $folder_dest );
     347
    335348        // Remove original folder
    336349        if ( $check_folder ) {
     
    339352        // Create folder
    340353        @mkdir( $folder_dest, 0777, true );
    341         //chmod($folder_source, 0777);
     354
    342355        // Copy folder source to folder destination
    343356        $check_replace = $this->recurse_copy( $folder_source, $folder_dest );
    344357
    345358        // Remove source folder
    346         //$check_replace = $this->delete_directory($folder_source);
     359        $check_replace = $this->delete_directory( $folder_source );
    347360
    348361        return $check_replace;
  • tp-backup-automator/trunk/includes/class-tpba-services.php

    r1705516 r1709427  
    1616    private $restore_security;
    1717
    18     /**
    19      * @var string Full path from $dir
    20      */
    21     public $dir_path;
    22 
    23     /**
    24      * @var string Base path
    25      */
    26     public $dir;
    27 
    28     /**
    29      * @var object TPBA_Scanner
    30      */
    31     public $scanner;
    32 
    3318    public function __construct( $session_id = '', $restore_security = '' ) {
    3419
    3520        parent::__construct();
    3621
    37         $this->session = $session_id;
     22        $this->session_id = $session_id;
    3823        $this->restore_security = $restore_security;
    39         $this->scanner = new TPBA_Scanner();
    40         $this->dir = 'wp-content';
    41         $this->config_dir( 'wp-content' );
    42     }
    43 
     24    }
     25
     26    /**
     27     * Get magic method
     28     * @param string $name Name of var
     29     * @return var
     30     */
    4431    public function __get( $name ) {
    4532        return $this->$name;
     
    4734
    4835    /**
    49      * Defined the path
    50      * @param string $dir
    51      * @return string Full path
    52      */
    53     public function get_dir( $dir ) {
    54         if ( $dir == 'plugins' ) {
    55             $dir = trailingslashit( WP_PLUGIN_DIR );
    56         } else if ( $dir == 'themes' ) {
    57             $dir = trailingslashit( WP_CONTENT_DIR ) . 'themes/';
    58         } else if ( $dir == 'uploads' ) {
    59             $uploadir = wp_upload_dir();
    60             $dir = trailingslashit( $uploadir['basedir'] );
    61         } else {
    62             $dir = trailingslashit( WP_CONTENT_DIR );
    63         }
    64 
    65         return $dir;
    66     }
    67 
    68     /**
    69      * Set local dir
    70      * @param string $dir
    71      * @return void
    72      */
    73     public function config_dir( $dir = '' ) {
    74         $this->dir_path = $this->get_dir( $dir );
    75         $this->scanner->config_dir( $this->dir_path );
    76     }
    77 
    78     /**
    7936     * Create a connect backup
    8037     * @since 1.0.0
     
    8340    public function connect_to_service() {
    8441
    85         $local_files = $this->local_files();
     42        $local_files = tpba_local_files();
    8643
    8744        $master = new TPBA_Master();
    88         $master_files = $master->get_master();
    89 
    90         $changed_files = $this->get_changed_files( $master_files, $local_files );
    91         $count_changed_files = $this->count_changed_files( $changed_files );
     45        $changed_files = tpba_get_changed_files( $master->get_master(), $local_files );
     46        $count_changed_files = tpba_count_changed_files( $changed_files );
    9247
    9348        /**
     
    154109                 * Save sql has changed content to local
    155110                 */
    156                 $this->dump_sql_changed( $changed_files['sql'] );
     111                tpba_dump_sql_changed( $changed_files['sql'] );
    157112
    158113                update_option( 'tpba_backup_current', array( 'session_id' => $session_id, 'total_count' => $count_changed_files['all'] ) );
     
    192147        }
    193148
    194         if ( file_exists( $realfile ) || $status == 'deleted' ) {
    195 
    196             $contents = $status != 'deleted' ? file_get_contents( $realfile ) : '';
     149        $file_exists = file_exists( $realfile );
     150
     151        if ( $file_exists || $status == 'deleted' ) {
     152
     153            $contents = '';
     154
     155            if ( $file_exists ) {
     156                $contents = file_get_contents( $realfile );
     157            }
    197158
    198159            $response = wp_remote_post( $this->service_api . 'file', array(
    199                 'timeout' => 3000,
     160                'timeout' => 1500,
    200161                'headers' => array(
    201162                    'remote' => 'FILE',
     
    204165                        'file' => $file,
    205166                        'status' => $status,
    206                         'session' => $this->session,
     167                        'session' => $this->session_id,
    207168                        'dir' => $dir
    208169                    ) ),
     
    226187        $res = array(
    227188            'status' => wp_remote_retrieve_response_code( $response ),
    228             'data' => sprintf( esc_html__( '%s cannot completed.', 'tp-backup-automator' ), $file ),
     189            'data' => sprintf( esc_html__( '%s has error from service.', 'tp-backup-automator' ), $file ),
    229190            'success' => false,
    230191            'server' => wp_remote_retrieve_body( $response )
     
    240201        }
    241202
     203        if ( $res['status'] != 200 ) {
     204            $res['data'] = esc_html__( 'Cannot create connect to service', 'tp-backup-automator' );
     205            return $res;
     206        }
     207
    242208        if ( !is_wp_error( $response ) ) {
    243209
     
    268234            'headers' => array(
    269235                'authentication' => $this->token,
    270             ), 'body' => array( 'session_restore' => $this->session ) ) );
     236            ), 'body' => array( 'session_restore' => $this->session_id ) ) );
    271237
    272238
     
    302268            if ( !empty( $response->session ) ) {
    303269                update_option( 'tpba_restore_current', array(
    304                     'total_count' => $response->file_count, 'session_id' => $this->session, 'security' => $response->session
     270                    'total_count' => $response->file_count, 'session_id' => $this->session_id, 'security' => $response->session
    305271                ) );
    306272            }
     
    327293
    328294        $response = wp_remote_post( $this->service_api . 'restore', array(
    329             'timeout' => 30000,
     295            'timeout' => 1500,
    330296            'headers' => array(
    331297                'authentication' => $this->token,
    332298            ), 'body' => array(
    333                 'session_restore' => $this->session,
     299                'session_restore' => $this->session_id,
    334300                'session' => $this->restore_security,
    335301                'index' => $index,
     
    342308            'server' => '',
    343309            'checksums' => '',
    344             'success' => false
     310            'success' => false,
     311            'status' => wp_remote_retrieve_response_code( $response )
    345312        );
     313       
     314        /**
     315         * Check operation timed out
     316         */
     317        if ( isset( $response->errors['http_request_failed'][0] ) ) {
     318            $data['status'] = -1;
     319            $data['data'] = esc_html__( '%s is response too long.', 'tp-backup-automator' );
     320            return $data;
     321        }
     322       
     323        if ( $data['status'] != 200 ) {
     324            $data['server'] = esc_html__( 'Cannot create connect to service', 'tp-backup-automator' );
     325            return $data;
     326        }
    346327
    347328        if ( !is_wp_error( $response ) ) {
     
    358339            if ( !empty( $response[3] ) ) {
    359340                if ( ($response[2] == 'sql') || strpos( $response[0], '.htacesss' ) > 0 || (strpos( $response[0], 'wp_config.php' ) > 0) ) {
    360                     $data['content'] = $this->update_new_domain( $response[3] );
     341                    $data['content'] = tpba_update_new_domain( $response[3] );
    361342                } else {
    362343                    $data['content'] = $response[3];
     
    380361
    381362    /**
    382      * Replace old domain to new domain of SQL file
    383      *
    384      * @param string $content Content File
    385      * @since 1.0.0
    386      *
    387      */
    388     private function update_new_domain( $content ) {
    389         global $wpdb;
    390         $old_domain = get_option( 'tpba_restore_domain' );
    391         $current_domain = get_site_url();
    392         $current_domain = format_address( $current_domain );
    393 
    394         return str_replace( $old_domain, $current_domain, $content );
    395     }
    396 
    397     /**
    398      * Compare repository with current files
    399      *
    400      * @param array $session_files File from session
    401      * @param string $local_files Folder contain files
    402      *
    403      * @return array Group files with status
    404      * @since 1.0.0
    405      */
    406     private function compare_files( $session_files, $local_files ) {
    407 
    408         $checked_files = array();
    409 
    410         $changed_files = array_diff_assoc( $local_files, $session_files );
    411 
    412         $new_files = array_diff_key( $local_files, $session_files );
    413         $deleted_files = array_diff_key( $session_files, $local_files );
    414 
    415         $checked_files['deleted'] = $deleted_files;
    416         $checked_files['added'] = $new_files;
    417         $checked_files['changed'] = array_diff_key( $changed_files, $new_files );
    418         return $checked_files;
    419     }
    420 
    421     /**
    422      * Get all changed files from compare
    423      * @since 1.0.0
    424      *
    425      * @param array $session_files File from session
    426      * @param string $local_files Folder contain files
    427      * @return array wp-content and sql file changed
    428      */
    429     public function get_changed_files( $session_files, $local_files ) {
    430         $sql = $this->compare_files( $session_files['sql'], $local_files['sql'] );
    431         $root = $this->compare_files( $session_files['root'], $local_files['root'] );
    432         $content = $this->compare_files( $session_files['wp-content'], $local_files['wp-content'] );
    433         $checked_files = array( 'sql' => $sql, 'root' => $root, 'wp-content' => $content );
    434 
    435         return $checked_files;
    436     }
    437 
    438     /**
    439      * Count file changed
    440      * @since 1.0.0
    441      *
    442      * @param array File after compared to local files
    443      * @return array
    444      */
    445     public function count_changed_files( $compare_files ) {
    446 
    447         $count_content = count( $compare_files['wp-content']['deleted'] );
    448         $count_content += count( $compare_files['wp-content']['added'] );
    449         $count_content += count( $compare_files['wp-content']['changed'] );
    450 
    451         $count_sql = count( $compare_files['sql']['deleted'] );
    452         $count_sql += count( $compare_files['sql']['added'] );
    453         $count_sql += count( $compare_files['sql']['changed'] );
    454 
    455         $count_root = count( $compare_files['root']['deleted'] );
    456         $count_root += count( $compare_files['root']['added'] );
    457         $count_root += count( $compare_files['root']['changed'] );
    458 
    459         return array(
    460             'wp-content' => $count_content,
    461             'root' => $count_root,
    462             'sql' => $count_sql,
    463             'all' => ($count_content + $count_root + $count_sql)
    464         );
    465     }
    466 
    467     /**
    468      * Scan all local file in wp-content with wp-config.php
    469      * @since 1.0.0
    470      * @return array Short path file with checksums
    471      */
    472     public function local_files() {
    473 
    474         $files = array();
    475 
    476         $files['sql'] = array();
    477 
    478         $sql = new TPBA_Sql();
    479         $tables = $sql->get_all_table();
    480 
    481         global $wpdb;
    482 
    483         $ignore_tables = array(
    484             $wpdb->prefix . 'tpba_master',
    485             $wpdb->prefix . 'tpba_logs'
    486         );
    487 
    488         foreach ( $tables as $table ) {
    489 
    490             if ( !in_array( $table, $ignore_tables ) ) {
    491 
    492                 $sql_dump = new TPBA_Sql_dump();
    493                 $sql_dump->table = $table;
    494                 $file = $sql_dump->toName();
    495 
    496                 $contents = $sql_dump->toSQL( 0, 100000 );
    497 
    498                 $files['sql'][$file] = md5( $contents );
    499             }
    500         }
    501 
    502         $files['root'] = array(
    503             'wp-config.php' => $this->scanner->checksum_file( ABSPATH . 'wp-config.php' ),
    504             '.htaccess' => $this->scanner->checksum_file( ABSPATH . '.htaccess' )
    505         );
    506 
    507         $files['wp-content'] = $this->scanner->checksum_files( WP_CONTENT_DIR, true );
    508 
    509         return $files;
    510     }
    511 
    512     /**
    513      * @param array $sql
    514      * @return void
    515      */
    516     public function dump_sql_changed( $sql ) {
    517 
    518         $sqls = $sql['changed'] + $sql['added'];
    519 
    520         $this->scanner->config_dir( ABSPATH . 'tpba-sql' );
    521 
    522         foreach ( $sqls as $table => $checksums ) {
    523 
    524             $sql_dump = new TPBA_Sql_dump();
    525             $dbname = $sql_dump->__get( 'db_name' );
    526             $name = str_replace( $dbname . '.', '', $table );
    527             $name = str_replace( '.sql', '', $name );
    528             $sql_dump->__set( 'table', $name );
    529             $this->scanner->write_file( $sql_dump->toSQL( 0, 100000 ), $sql_dump->toName() );
    530         }
     363     * Rollback when a session was not done
     364     * @since 1.0.0
     365     */
     366    public function rollback() {
     367
     368        $response = wp_remote_post( $this->service_api . 'rollback', array(
     369            'timeout' => 1500,
     370            'headers' => array(
     371                'authentication' => $this->token,
     372            ), 'body' => array(
     373                'session' => $this->session_id
     374            )
     375                ) );
     376
     377        return $this->remote_response( $response );
    531378    }
    532379
     
    545392        }
    546393
    547         $response = wp_remote_get( $this->service_api . 'activity/' . $this->token . '?type=' . $type );
     394        $response = wp_remote_get( $this->service_api . 'activity/' . $this->token . '?type=' . $type, array( 'timeout' => 300 ) );
     395        /**
     396         * Check operation timed out
     397         */
     398        if ( isset( $response->errors['http_request_failed'][0] ) ) {
     399            throw new Exception( esc_html__( 'Response to service is too long, pls try again.', 'tp-backup-automator' ), -1 );
     400        }
     401
    548402
    549403        $status = wp_remote_retrieve_response_code( $response );
     
    594448            update_option( 'themespond_key', '' );
    595449            update_option( 'themespond_email', '' );
    596             wp_safe_redirect(admin_url('tools.php?page=tp-backup-automator'));
     450            wp_safe_redirect( admin_url( 'tools.php?page=tp-backup-automator' ) );
    597451            exit();
    598452        }
     
    600454}
    601455
    602 add_action( 'load-tools_page_tp-backup-automator','tpba_reset_key' );
     456add_action( 'load-tools_page_tp-backup-automator', 'tpba_reset_key' );
  • tp-backup-automator/trunk/includes/class-tpba-sql-dump.php

    r1705516 r1709427  
    2323    // List column name of table
    2424    private $list_columns_name;
     25    private $prefix;
    2526
    2627    public function __construct( $table_name = '' ) {
     
    2829        $this->db_name = $wpdb->dbname;
    2930        $this->table = $table_name;
     31        $this->prefix = $wpdb->prefix;
    3032    }
    3133
     
    3941
    4042    public function toName() {
    41         return $this->db_name . '.' . $this->table . '.sql';
     43        return str_replace( $this->prefix, '', $this->table ) . '.sql';
    4244    }
    4345
     
    5658        // Delete if exist
    5759
    58         $output = "DROP TABLE IF EXISTS `" . $table . "`;\r\n-- --- \r\n";
     60        $output = "DROP TABLE IF EXISTS `$table`;\r\n-- --- \r\n";
    5961
    6062        // Create table
     
    7173
    7274        foreach ( $rows as $row ) {
    73             $cols = "INSERT INTO " . $table . " (";
     75            $cols = "INSERT INTO `$table` (";
    7476            foreach ( $columns as $column ) {
    7577                // for custom queries we don't know the column types
     
    253255            exec( sprintf( '%s %s', escapeshellcmd( $mysql ), vsprintf( '-A --default-character-set=%s -u%s -p%s -h%s -P%s %s < %s', array_map( 'escapeshellarg', $params ) ) ), $output, $r );
    254256
    255             //if (0 === $r) {
     257
    256258            if ( $delete ) {
    257259                @unlink( $sql_path );
    258260            }
    259261            return array( 'affected_rows' => 1, 'sql_file' => $sql_path, 'mysql_cli' => true );
    260             //}
    261262        }
    262263
     
    265266        $sql_source = file_get_contents( $sql_path );
    266267        $sql_queries = explode( "-- ---", $sql_source );
     268       
    267269        foreach ( $sql_queries as $sql_query ) {
    268270            if ( !ctype_space( $sql_query ) ) {
  • tp-backup-automator/trunk/includes/class-tpba-user.php

    r1705516 r1709427  
    2626        $this->tp_api = 'http://api.themespond.com/api/v1/';
    2727        $this->service_api = 'http://api.themespond.com/api/v1/backup/';
    28 
     28       
    2929        if ( !empty( $email ) ) {
    3030            $this->email = $email;
  • tp-backup-automator/trunk/languages/tp-backup-automator.pot

    r1705516 r1709427  
    44"Project-Id-Version: PACKAGE VERSION\n"
    55"Report-Msgid-Bugs-To: \n"
    6 "POT-Creation-Date: 2017-07-31 07:56+0000\n"
     6"POT-Creation-Date: 2017-08-07 00:28+0000\n"
    77"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    88"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1515"X-Generator: Loco - https://localise.biz/"
    1616
    17 #: tp-backup-automator.php:83
     17#: tp-backup-automator.php:84
    1818#, php-format
    1919msgid ""
     
    2222msgstr ""
    2323
    24 #: tp-backup-automator.php:87
     24#: tp-backup-automator.php:88
    2525#, php-format
    2626msgid ""
     
    3030
    3131#. Name of the plugin
    32 #: tp-backup-automator.php:116 templates/plugin-page.php:19
     32#: tp-backup-automator.php:118 templates/plugin-page.php:19
    3333msgid "TP Backup Automator"
    3434msgstr ""
    3535
    36 #: tp-backup-automator.php:116
     36#: tp-backup-automator.php:118
    3737msgid "Backup Automator"
    3838msgstr ""
    3939
    40 #: tp-backup-automator.php:174 includes/class-tpba-ajax.php:193
     40#: tp-backup-automator.php:177 includes/class-tpba-ajax.php:226
    4141msgid "Please, enter a valid email."
    4242msgstr ""
    4343
    44 #: tp-backup-automator.php:175
     44#: tp-backup-automator.php:178
    4545msgid "Please, enter a valid product key."
    4646msgstr ""
    4747
    48 #: tp-backup-automator.php:176
     48#: tp-backup-automator.php:179
    4949msgid "Connecting..."
    5050msgstr ""
    5151
    52 #: tp-backup-automator.php:177
     52#: tp-backup-automator.php:180
    5353msgid "Cannot prepare files."
    5454msgstr ""
    5555
    56 #: tp-backup-automator.php:178 includes/class-tpba-ajax.php:174
    57 #: includes/class-tpba-cron.php:214
     56#: tp-backup-automator.php:181
    5857msgid "All done"
    5958msgstr ""
    6059
    61 #: tp-backup-automator.php:179
     60#: tp-backup-automator.php:182
    6261msgid "Warning"
    6362msgstr ""
    6463
    65 #: tp-backup-automator.php:180
     64#: tp-backup-automator.php:183
    6665msgid "files have backed up successfully."
    6766msgstr ""
    6867
    69 #: tp-backup-automator.php:181
     68#: tp-backup-automator.php:184
    7069msgid "files have restored successfully."
    7170msgstr ""
    7271
    73 #: tp-backup-automator.php:182
     72#: tp-backup-automator.php:185
    7473msgid "Are you sure you want to create a backup now?"
    7574msgstr ""
    7675
    77 #: tp-backup-automator.php:183
     76#: tp-backup-automator.php:186
    7877msgid "All your current data will be changed, are you sure?"
    7978msgstr ""
    8079
    81 #: tp-backup-automator.php:225 tp-backup-automator.php:225
     80#: tp-backup-automator.php:228 tp-backup-automator.php:228
    8281msgid "Settings"
    8382msgstr ""
    8483
    85 #: includes/class-tpba-ajax.php:100
     84#: includes/class-tpba-ajax.php:113
    8685msgid "Error when backup"
    8786msgstr ""
    8887
    89 #: includes/class-tpba-ajax.php:165
    90 msgid "There is nothing."
    91 msgstr ""
    92 
    93 #: includes/class-tpba-ajax.php:189 includes/class-tpba-ajax.php:233
     88#: includes/class-tpba-ajax.php:203
     89msgid "Error when restore a file"
     90msgstr ""
     91
     92#: includes/class-tpba-ajax.php:222 includes/class-tpba-ajax.php:266
    9493msgid "Sorry, your security key did not verify."
    9594msgstr ""
    9695
    97 #: includes/class-tpba-ajax.php:237
     96#: includes/class-tpba-ajax.php:270
    9897msgid "Your product key can not be empty."
    9998msgstr ""
    10099
    101 #: includes/class-tpba-ajax.php:243
     100#: includes/class-tpba-ajax.php:276
    102101msgid "Email is not validate."
    103102msgstr ""
    104103
    105 #: includes/class-tpba-cron.php:13 includes/class-tpba-cron.php:20
     104#: includes/class-tpba-cron.php:15 includes/class-tpba-cron.php:22
    106105msgid "Prepare files..."
    107106msgstr ""
    108107
    109 #: includes/class-tpba-cron.php:49
    110 msgid "Almost done"
    111 msgstr ""
    112 
    113 #: includes/class-tpba-cron.php:66 templates/backups.php:70
    114 msgid "Done"
    115 msgstr ""
    116 
    117 #: includes/class-tpba-cron.php:68 includes/class-tpba-cron.php:138
     108#: includes/class-tpba-cron.php:72 includes/class-tpba-cron.php:171
     109msgid "Almost done, please wait..."
     110msgstr ""
     111
     112#: includes/class-tpba-cron.php:76
    118113msgid "Data backup is not avaiable."
    119114msgstr ""
    120115
    121 #: includes/class-tpba-cron.php:86
     116#: includes/class-tpba-cron.php:94
    122117#, php-format
    123118msgid "%s was %s"
    124119msgstr ""
    125120
    126 #: includes/class-tpba-cron.php:90
    127 #, php-format
    128 msgid "Cannot remote %s file"
    129 msgstr ""
    130 
    131 #: includes/class-tpba-cron.php:97
     121#: includes/class-tpba-cron.php:98
     122msgid "File is not exist"
     123msgstr ""
     124
     125#: includes/class-tpba-cron.php:106
    132126#, php-format
    133127msgid "%s not found."
    134128msgstr ""
    135129
    136 #: includes/class-tpba-cron.php:129
    137 msgid "Almost done, Please wait..."
    138 msgstr ""
    139 
    140 #: includes/class-tpba-cron.php:165
     130#: includes/class-tpba-cron.php:174
     131msgid "Data to backup is not avaiable."
     132msgstr ""
     133
     134#: includes/class-tpba-cron.php:196
    141135#, php-format
    142136msgid "%s was not saved. "
    143137msgstr ""
    144138
    145 #: includes/class-tpba-cron.php:168
     139#: includes/class-tpba-cron.php:199
    146140#, php-format
    147141msgid "Prepare %s was done. "
    148142msgstr ""
    149143
    150 #: includes/class-tpba-cron.php:216
    151 msgid "Have an error while restore progress."
    152 msgstr ""
    153 
    154 #: includes/class-tpba-services.php:121 includes/class-tpba-services.php:282
     144#: includes/class-tpba-cron.php:283
     145msgid "You have created a backup successfully."
     146msgstr ""
     147
     148#: includes/class-tpba-cron.php:286
     149msgid "Opps, this backup has not been done. All data will be rolled back."
     150msgstr ""
     151
     152#: includes/class-tpba-cron.php:303
     153msgid "Done! Your data has been restored successfully."
     154msgstr ""
     155
     156#: includes/class-tpba-cron.php:306
     157msgid ""
     158"Opps, the restoration process cannot be completed now. Dont worry! Your data "
     159"won't be affected."
     160msgstr ""
     161
     162#: includes/class-tpba-services.php:76 includes/class-tpba-services.php:248
     163#: includes/class-tpba-services.php:399
    155164msgid "Response to service is too long, pls try again."
    156165msgstr ""
    157166
    158 #: includes/class-tpba-services.php:126 includes/class-tpba-services.php:287
    159 #: includes/class-tpba-services.php:556 includes/class-tpba-user.php:72
     167#: includes/class-tpba-services.php:81 includes/class-tpba-services.php:253
     168#: includes/class-tpba-services.php:410 includes/class-tpba-user.php:72
    160169#: includes/class-tpba-user.php:112
    161170msgid "Cannot connect to service."
    162171msgstr ""
    163172
    164 #: includes/class-tpba-services.php:131 includes/class-tpba-services.php:560
     173#: includes/class-tpba-services.php:86 includes/class-tpba-services.php:414
    165174#: includes/class-tpba-user.php:76 includes/class-tpba-user.php:116
    166175msgid "Error from service."
    167176msgstr ""
    168177
    169 #: includes/class-tpba-services.php:161
     178#: includes/class-tpba-services.php:116
    170179msgid "Connected."
    171180msgstr ""
    172181
    173 #: includes/class-tpba-services.php:166
     182#: includes/class-tpba-services.php:121
    174183msgid "Nothing changed now to backup"
    175184msgstr ""
    176185
    177 #: includes/class-tpba-services.php:228
    178 #, php-format
    179 msgid "%s cannot completed."
    180 msgstr ""
    181 
    182 #: includes/class-tpba-services.php:238
     186#: includes/class-tpba-services.php:189
     187#, php-format
     188msgid "%s has error from service."
     189msgstr ""
     190
     191#: includes/class-tpba-services.php:199 includes/class-tpba-services.php:319
    183192#, php-format
    184193msgid "%s is response too long."
    185194msgstr ""
    186195
    187 #: includes/class-tpba-services.php:299
     196#: includes/class-tpba-services.php:204 includes/class-tpba-services.php:324
     197msgid "Cannot create connect to service"
     198msgstr ""
     199
     200#: includes/class-tpba-services.php:265
    188201msgid "Connected"
    189202msgstr ""
    190203
    191 #: includes/class-tpba-services.php:552
     204#: includes/class-tpba-services.php:406
    192205msgid "Email and product key are invalid."
    193206msgstr ""
     
    213226msgstr ""
    214227
     228#: templates/backups.php:70
     229msgid "Done"
     230msgstr ""
     231
    215232#: templates/backups.php:74
    216233msgid "Error"
     
    229246msgstr ""
    230247
    231 #: templates/dashboard.php:30
     248#: templates/dashboard.php:31
    232249msgid "Recent activities"
    233250msgstr ""
    234251
    235 #: templates/dashboard.php:36
     252#: templates/dashboard.php:37
    236253msgid "Create a backup Now"
    237254msgstr ""
    238255
    239 #: templates/dashboard.php:76
     256#: templates/dashboard.php:77
    240257#, php-format
    241258msgid "You have created a backup with %d changed files about %s ago."
    242259msgstr ""
    243260
    244 #: templates/dashboard.php:79
     261#: templates/dashboard.php:80
    245262#, php-format
    246263msgid "You have some error with a backup with %d changed files about %s ago."
    247264msgstr ""
    248265
    249 #: templates/dashboard.php:86
    250 #, php-format
    251 msgid "You are restoring data with %d  files, begin from %s ago."
    252 msgstr ""
    253 
    254 #: templates/dashboard.php:88
     266#: templates/dashboard.php:87
     267#, php-format
     268msgid "You are restoring data with %d files, begin from %s ago."
     269msgstr ""
     270
     271#: templates/dashboard.php:89
    255272#, php-format
    256273msgid "You have restored all data with %d files about %s ago."
    257274msgstr ""
    258275
    259 #: templates/dashboard.php:102
     276#: templates/dashboard.php:103
    260277msgid "You have no activity to display."
    261278msgstr ""
  • tp-backup-automator/trunk/readme.txt

    r1705516 r1709427  
    66Requires at least: 4.0   
    77Tested up to: 4.8   
    8 Stable tag: 1.0.0   
     8Stable tag: 1.0.1   
    99License: GPLv3   
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html   
     
    6565== Changelog ==
    6666
     67= 1.0.1 (August 07, 2017): =
     68* Rollback when restore or backup is not completed
     69
    6770= 1.0.0 (July 26, 2017): =
    6871* Initial Public Release
  • tp-backup-automator/trunk/templates/dashboard.php

    r1705516 r1709427  
    2121    echo '<div class="tpba_alert tpba_alert--error">' . $ex->getMessage() . ' ' . $button . '</div>';
    2222}
     23
    2324if ( $is_connect ):
    2425    ?>
     
    8485                        if ( $session_id == $item->session ) {
    8586                            $cssClass .= ' item-done';
    86                             $content .= sprintf( esc_html__( 'You are restoring data with %d  files, begin from %s ago.', 'tp-backup-automator' ), $item->total_count, $tagDate );
     87                            $content .= sprintf( esc_html__( 'You are restoring data with %d files, begin from %s ago.', 'tp-backup-automator' ), $item->total_count, $tagDate );
    8788                        } else {
    8889                            $content .= sprintf( esc_html__( 'You have restored all data with %d files about %s ago.', 'tp-backup-automator' ), $item->total_count, $tagDate );
     
    109110    </table>
    110111    <?php
     112
     113
     114
     115
     116
     117
     118
    111119 endif;
  • tp-backup-automator/trunk/tp-backup-automator.php

    r1705516 r1709427  
    55 * Plugin URI: https://wordpress.org/plugins/tp-backup-automator/
    66 * Description: Backup & Restore your WordPress data and keep it safe.     
    7  * Version: 1.0.0
     7 * Version: 1.0.1
    88 * Author: ThemesPond
    99 * Author URI: https://themespond.com/
     
    6363        public function hook() {
    6464            register_activation_hook( __FILE__, array( 'TPBA_Install', 'install' ) );
     65            register_deactivation_hook( __FILE__, array( 'TPBA_Install', 'uninstall' ) );
    6566            add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 15 );
    6667            add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
     
    9899           
    99100            require TPBA_DIR . 'includes/helper-functions.php';
     101            require TPBA_DIR . 'includes/file-functions.php';
    100102            require TPBA_DIR . 'includes/class-tpba-ajax.php';
    101103            require TPBA_DIR . 'includes/class-tpba-user.php';
     
    129131                tpba_template( 'install', array( 'user' => $user ) );
    130132            }
     133           
    131134        }
    132135
     
    152155            define( 'TPBA_URL', plugin_dir_url( __FILE__ ) );
    153156            define( 'TPBA_DIR', plugin_dir_path( __FILE__ ) );
    154             define( 'TPBA_VER', '1.0.0' );
     157            define( 'TPBA_VER', '1.0.1' );
    155158        }
    156159
Note: See TracChangeset for help on using the changeset viewer.