public static function execute( $params ) { // Set progress Ai1wm_Status::info( __( 'Connecting to Google Drive...', AI1WMGE_PLUGIN_NAME ) ); // Open achive file $archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) ); // Append EOF block $archive->close( true ); // Set Gdrive client $gdrive = new ServMaskGdriveClient( get_option( 'ai1wmge_gdrive_token' ), get_option( 'ai1wmge_gdrive_ssl', true ) ); // Get or Create folder $folder = $gdrive->listFolder( ai1wm_archive_folder() ); if ( isset( $folder['items'] ) && ( $item = array_shift( $folder['items'] ) ) ) { $folder = $item; } else { $folder = $gdrive->createFolder( ai1wm_archive_folder() ); } // Upload resumable $params['uploadUrl'] = $gdrive->uploadResumable( ai1wm_archive_name( $params ), ai1wm_archive_bytes( $params ), $folder['id'] ); return $params; }
public static function execute( $params ) { // Set progress Ai1wm_Status::info( __( 'Unpacking archive...', AI1WM_PLUGIN_NAME ) ); // Open the archive file for reading $archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) ); // Validate the archive file consistency if ( ! $archive->is_valid() ) { throw new Ai1wm_Import_Exception( __( 'The archive file is corrupted. Follow this article to resolve the problem: ' . '<a href="https://help.servmask.com/knowledgebase/corrupted-archive/" target="_blank">https://help.servmask.com/knowledgebase/corrupted-archive/</a>', AI1WM_PLUGIN_NAME ) ); } // Obtain the name of the archive $name = ai1wm_archive_name( $params ); // Obtain the size of the archive $size = ai1wm_archive_bytes( $params ); // Check file size of the archive if ( false === $size ) { throw new Ai1wm_Not_Accesible_Exception( sprintf( __( 'Unable to get the file size of <strong>%s</strong>', AI1WM_PLUGIN_NAME ), $name ) ); } $allowed_size = apply_filters( 'ai1wm_max_file_size', AI1WM_MAX_FILE_SIZE ); // Let's check the size of the file to make sure it is less than the maximum allowed if ( ( $allowed_size > 0 ) && ( $size > $allowed_size ) ) { throw new Ai1wm_Import_Exception( sprintf( __( 'The file that you are trying to import is over the maximum upload file size limit of <strong>%s</strong>.<br />' . 'You can remove this restriction by purchasing our ' . '<a href="https://servmask.com/products/unlimited-extension" target="_blank">Unlimited Extension</a>.', AI1WM_PLUGIN_NAME ), size_format( $allowed_size ) ) ); } // Unpack package.json, multisite.json and database.sql files $archive->extract_by_files_array( ai1wm_storage_path( $params ), array( AI1WM_PACKAGE_NAME, AI1WM_MULTISITE_NAME, AI1WM_DATABASE_NAME, ) ); // Close the archive file $archive->close(); // Check package.json file if ( false === is_file( ai1wm_package_path( $params ) ) ) { throw new Ai1wm_Import_Exception( __( 'Invalid archive file. It should contain <strong>package.json</strong> file.', AI1WM_PLUGIN_NAME ) ); } return $params; }
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 Dropbox client $dropbox = new ServMaskDropboxClient(get_option('ai1wmde_dropbox_token'), get_option('ai1wmde_dropbox_ssl', true)); // Get archive file $archive = fopen(ai1wm_archive_path($params), 'rb'); // Read file chunk if (fseek($archive, $params['offset']) !== -1 && ($chunk = fread($archive, ServMaskDropboxClient::CHUNK_SIZE))) { try { // Increase number of retries $params['retry'] += 1; // Upload file chunk $dropbox->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-dropbox\"></i> " . "Uploading <strong>{$name}</strong> ({$size})<br />{$progress}% complete", AI1WMDE_PLUGIN_NAME)); } else { // Set archive details $name = ai1wm_archive_name($params); $folder = ai1wm_archive_folder(); // Commit upload file chunk $dropbox->uploadFileChunkCommit(sprintf('%s/%s', $folder, $name), $params); // Set last backup date update_option('ai1wmde_dropbox_timestamp', current_time('timestamp')); // Set progress Ai1wm_Status::done(__('Your WordPress archive has been uploaded to Dropbox.', AI1WMDE_PLUGIN_NAME), __('Dropbox', AI1WMDE_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; }
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; }