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;
	}
Example #2
0
/**
 * Get backups URL address
 *
 * @param  array  $params Request parameters
 * @return string
 */
function ai1wm_backups_url($params)
{
    return AI1WM_BACKUPS_URL . '/' . ai1wm_archive_name($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 notify_admin_of_new_backup($params)
 {
     $recipient = get_option('ai1wmde_dropbox_notify_email', get_option('admin_email', ''));
     if (self::is_notification_enabled($recipient)) {
         $subject = __('Dropbox Backup report', AI1WMDE_PLUGIN_NAME);
         $message = sprintf(__("Your site %s was successfully exported to Dropbox.\n", AI1WMDE_PLUGIN_NAME), site_url());
         $message .= "\n\n";
         $message .= sprintf(__("Date: %s\n", AI1WMDE_PLUGIN_NAME), date('r'));
         $message .= sprintf(__("Backup file: %s\n", AI1WMDE_PLUGIN_NAME), ai1wm_archive_name($params));
         $message .= sprintf(__("Size: %s\n", AI1WMDE_PLUGIN_NAME), ai1wm_archive_size($params));
         wp_mail($recipient, $subject, $message);
     }
 }