public static function execute( $params ) { $completed = false; // File ID if ( ! isset( $params['fileId'] ) ) { throw new Ai1wm_Import_Exception( __( 'Google Drive File ID is not specified. ', AI1WMGE_PLUGIN_NAME ) ); } // Set startBytes if ( ! isset( $params['startBytes'] ) ) { $params['startBytes'] = 0; } // Set endBytes if ( ! isset( $params['endBytes'] ) ) { $params['endBytes'] = ServMaskGdriveClient::CHUNK_SIZE; } // Set retry if ( ! isset( $params['retry'] ) ) { $params['retry'] = 0; } // Set Google Drive client $gdrive = new ServMaskGdriveClient( get_option( 'ai1wmge_gdrive_token' ), get_option( 'ai1wmge_gdrive_ssl', true ) ); // Get archive file $archive = fopen( ai1wm_archive_path( $params ), 'ab' ); try { // Increase number of retries $params['retry'] += 1; // Download file chunk $gdrive->getFile( $params['fileId'], $archive, $params ); } catch ( Exception $e ) { // Retry 3 times if ( $params['retry'] <= 3 ) { return $params; } throw $e; } // Reset retry counter $params['retry'] = 0; // Close the archive file fclose( $archive ); // Calculate percent $percent = (int) ( ( $params['startBytes'] / $params['totalBytes'] ) * 100 ); // Set progress Ai1wm_Status::progress( $percent ); // Next file chunk if ( empty( $params['totalBytes'] ) ) { throw new Ai1wm_Import_Exception( 'Unable to import the archive! Please check file size parameter. '); } else if ( $params['totalBytes'] == $params['startBytes'] ) { $completed = true; } // Set completed flag $params['completed'] = $completed; return $params; }