public static function execute( $params ) { $completed = false; // Set offset if ( ! isset( $params['offset'] ) ) { $params['offset'] = 0; } // Set retry if ( ! isset( $params['retry'] ) ) { $params['retry'] = 0; } // Set Gdrive client $gdrive = new ServMaskGdriveClient( get_option( 'ai1wmge_gdrive_token' ), get_option( 'ai1wmge_gdrive_ssl', true ) ); // Get archive file $archive = fopen( ai1wm_archive_path( $params ), 'rb' ); // Read file chunk if ( ( fseek( $archive, $params['offset'] ) !== -1 ) && ( $chunk = fread( $archive, ServMaskGdriveClient::CHUNK_SIZE ) ) ) { // Set chunk size $params['chunkSize'] = ftell( $archive ) - $params['offset']; // Set file size $params['fileSize'] = ai1wm_archive_bytes( $params ); try { // Increase number of retries $params['retry'] += 1; // Upload file chunk $gdrive->uploadFileChunk( $chunk, $params ); } catch ( Exception $e ) { // Retry 3 times if ( $params['retry'] <= 3 ) { return $params; } throw $e; } // Reset retry counter $params['retry'] = 0; // Set archive details $name = ai1wm_archive_name( $params ); $bytes = ai1wm_archive_bytes( $params ); $size = ai1wm_archive_size( $params ); // Get progress if ( isset( $params['offset'] ) ) { $progress = (int) ( ( $params['offset'] / $bytes ) * 100 ); } else { $progress = 100; } // Set progress Ai1wm_Status::info( __( "<i class=\"ai1wm-icon-gdrive\"></i> " . "Uploading <strong>{$name}</strong> ({$size})<br />{$progress}% complete", AI1WMGE_PLUGIN_NAME ) ); } else { // Set last backup date update_option( 'ai1wmge_gdrive_timestamp', current_time( 'timestamp' ) ); // Set progress Ai1wm_Status::done( __( 'Your WordPress archive has been uploaded to Google Drive.', AI1WMGE_PLUGIN_NAME ), __( 'Google Drive', AI1WMGE_PLUGIN_NAME ) ); // Upload completed $completed = true; self::notify_admin_of_new_backup( $params ); } // Close the archive file fclose( $archive ); // Set completed flag $params['completed'] = $completed; return $params; }