Plugin Directory

Changeset 2005302


Ignore:
Timestamp:
01/02/2019 06:13:49 PM (7 years ago)
Author:
fullmoonfriday
Message:

Improve file transfers

Location:
wps-backup
Files:
36 added
3 edited

Legend:

Unmodified
Added
Removed
  • wps-backup/trunk/README.txt

    r2003439 r2005302  
    35351. Make the backup of your current website database
    36361. Restore the backup you have previously saved
     371. Select from cloud backups from WPScomplete.com
    3738
    3839== Changelog ==
  • wps-backup/trunk/includes/data_actions/wpsc_class_data_management.php

    r2003439 r2005302  
    130130        return $data;
    131131    }
     132
     133
     134
     135  //   public function process_part_file_download_transfer( $directory , $data , $filename , $part ) {
     136  //    $file_data = base64_decode( $data );
     137        // $create_file = $directory."/".$filename;
     138        // $db_file = fopen( $create_file ,'w' );
     139        // $bytes = fwrite( $db_file , $file_data );
     140        // $close = fclose( $db_file );
     141        // return $data;
     142  //   }
    132143
    133144
  • wps-backup/trunk/includes/wpsc_backup_functions.php

    r2003439 r2005302  
    2929    }
    3030    wp_safe_redirect( $url );
    31 
    3231}
    3332add_action('WPS_action_get-url-database-backups','wpsc_request_url_backups');
     
    4443    }
    4544    wp_safe_redirect( $url );
    46 
    47 }
    48 
     45}
     46add_action('WPS_action_restore-url-database-backups','wpsc_restore_cloud_database_backup');
    4947
    5048// Delete backup api
     
    6462add_action('WPS_action_delete-backup-api-key','wpsc_delete_backup_api_key');
    6563
     64/*
     65*
     66* Download and restore database file
     67*
     68*/
     69
    6670function wpsc_retreve_db_file(){
    6771    global $wpdb;
     72
     73    // echo "running the new thing";
    6874    $description = 'wpscomplete_base_api';
    6975
    70 
    71     // var_dump($description);
    7276    $keys = $wpdb->get_row(
    7377                $wpdb->prepare( "
     
    7983
    8084    $url = 'https://wpscomplete.com/wp-json/wpscb/v1/retrieve_db_backup_file/';
     85
     86    $site_url = site_url();
     87    $site_url = substr($site_url, 8);
    8188
    8289    // api request to the server
     
    97104            'backup_site_url'       => $_POST['url'],
    98105            'required_backup_file'  => $_POST['required_backup'],
     106            'current_site_url'      => $site_url,
     107            'file_part'             => 0,
    99108        ),
    100109        'cookies'     => array()
     
    111120    }
    112121
    113     $data = $response['body'];
    114     $file_name = $_GET['required_backup'];
     122
     123    $file_size = base64_decode( $response['body'] );
     124    settype($file_size, 'int');
     125
     126    var_dump("File size: ",$file_size);
    115127
    116128    $data_management = new WPS_data_management;
    117129    $dirpath = $data_management->setup_directory_for_restoring();
     130    // var_dump($dirpath);
     131
     132    $file_name = $_GET['required_backup'];
     133    $download_file = $dirpath."/".$file_name;
     134
     135    // var_dump($download_file);
     136
     137
     138    $db_file = fopen( $download_file ,'w' );
     139    $file_divide = 10000;
     140
     141    $i = 1;
     142    $divides = intdiv($file_size, $file_divide);
     143
     144    var_dump(" Divides: ",$divides);
     145
     146    for( $i = 1; $i <= ( $divides + 1 ); $i++){
     147
     148        // api to request file section
     149        // api request to the server
     150        $response = wp_remote_post( $url, array(
     151            'method'      => 'POST',
     152            'timeout'     => 45,
     153            'redirection' => 5,
     154            'httpversion' => '1.0',
     155            'blocking'    => true,
     156            // 'headers'     => array( 
     157            //  'accept'    => 'application/json', // The API returns JSON             
     158            //  'content-type'  => 'application/binary', // Set content type to binary         
     159            // ),
     160            'headers'     => array(),
     161            'body'        => array(
     162                'consumer_key'          => $keys['consumer_key'],
     163                'consumer_secret'       => $keys['consumer_secret'],
     164                'backup_site_url'       => $_POST['url'],
     165                'required_backup_file'  => $_POST['required_backup'],
     166                'current_site_url'      => $site_url,
     167                'file_part'             => $i,
     168            ),
     169            'cookies'     => array()
     170            )
     171        );
     172
     173        $file_data = base64_decode( $response['body'] );
     174        $bytes = fwrite( $db_file , $file_data );
     175    }
     176    $close = fclose( $db_file );
     177    //check our file sizes are correct
     178    if( $file_size != filesize( $download_file ) ){
     179        return 'file_hasnt_completed_download_correctly';
     180    }
     181    // return;
    118182    $result = $data_management->process_file_download_transfer( $dirpath, $data , $file_name );
    119183
    120184    //check the file is ready to be used
    121185    $download_complete = $data_management->check_backup_db_file_exists( 0 , $dirpath , $file_name );
    122 
     186    $download_complete = false;
    123187    if($download_complete){
    124188        $unzip = $data_management->unzip_file( $dirpath , $file_name );
    125         if($unzip){
     189        if( $unzip ){
    126190            $unzipped_file = $data_management->fetch_sql_file( $dirpath );
    127191            $restore = $data_management->wpsc_restore_db_to_site( $dirpath , $unzipped_file ); 
     
    138202
    139203add_action('WPS_action_restore-cloud-backup','wpsc_retreve_db_file');
     204
     205
Note: See TracChangeset for help on using the changeset viewer.