public static function resolve($args = array())
 {
     // Set error handler
     @set_error_handler('Ai1wm_Log::error_handler');
     // Set arguments
     if (empty($args)) {
         $args = ai1wm_urldecode($_REQUEST);
     }
     // Set secret key
     $secret_key = null;
     if (isset($args['secret_key'])) {
         $secret_key = $args['secret_key'];
     }
     // Verify secret key by using the value in the database, not in cache
     if ($secret_key !== get_site_option(AI1WM_SECRET_KEY, false, false)) {
         Ai1wm_Status::set(array('type' => 'error', 'title' => __("Unable to resolve", AI1WM_PLUGIN_NAME), 'message' => __("Unable to authenticate your request with secret_key = \"{$secret_key}\"", AI1WM_PLUGIN_NAME)));
         exit;
     }
     // Set IP address
     if (isset($args['url_ip']) && ($ip = $args['url_ip'])) {
         update_site_option(AI1WM_URL_IP, $ip);
     }
     // Set transport layer
     if (isset($args['url_transport']) && ($transport = $args['url_transport'])) {
         if ($transport === 'curl') {
             update_site_option(AI1WM_URL_TRANSPORT, array('curl', 'ai1wm'));
         } else {
             update_site_option(AI1WM_URL_TRANSPORT, array('ai1wm', 'curl'));
         }
     }
 }
	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 ) {
		$messages = Ai1wm_Compatibility::get( $params );

		// Set messages
		if ( empty( $messages ) ) {
			return $params;
		}

		// Set progress
		Ai1wm_Status::error( implode( $messages ) );

		// Manual export
		if ( empty( $params['ai1wm_manual_export'] ) ) {
			if ( function_exists( 'wp_mail' ) ) {
				// Set recipient
				$recipient = get_option( 'admin_email', '' );

				// Set subject
				$subject = __( 'Unable to backup your site', AI1WM_PLUGIN_NAME );

				// Set message
				$message = sprintf( __( 'All-in-One WP Migration was unable to backup %s. %s', AI1WM_PLUGIN_NAME ), site_url(), implode( $messages ) );

				// Send email
				wp_mail( $recipient, $subject, $message );
			}
		}

		exit;
	}
	public function export() {
		// Set progress
		Ai1wm_Status::set( array( 'message' => __( 'Renaming exported file...', AI1WM_PLUGIN_NAME ) ) );

		// Close achive file
		$archive = new Ai1wm_Compressor( $this->storage()->archive() );

		// Append EOF block
		$archive->close( true );

		// Rename archive file
		if ( rename( $this->storage()->archive(), $this->storage()->backup() ) ) {

			// Set progress
			Ai1wm_Status::set(
				array(
					'type'    => 'download',
					'message' => sprintf(
						__(
							'<a href="%s/%s" class="ai1wm-button-green ai1wm-emphasize">' .
							'<span>Download %s</span>' .
							'<em>Size: %s</em>' .
							'</a>',
							AI1WM_PLUGIN_NAME
						),
						AI1WM_BACKUPS_URL,
						basename( $this->storage()->backup() ),
						parse_url( home_url(), PHP_URL_HOST ),
						size_format( filesize( $this->storage()->backup() ) )
					)
				),
				$this->storage()->status() // status.log file
			);
		}
	}
 public static function resolve($params = array())
 {
     // Set error handler
     @set_error_handler('Ai1wm_Handler::error');
     // Set params
     if (empty($params)) {
         $params = ai1wm_urldecode($_REQUEST);
     }
     // Set secret key
     $secret_key = null;
     if (isset($params['secret_key'])) {
         $secret_key = $params['secret_key'];
     }
     // Verify secret key by using the value in the database, not in cache
     if ($secret_key !== get_option(AI1WM_SECRET_KEY)) {
         Ai1wm_Status::error(sprintf(__('Unable to authenticate your request with secret_key = "%s"', AI1WM_PLUGIN_NAME), $secret_key), __('Unable to resolve', AI1WM_PLUGIN_NAME));
         exit;
     }
     // Set IP address
     if (isset($params['url_ip']) && ($ip = $params['url_ip'])) {
         update_option(AI1WM_URL_IP, $ip);
     }
     // Set adapter
     if (isset($params['url_adapter']) && ($adapter = $params['url_adapter'])) {
         if ($adapter === 'curl') {
             update_option(AI1WM_URL_ADAPTER, 'curl');
         } else {
             update_option(AI1WM_URL_ADAPTER, 'stream');
         }
     }
 }
 public static function import($params = array())
 {
     global $wp_filter;
     // Set error handler
     @set_error_handler('Ai1wm_Handler::error');
     // Set params
     if (empty($params)) {
         $params = ai1wm_urldecode($_REQUEST);
     }
     // Set priority
     $priority = 10;
     if (isset($params['priority'])) {
         $priority = (int) $params['priority'];
     }
     // Set secret key
     $secret_key = null;
     if (isset($params['secret_key'])) {
         $secret_key = $params['secret_key'];
     }
     // Verify secret key by using the value in the database, not in cache
     if ($secret_key !== get_option(AI1WM_SECRET_KEY)) {
         Ai1wm_Status::error(sprintf(__('Unable to authenticate your request with secret_key = "%s"', AI1WM_PLUGIN_NAME), $secret_key), __('Unable to import', AI1WM_PLUGIN_NAME));
         exit;
     }
     // Get hook
     if (isset($wp_filter['ai1wm_import']) && ($filters = $wp_filter['ai1wm_import']) && ksort($filters)) {
         while ($hooks = current($filters)) {
             if ($priority == key($filters)) {
                 foreach ($hooks as $hook) {
                     try {
                         $params = call_user_func_array($hook['function'], array($params));
                     } catch (Ai1wm_Import_Retry_Exception $exception) {
                         status_header($exception->getCode());
                         echo json_encode(array('message' => $exception->getMessage()));
                         exit;
                     } catch (Exception $e) {
                         Ai1wm_Status::error($e->getMessage(), __('Unable to import', AI1WM_PLUGIN_NAME));
                         exit;
                     }
                 }
                 // Set completed
                 $completed = true;
                 if (isset($params['completed'])) {
                     $completed = (bool) $params['completed'];
                 }
                 // Log request
                 if (empty($params['priority']) || is_file(ai1wm_import_path($params))) {
                     Ai1wm_Log::import($params);
                 }
                 // Do request
                 if ($completed === false || ($next = next($filters)) && ($params['priority'] = key($filters))) {
                     return Ai1wm_Http::get(admin_url('admin-ajax.php?action=ai1wm_import'), $params);
                 }
             }
             next($filters);
         }
     }
 }
 public static function execute($params)
 {
     // Set progress
     Ai1wm_Status::info(__('Connecting to Dropbox...', AI1WMDE_PLUGIN_NAME));
     // Open archive file
     $archive = new Ai1wm_Compressor(ai1wm_archive_path($params));
     // Append EOF block
     $archive->close(true);
     return $params;
 }
 public static function execute($params)
 {
     // Set progress
     Ai1wm_Status::info(__('Creating an empty archive...', AI1WMDE_PLUGIN_NAME));
     // Create empty archive file
     $archive = new Ai1wm_Compressor(ai1wm_archive_path($params));
     $archive->close();
     // Set progress
     Ai1wm_Status::info(__('Done creating an empty archive.', AI1WMDE_PLUGIN_NAME));
     return $params;
 }
	public static function execute( $params ) {

		// Set progress
		Ai1wm_Status::confirm( __(
			'The import process will overwrite your database, media, plugins, and themes. ' .
			'Please ensure that you have a backup of your data before proceeding to the next step.',
			AI1WM_PLUGIN_NAME
		) );

		exit;
	}
Ejemplo n.º 10
0
 public static function import($args = array())
 {
     // Set error handler
     @set_error_handler('Ai1wm_Log::error_handler');
     try {
         // Set arguments
         if (empty($args)) {
             $args = ai1wm_urldecode($_REQUEST);
         }
         // Set storage path
         if (empty($args['storage'])) {
             $args['storage'] = uniqid();
         }
         // Set secret key
         $secret_key = null;
         if (isset($args['secret_key'])) {
             $secret_key = $args['secret_key'];
         }
         // Verify secret key by using the value in the database, not in cache
         if ($secret_key !== get_site_option(AI1WM_SECRET_KEY, false, false)) {
             throw new Ai1wm_Import_Exception(sprintf(__('Unable to authenticate your request with secret_key = <strong>"%s"</strong>', AI1WM_PLUGIN_NAME), $secret_key));
         }
         // Set provider
         $provider = null;
         if (isset($args['provider'])) {
             $provider = $args['provider'];
         }
         $class = "Ai1wm_Import_{$provider}";
         if (!class_exists($class)) {
             throw new Ai1wm_Import_Exception(sprintf(__('Unknown provider: <strong>"%s"</strong>', AI1WM_PLUGIN_NAME), $class));
         }
         // Set method
         $method = null;
         if (isset($args['method'])) {
             $method = $args['method'];
         }
         // Initialize provider
         $provider = new $class($args);
         if (!method_exists($provider, $method)) {
             throw new Ai1wm_Import_Exception(sprintf(__('Unknown method: <strong>"%s"</strong>', AI1WM_PLUGIN_NAME), $method));
         }
         // Invoke method
         echo json_encode($provider->{$method}());
         exit;
     } catch (Exception $e) {
         // Log the error
         Ai1wm_Log::error('Exception while importing: ' . $e->getMessage());
         // Set the status to failed
         Ai1wm_Status::set(array('type' => 'error', 'title' => __('Unable to import', AI1WM_PLUGIN_NAME), 'message' => $e->getMessage()));
         // End the process
         wp_die('Exception while importing: ' . $e->getMessage());
     }
 }
	public static function execute( $params ) {

		// Set progress
		Ai1wm_Status::info( __( 'Resolving URL address...', AI1WM_PLUGIN_NAME ) );

		// HTTP resolve
		Ai1wm_Http::resolve( admin_url( 'admin-ajax.php?action=ai1wm_resolve' ) );

		// Set progress
		Ai1wm_Status::info( __( 'Done resolving URL address...', AI1WM_PLUGIN_NAME ) );

		return $params;
	}
	public static function execute( $params ) {
		$messages = Ai1wm_Compatibility::get( $params );

		// Set messages
		if ( empty( $messages ) ) {
			return $params;
		}

		// Set progress
		Ai1wm_Status::error( implode( $messages ) );

		exit;
	}
 public static function execute($params)
 {
     $completed = false;
     // Set startBytes
     if (!isset($params['startBytes'])) {
         $params['startBytes'] = 0;
     }
     // Set endBytes
     if (!isset($params['endBytes'])) {
         $params['endBytes'] = ServMaskDropboxClient::CHUNK_SIZE;
     }
     // 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), 'ab');
     try {
         // Increase number of retries
         $params['retry'] += 1;
         // Download file chunk
         $dropbox->getFile($params['filePath'], $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;
 }
	public static function execute( $params ) {
		global $wp_version;

		// Set progress
		Ai1wm_Status::info( __( 'Adding configuration to archive...', AI1WM_PLUGIN_NAME ) );

		// Initialize empty WP cache
		wp_cache_init();

		// Get options
		$options = wp_load_alloptions();

		// Set config
		$config = new Ai1wm_Config;

		// Set Site URL
		if ( isset( $options['siteurl'] ) ) {
			$config->SiteURL = untrailingslashit( $options['siteurl'] );
		} else {
			$config->SiteURL = site_url();
		}

		// Set Home URL
		if ( isset( $options['home'] ) ) {
			$config->HomeURL = untrailingslashit( $options['home'] );
		} else {
			$config->HomeURL = home_url();
		}

		// Set Plugin Version
		$config->Plugin = (object) array( 'Version' => AI1WM_VERSION );

		// Set WordPress Version and Content
		$config->WordPress = (object) array( 'Version' => $wp_version, 'Content' => WP_CONTENT_DIR );

		// Save package.json file
		$handle = fopen( ai1wm_package_path( $params ), 'w' );
		fwrite( $handle, json_encode( $config ) );
		fclose( $handle );

		// Add package.json file
		$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
		$archive->add_file( ai1wm_package_path( $params ), AI1WM_PACKAGE_NAME );
		$archive->close();

		// Set progress
		Ai1wm_Status::info( __( 'Done adding configuration to archive.', AI1WM_PLUGIN_NAME ) );

		return $params;
	}
 public static function execute($params)
 {
     // Set progress
     Ai1wm_Status::info(__('Activating plugins...', AI1WM_PLUGIN_NAME));
     // Open the archive file for reading
     $archive = new Ai1wm_Extractor(ai1wm_archive_path($params));
     // Include WordPress files
     $include_files = array_keys(_get_dropins());
     // Include mu-plugins files
     $include_files = array_merge($include_files, array(AI1WM_MUPLUGINS_NAME));
     // Unpack WordPress files and mu-plugins files
     $archive->extract_by_files_array(WP_CONTENT_DIR, $include_files);
     // Close the archive file
     $archive->close();
     // Set progress
     Ai1wm_Status::info(__('Done activating plugins...', AI1WM_PLUGIN_NAME));
     return $params;
 }
 public static function execute($params)
 {
     global $wp_version;
     // Set progress
     Ai1wm_Status::info(__('Adding configuration to archive...', AI1WM_PLUGIN_NAME));
     // Flush WP cache
     ai1wm_cache_flush();
     // Get options
     $options = wp_load_alloptions();
     // Set config
     $config = array();
     // Set Site URL
     if (isset($options['siteurl'])) {
         $config['SiteURL'] = untrailingslashit($options['siteurl']);
     } else {
         $config['SiteURL'] = site_url();
     }
     // Set Home URL
     if (isset($options['home'])) {
         $config['HomeURL'] = untrailingslashit($options['home']);
     } else {
         $config['HomeURL'] = home_url();
     }
     // Set Plugin Version
     $config['Plugin'] = array('Version' => AI1WM_VERSION);
     // Set WordPress Version and Content
     $config['WordPress'] = array('Version' => $wp_version, 'Content' => WP_CONTENT_DIR);
     // Set No Replace Email
     if (isset($params['options']['no_email_replace'])) {
         $config['NoEmailReplace'] = true;
     }
     // Save package.json file
     $handle = fopen(ai1wm_package_path($params), 'w');
     fwrite($handle, json_encode($config));
     fclose($handle);
     // Add package.json file
     $archive = new Ai1wm_Compressor(ai1wm_archive_path($params));
     $archive->add_file(ai1wm_package_path($params), AI1WM_PACKAGE_NAME);
     $archive->close();
     // Set progress
     Ai1wm_Status::info(__('Done adding configuration to archive.', AI1WM_PLUGIN_NAME));
     return $params;
 }
 public static function execute($params)
 {
     // Set progress
     Ai1wm_Status::info(__('Preparing blogs...', AI1WM_PLUGIN_NAME));
     $blogs = array();
     // Check multisite.json file
     if (true === is_file(ai1wm_multisite_path($params))) {
         // Read multisite.json file
         $handle = fopen(ai1wm_multisite_path($params), 'r');
         if ($handle === false) {
             throw new Ai1wm_Import_Exception(__('Unable to read multisite.json file', AI1WM_PLUGIN_NAME));
         }
         // Parse multisite.json file
         $multisite = fread($handle, filesize(ai1wm_multisite_path($params)));
         $multisite = json_decode($multisite, true);
         // Close handle
         fclose($handle);
         // Validate
         if (empty($multisite['Network'])) {
             if (isset($multisite['Sites']) && ($sites = $multisite['Sites'])) {
                 if (count($sites) === 1 && ($site = current($sites))) {
                     $blogs[] = array('Old' => array('BlogID' => $site['BlogID'], 'SiteURL' => $site['SiteURL'], 'HomeURL' => $site['HomeURL']), 'New' => array('BlogID' => null, 'SiteURL' => site_url(), 'HomeURL' => home_url()));
                 } else {
                     throw new Ai1wm_Import_Exception(__('The archive should contain <strong>Single WordPress</strong> site! Please revisit your export settings.', AI1WM_PLUGIN_NAME));
                 }
             } else {
                 throw new Ai1wm_Import_Exception(__('At least <strong>one WordPress</strong> site should be presented in the archive.', AI1WM_PLUGIN_NAME));
             }
         } else {
             throw new Ai1wm_Import_Exception(__('Unable to import <strong>WordPress Network</strong> into WordPress <strong>Single</strong> site.', AI1WM_PLUGIN_NAME));
         }
     }
     // Save blogs.json file
     $handle = fopen(ai1wm_blogs_path($params), 'w');
     fwrite($handle, json_encode($blogs));
     fclose($handle);
     // Set progress
     Ai1wm_Status::info(__('Done preparing blogs...', AI1WM_PLUGIN_NAME));
     return $params;
 }
	public static function execute( $params ) {

		// Set progress
		Ai1wm_Status::info( __( 'Retrieving a list of all WordPress files...', AI1WM_PLUGIN_NAME ) );

		// Open the archive file for reading
		$archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );

		// Get total files
		$params['total_files'] = $archive->get_total_files();

		// Get total size
		$params['total_size'] = $archive->get_total_size();

		// Close the archive file
		$archive->close();

		// Set progress
		Ai1wm_Status::info( __( 'Done retrieving a list of all WordPress files.', AI1WM_PLUGIN_NAME ) );

		return $params;
	}
	public static function execute( $params ) {

		// Set progress
		Ai1wm_Status::info( __( 'Renaming exported file...', AI1WM_PLUGIN_NAME ) );

		// Close achive file
		$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );

		// Append EOF block
		$archive->close( true );

		// Rename archive file
		if ( rename( ai1wm_archive_path( $params ), ai1wm_download_path( $params ) ) ) {

			// Set archive details
			$link = ai1wm_backups_url( $params );
			$size = ai1wm_download_size( $params );
			$name = ai1wm_site_name();

			// Set progress
			Ai1wm_Status::download(
				sprintf(
					__(
						'<a href="%s" class="ai1wm-button-green ai1wm-emphasize">' .
						'<span>Download %s</span>' .
						'<em>Size: %s</em>' .
						'</a>',
						AI1WM_PLUGIN_NAME
					),
					$link,
					$name,
					$size
				)
			);
		}

		return $params;
	}
	public static function execute( $params ) {

		// Set progress
		Ai1wm_Status::info( __( 'Resolving URL address...', AI1WM_PLUGIN_NAME ) );

		// HTTP resolve
		Ai1wm_Http::resolve( admin_url( 'admin-ajax.php?action=ai1wm_resolve' ) );

		// Set archive
		if ( empty( $params['archive'] ) ) {
			$params['archive'] = ai1wm_archive_file();
		}

		// Set storage
		if ( empty( $params['storage'] ) ) {
			$params['storage'] = ai1wm_storage_folder();
		}

		// Set progress
		Ai1wm_Status::info( __( 'Done resolving URL address...', AI1WM_PLUGIN_NAME ) );

		return $params;
	}
 public static function execute($params)
 {
     // Check multisite.json file
     if (true === is_file(ai1wm_multisite_path($params))) {
         // Read multisite.json file
         $handle = fopen(ai1wm_multisite_path($params), 'r');
         if ($handle === false) {
             throw new Ai1wm_Import_Exception(__('Unable to read multisite.json file', AI1WM_PLUGIN_NAME));
         }
         // Parse multisite.json file
         $multisite = fread($handle, filesize(ai1wm_multisite_path($params)));
         $multisite = json_decode($multisite, true);
         // Close handle
         fclose($handle);
         // Activate plugins
         if (isset($multisite['Plugins']) && ($active_sitewide_plugins = $multisite['Plugins'])) {
             activate_plugins($active_sitewide_plugins, null, is_multisite(), true);
         }
     }
     // Set progress
     Ai1wm_Status::done(sprintf(__('You need to perform two more steps:<br />' . '<strong>1. You must save your permalinks structure twice. <a class="ai1wm-no-underline" href="%s" target="_blank">Permalinks Settings</a></strong> <small>(opens a new window)</small><br />' . '<strong>2. <a class="ai1wm-no-underline" href="https://wordpress.org/support/view/plugin-reviews/all-in-one-wp-migration?rate=5#postform" target="_blank">Optionally, review the plugin</a>.</strong> <small>(opens a new window)</small>', AI1WM_PLUGIN_NAME), admin_url('options-permalink.php#submit')), __('Your data has been imported successfuly!', AI1WM_PLUGIN_NAME));
     return $params;
 }
	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;
	}
	public static function execute( $params ) {

		// Set content offset
		if ( isset( $params['content_offset'] ) ) {
			$content_offset = (int) $params['content_offset'];
		} else {
			$content_offset = 0;
		}
		// Set filemap offset
		if ( isset( $params['filemap_offset'] ) ) {
			$filemap_offset = (int) $params['filemap_offset'];
		} else {
			$filemap_offset = 0;
		}

		// Get total files
		if ( isset( $params['total_files'] ) ) {
			$total_files = (int) $params['total_files'];
		} else {
			$total_files = 1;
		}

		// Get total size
		if ( isset( $params['total_size'] ) ) {
			$total_size = (int) $params['total_size'];
		} else {
			$total_size = 1;
		}

		// Get processed files
		if ( isset( $params['processed'] ) ) {
			$processed = (int) $params['processed'];
		} else {
			$processed = 0;
		}

		// What percent of files have we processed?
		$progress = (int) ( ( $processed / $total_size ) * 100 );

		// Set progress
		if ( empty( $content_offset ) ) {
			Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );
		}

		// Get map file
		$filemap = fopen( ai1wm_filemap_path( $params ), 'r' );

		// Start time
		$start = microtime( true );

		// Flag to hold if all files have been processed
		$completed = true;

		// Set filemap pointer at the current index
		if ( fseek( $filemap, $filemap_offset ) !== -1 ) {

			// Get archive
			$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );

			while ( $path = trim( fgets( $filemap ) ) ) {
				try {

					// Add file to archive
					if ( ( $content_offset = $archive->add_file( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $path, $path, $content_offset, 10 ) ) ) {

						// Set progress
						if ( ( $processed += $content_offset ) ) {
							$progress = (int) ( ( $processed / $total_size ) * 100 );
						}

						// Set progress
						Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );

						// Set content offset
						$params['content_offset'] = $content_offset;

						// Set filemap offset
						$params['filemap_offset'] = $filemap_offset;

						// Set completed flag
						$params['completed'] = false;

						// Close the filemap file
						fclose( $filemap );

						return $params;
					}

					// Set content offset
					$content_offset = 0;

					// Set filemap offset
					$filemap_offset = ftell( $filemap );

				} catch ( Exception $e ) {
					// Skip bad file permissions
				}

				// Increment processed files
				$processed += $archive->get_current_filesize();

				// More than 10 seconds have passed, break and do another request
				if ( ( microtime( true ) - $start ) > 10 ) {
					$completed = false;
					break;
				}
			}

			$archive->close();
		}

		// Set content offset
		$params['content_offset'] = $content_offset;

		// Set filemap offset
		$params['filemap_offset'] = $filemap_offset;

		// Set processed files
		$params['processed'] = $processed;

		// Set completed flag
		$params['completed'] = $completed;

		// Close the filemap file
		fclose( $filemap );

		return $params;
	}
	public static function execute( $params ) {

		// Read blogs.json file
		$handle = fopen( ai1wm_blogs_path( $params ), 'r' );
		if ( $handle === false ) {
			throw new Ai1wm_Import_Exception( 'Unable to read blogs.json file' );
		}

		// Parse blogs.json file
		$blogs = fread( $handle, filesize( ai1wm_blogs_path( $params ) ) );
		$blogs = json_decode( $blogs );

		// Close handle
		fclose( $handle );

		// Set content offset
		if ( isset( $params['content_offset'] ) ) {
			$content_offset = (int) $params['content_offset'];
		} else {
			$content_offset = 0;
		}

		// Set archive offset
		if ( isset( $params['archive_offset']) ) {
			$archive_offset = (int) $params['archive_offset'];
		} else {
			$archive_offset = 0;
		}

		// Get total files
		if ( isset( $params['total_files'] ) ) {
			$total_files = (int) $params['total_files'];
		} else {
			$total_files = 1;
		}

		// Get total size
		if ( isset( $params['total_size'] ) ) {
			$total_size = (int) $params['total_size'];
		} else {
			$total_size = 1;
		}

		// Get processed files
		if ( isset( $params['processed'] ) ) {
			$processed = (int) $params['processed'];
		} else {
			$processed = 0;
		}

		// What percent of files have we processed?
		$progress = (int) ( ( $processed / $total_size ) * 100 );

		// Set progress
		if ( empty( $content_offset ) ) {
			Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );
		}

		// Start time
		$start = microtime( true );

		// Flag to hold if all files have been processed
		$completed = true;

		// Open the archive file for reading
		$archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );

		// Set the file pointer to the one that we have saved
		$archive->set_file_pointer( null, $archive_offset );

		$old_paths = array();
		$new_paths = array();

		// Set extract paths
		foreach ( $blogs as $blog ) {
			$old_paths[] = ai1wm_sites_path( $blog->Old->Id );
			$new_paths[] = ai1wm_sites_path( $blog->New->Id );
		}

		while ( $archive->has_not_reached_eof() ) {
			try {

				// Extract a file from archive to WP_CONTENT_DIR
				if ( ( $content_offset = $archive->extract_one_file_to( WP_CONTENT_DIR, array( AI1WM_PACKAGE_NAME, AI1WM_MULTISITE_NAME, AI1WM_DATABASE_NAME, AI1WM_MUPLUGINS_NAME ), $old_paths, $new_paths, $content_offset, 10 ) ) ) {

					// Set progress
					if ( ( $processed += $content_offset ) ) {
						$progress = (int) ( ( $processed / $total_size ) * 100 );
					}

					// Set progress
					Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );

					// Set content offset
					$params['content_offset'] = $content_offset;

					// Set archive offset
					$params['archive_offset'] = $archive_offset;

					// Set completed flag
					$params['completed'] = false;

					// Close the archive file
					$archive->close();

					return $params;
				}

				// Set content offset
				$content_offset = 0;

				// Set archive offset
				$archive_offset = $archive->get_file_pointer();

			} catch ( Exception $e ) {
				// Skip bad file permissions
			}

			// Increment processed files
			$processed += $archive->get_current_filesize();

			// More than 10 seconds have passed, break and do another request
			if ( ( microtime( true ) - $start ) > 10 ) {
				$completed = false;
				break;
			}
		}

		// Set content offset
		$params['content_offset'] = $content_offset;

		// Set archive offset
		$params['archive_offset'] = $archive_offset;

		// Set processed files
		$params['processed'] = $processed;

		// Set completed flag
		$params['completed'] = $completed;

		// Close the archive file
		$archive->close();

		return $params;
	}
 /**
  * Add database
  *
  * @return void
  */
 public function database()
 {
     // Set exclude database
     if ($this->should_exclude_database()) {
         // Disable maintenance mode
         Ai1wm_Maintenance::disable();
         // Redirect
         return $this->route_to('export');
     }
     // Set progress
     Ai1wm_Status::set(array('message' => __('Exporting database...', AI1WM_PLUGIN_NAME)));
     // Get databsae file
     $service = new Ai1wm_Service_Database($this->args);
     $service->export();
     // Get archive file
     $archive = new Ai1wm_Compressor($this->storage()->archive());
     // Add database to archive
     $archive->add_file($this->storage()->database(), AI1WM_DATABASE_NAME);
     $archive->close();
     // Set progress
     Ai1wm_Status::set(array('message' => __('Done exporting database.', AI1WM_PLUGIN_NAME)));
     // Disable maintenance mode
     Ai1wm_Maintenance::disable();
     // Redirect
     $this->route_to('export');
 }
 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)
 {
     global $wpdb;
     // Skip database import
     if (!is_file(ai1wm_database_path($params))) {
         return $params;
     }
     // Read blogs.json file
     $handle = fopen(ai1wm_blogs_path($params), 'r');
     if ($handle === false) {
         throw new Ai1wm_Import_Exception('Unable to read blogs.json file');
     }
     // Parse blogs.json file
     $blogs = fread($handle, filesize(ai1wm_blogs_path($params)));
     $blogs = json_decode($blogs);
     // Close handle
     fclose($handle);
     // Read package.json file
     $handle = fopen(ai1wm_package_path($params), 'r');
     if ($handle === false) {
         throw new Ai1wm_Import_Exception('Unable to read package.json file');
     }
     // Parse package.json file
     $config = fread($handle, filesize(ai1wm_package_path($params)));
     $config = json_decode($config);
     // Close handle
     fclose($handle);
     // Set progress
     Ai1wm_Status::info(__('Restoring database...', AI1WM_PLUGIN_NAME));
     $old_values = array();
     $new_values = array();
     // Get Blog URLs
     foreach ($blogs as $blog) {
         // Get blogs dir Upload Path
         if (!in_array(sprintf("'%s'", trim(ai1wm_blogsdir_path($blog->Old->Id), '/')), $old_values)) {
             $old_values[] = sprintf("'%s'", trim(ai1wm_blogsdir_path($blog->Old->Id), '/'));
             $new_values[] = sprintf("'%s'", get_option('upload_path'));
         }
         // Get sites Upload Path
         if (!in_array(sprintf("'%s'", trim(ai1wm_uploads_path($blog->Old->Id), '/')), $old_values)) {
             $old_values[] = sprintf("'%s'", trim(ai1wm_uploads_path($blog->Old->Id), '/'));
             $new_values[] = sprintf("'%s'", get_option('upload_path'));
         }
         // Handle old and new sites dir style
         if (defined('UPLOADBLOGSDIR')) {
             // Get Upload Path
             if (!in_array(ai1wm_blogsdir_path($blog->Old->Id), $old_values)) {
                 $old_values[] = ai1wm_blogsdir_path($blog->Old->Id);
                 $new_values[] = ai1wm_blogsdir_path($blog->New->Id);
             }
             // Get escaped Upload Path
             if (!in_array(addslashes(addcslashes(ai1wm_blogsdir_path($blog->Old->Id), '\\/')), $old_values)) {
                 $old_values[] = addslashes(addcslashes(ai1wm_blogsdir_path($blog->Old->Id), '\\/'));
                 $new_values[] = addslashes(addcslashes(ai1wm_blogsdir_path($blog->New->Id), '\\/'));
             }
             // Get Upload Path
             if (!in_array(ai1wm_uploads_path($blog->Old->Id), $old_values)) {
                 $old_values[] = ai1wm_uploads_path($blog->Old->Id);
                 $new_values[] = ai1wm_blogsdir_path($blog->New->Id);
             }
             // Get escaped Upload Path
             if (!in_array(addslashes(addcslashes(ai1wm_uploads_path($blog->Old->Id), '\\/')), $old_values)) {
                 $old_values[] = addslashes(addcslashes(ai1wm_uploads_path($blog->Old->Id), '\\/'));
                 $new_values[] = addslashes(addcslashes(ai1wm_blogsdir_path($blog->New->Id), '\\/'));
             }
         } else {
             // Get Upload Path
             if (!in_array(ai1wm_blogsdir_path($blog->Old->Id), $old_values)) {
                 $old_values[] = ai1wm_blogsdir_path($blog->Old->Id);
                 $new_values[] = ai1wm_uploads_path($blog->New->Id);
             }
             // Get escaped Upload Path
             if (!in_array(addslashes(addcslashes(ai1wm_blogsdir_path($blog->Old->Id), '\\/')), $old_values)) {
                 $old_values[] = addslashes(addcslashes(ai1wm_blogsdir_path($blog->Old->Id), '\\/'));
                 $new_values[] = addslashes(addcslashes(ai1wm_uploads_path($blog->New->Id), '\\/'));
             }
             // Get Upload Path
             if (!in_array(ai1wm_uploads_path($blog->Old->Id), $old_values)) {
                 $old_values[] = ai1wm_uploads_path($blog->Old->Id);
                 $new_values[] = ai1wm_uploads_path($blog->New->Id);
             }
             // Get escaped Upload Path
             if (!in_array(addslashes(addcslashes(ai1wm_uploads_path($blog->Old->Id), '\\/')), $old_values)) {
                 $old_values[] = addslashes(addcslashes(ai1wm_uploads_path($blog->Old->Id), '\\/'));
                 $new_values[] = addslashes(addcslashes(ai1wm_uploads_path($blog->New->Id), '\\/'));
             }
         }
         // Get Site URL
         if (isset($blog->Old->SiteURL) && $blog->Old->SiteURL !== $blog->New->SiteURL) {
             // Get domain
             $old_domain = parse_url($blog->Old->SiteURL, PHP_URL_HOST);
             $new_domain = parse_url($blog->New->SiteURL, PHP_URL_HOST);
             // Get scheme
             $new_scheme = parse_url($blog->New->SiteURL, PHP_URL_SCHEME);
             // Replace Site URL scheme
             foreach (array('http', 'https') as $old_scheme) {
                 // Add plain Site URL
                 if (!in_array(set_url_scheme($blog->Old->SiteURL, $old_scheme), $old_values)) {
                     $old_values[] = set_url_scheme($blog->Old->SiteURL, $old_scheme);
                     $new_values[] = set_url_scheme($blog->New->SiteURL, $new_scheme);
                 }
                 // Add encoded Site URL
                 if (!in_array(urlencode(set_url_scheme($blog->Old->SiteURL, $old_scheme)), $old_values)) {
                     $old_values[] = urlencode(set_url_scheme($blog->Old->SiteURL, $old_scheme));
                     $new_values[] = urlencode(set_url_scheme($blog->New->SiteURL, $new_scheme));
                 }
                 // Add escaped Site URL
                 if (!in_array(addslashes(addcslashes(set_url_scheme($blog->Old->SiteURL, $old_scheme), '/')), $old_values)) {
                     $old_values[] = addslashes(addcslashes(set_url_scheme($blog->Old->SiteURL, $old_scheme), '/'));
                     $new_values[] = addslashes(addcslashes(set_url_scheme($blog->New->SiteURL, $new_scheme), '/'));
                 }
             }
             // Add email
             if (!isset($config->NoEmailReplace)) {
                 if (!in_array(sprintf("@%s", $old_domain), $old_values)) {
                     $old_values[] = sprintf("@%s", $old_domain);
                     $new_values[] = sprintf("@%s", $new_domain);
                 }
             }
         }
         // Get Home URL
         if (isset($blog->Old->HomeURL) && $blog->Old->HomeURL !== $blog->New->HomeURL) {
             // Get domain
             $old_domain = parse_url($blog->Old->HomeURL, PHP_URL_HOST);
             $new_domain = parse_url($blog->New->HomeURL, PHP_URL_HOST);
             // Get scheme
             $new_scheme = parse_url($blog->New->HomeURL, PHP_URL_SCHEME);
             // Replace Home URL scheme
             foreach (array('http', 'https') as $old_scheme) {
                 // Add plain Home URL
                 if (!in_array(set_url_scheme($blog->Old->HomeURL, $old_scheme), $old_values)) {
                     $old_values[] = set_url_scheme($blog->Old->HomeURL, $old_scheme);
                     $new_values[] = set_url_scheme($blog->New->HomeURL, $new_scheme);
                 }
                 // Add encoded Home URL
                 if (!in_array(urlencode(set_url_scheme($blog->Old->HomeURL, $old_scheme)), $old_values)) {
                     $old_values[] = urlencode(set_url_scheme($blog->Old->HomeURL, $old_scheme));
                     $new_values[] = urlencode(set_url_scheme($blog->New->HomeURL, $new_scheme));
                 }
                 // Add escaped Home URL
                 if (!in_array(addslashes(addcslashes(set_url_scheme($blog->Old->HomeURL, $old_scheme), '/')), $old_values)) {
                     $old_values[] = addslashes(addcslashes(set_url_scheme($blog->Old->HomeURL, $old_scheme), '/'));
                     $new_values[] = addslashes(addcslashes(set_url_scheme($blog->New->HomeURL, $new_scheme), '/'));
                 }
             }
             // Add email
             if (!isset($config->NoEmailReplace)) {
                 if (!in_array(sprintf("@%s", $old_domain), $old_values)) {
                     $old_values[] = sprintf("@%s", $old_domain);
                     $new_values[] = sprintf("@%s", $new_domain);
                 }
             }
         }
     }
     // Get Site URL
     if (isset($config->SiteURL) && $config->SiteURL !== site_url()) {
         // Get www URL
         if (stripos($config->SiteURL, '//www.') !== false) {
             $www = str_ireplace('//www.', '//', $config->SiteURL);
         } else {
             $www = str_ireplace('//', '//www.', $config->SiteURL);
         }
         // Replace Site URL
         foreach (array($config->SiteURL, $www) as $url) {
             // Get domain
             $old_domain = parse_url($url, PHP_URL_HOST);
             $new_domain = parse_url(site_url(), PHP_URL_HOST);
             // Get path
             $old_path = parse_url($url, PHP_URL_PATH);
             $new_path = parse_url(site_url(), PHP_URL_PATH);
             // Get scheme
             $new_scheme = parse_url(site_url(), PHP_URL_SCHEME);
             // Add domain and path
             if (!in_array(sprintf("%s','%s", $old_domain, trailingslashit($old_path)), $old_values)) {
                 $old_values[] = sprintf("%s','%s", $old_domain, trailingslashit($old_path));
                 $new_values[] = sprintf("%s','%s", $new_domain, trailingslashit($new_path));
             }
             // Replace Site URL scheme
             foreach (array('http', 'https') as $old_scheme) {
                 // Add plain Site URL
                 if (!in_array(set_url_scheme($url, $old_scheme), $old_values)) {
                     $old_values[] = set_url_scheme($url, $old_scheme);
                     $new_values[] = set_url_scheme(site_url(), $new_scheme);
                 }
                 // Add encoded Site URL
                 if (!in_array(urlencode(set_url_scheme($url, $old_scheme)), $old_values)) {
                     $old_values[] = urlencode(set_url_scheme($url, $old_scheme));
                     $new_values[] = urlencode(set_url_scheme(site_url(), $new_scheme));
                 }
                 // Add escaped Site URL
                 if (!in_array(addslashes(addcslashes(set_url_scheme($url, $old_scheme), '/')), $old_values)) {
                     $old_values[] = addslashes(addcslashes(set_url_scheme($url, $old_scheme), '/'));
                     $new_values[] = addslashes(addcslashes(set_url_scheme(site_url(), $new_scheme), '/'));
                 }
             }
             // Add email
             if (!isset($config->NoEmailReplace)) {
                 if (!in_array(sprintf("@%s", $old_domain), $old_values)) {
                     $old_values[] = sprintf("@%s", $old_domain);
                     $new_values[] = sprintf("@%s", $new_domain);
                 }
             }
         }
     }
     // Get Home URL
     if (isset($config->HomeURL) && $config->HomeURL !== home_url()) {
         // Get www URL
         if (stripos($config->HomeURL, '//www.') !== false) {
             $www = str_ireplace('//www.', '//', $config->HomeURL);
         } else {
             $www = str_ireplace('//', '//www.', $config->HomeURL);
         }
         // Replace Home URL
         foreach (array($config->HomeURL, $www) as $url) {
             // Get domain
             $old_domain = parse_url($url, PHP_URL_HOST);
             $new_domain = parse_url(home_url(), PHP_URL_HOST);
             // Get path
             $old_path = parse_url($url, PHP_URL_PATH);
             $new_path = parse_url(home_url(), PHP_URL_PATH);
             // Get scheme
             $new_scheme = parse_url(home_url(), PHP_URL_SCHEME);
             // Add domain and path
             if (!in_array(sprintf("%s','%s", $old_domain, trailingslashit($old_path)), $old_values)) {
                 $old_values[] = sprintf("%s','%s", $old_domain, trailingslashit($old_path));
                 $new_values[] = sprintf("%s','%s", $new_domain, trailingslashit($new_path));
             }
             // Replace Home URL scheme
             foreach (array('http', 'https') as $old_scheme) {
                 // Add plain Home URL
                 if (!in_array(set_url_scheme($url, $old_scheme), $old_values)) {
                     $old_values[] = set_url_scheme($url, $old_scheme);
                     $new_values[] = set_url_scheme(home_url(), $new_scheme);
                 }
                 // Add encoded Home URL
                 if (!in_array(urlencode(set_url_scheme($url, $old_scheme)), $old_values)) {
                     $old_values[] = urlencode(set_url_scheme($url, $old_scheme));
                     $new_values[] = urlencode(set_url_scheme(home_url(), $new_scheme));
                 }
                 // Add escaped Home URL
                 if (!in_array(addslashes(addcslashes(set_url_scheme($url, $old_scheme), '/')), $old_values)) {
                     $old_values[] = addslashes(addcslashes(set_url_scheme($url, $old_scheme), '/'));
                     $new_values[] = addslashes(addcslashes(set_url_scheme(home_url(), $new_scheme), '/'));
                 }
             }
             // Add email
             if (!isset($config->NoEmailReplace)) {
                 if (!in_array(sprintf("@%s", $old_domain), $old_values)) {
                     $old_values[] = sprintf("@%s", $old_domain);
                     $new_values[] = sprintf("@%s", $new_domain);
                 }
             }
         }
     }
     // Get WordPress Content
     if (isset($config->WordPress->Content) && $config->WordPress->Content !== WP_CONTENT_DIR) {
         // Add plain WordPress Content
         if (!in_array($config->WordPress->Content, $old_values)) {
             $old_values[] = $config->WordPress->Content;
             $new_values[] = WP_CONTENT_DIR;
         }
         // Add encoded WordPress Content
         if (!in_array(urlencode($config->WordPress->Content), $old_values)) {
             $old_values[] = urlencode($config->WordPress->Content);
             $new_values[] = urlencode(WP_CONTENT_DIR);
         }
         // Add escaped WordPress Content
         if (!in_array(addslashes(addcslashes($config->WordPress->Content, '\\/')), $old_values)) {
             $old_values[] = addslashes(addcslashes($config->WordPress->Content, '\\/'));
             $new_values[] = addslashes(addcslashes(WP_CONTENT_DIR, '\\/'));
         }
     }
     // Get URL IP
     $url_ip = get_option(AI1WM_URL_IP);
     // Get URL adapter
     $url_adapter = get_option(AI1WM_URL_ADAPTER);
     // Get secret key
     $secret_key = get_option(AI1WM_SECRET_KEY);
     // Get HTTP user
     $auth_user = get_option(AI1WM_AUTH_USER);
     // Get HTTP password
     $auth_password = get_option(AI1WM_AUTH_PASSWORD);
     // Get active ServMask plugins
     $active_servmask_plugins = ai1wm_active_servmask_plugins();
     $old_prefixes = array();
     $new_prefixes = array();
     // Set main table prefixes
     $old_prefixes[] = ai1wm_servmask_prefix('mainsite');
     $new_prefixes[] = ai1wm_table_prefix();
     // Set site table prefixes
     foreach ($blogs as $blog) {
         if (ai1wm_main_site($blog->Old->Id) === false) {
             $old_prefixes[] = ai1wm_servmask_prefix($blog->Old->Id);
             $new_prefixes[] = ai1wm_table_prefix($blog->New->Id);
         }
     }
     // Set base table prefixes
     foreach ($blogs as $blog) {
         if (ai1wm_main_site($blog->Old->Id) === true) {
             $old_prefixes[] = ai1wm_servmask_prefix('basesite');
             $new_prefixes[] = ai1wm_table_prefix($blog->New->Id);
         }
     }
     // Set site table prefixes
     foreach ($blogs as $blog) {
         if (ai1wm_main_site($blog->Old->Id) === true) {
             $old_prefixes[] = ai1wm_servmask_prefix($blog->Old->Id);
             $new_prefixes[] = ai1wm_table_prefix($blog->New->Id);
         }
     }
     // Set table prefixes
     $old_prefixes[] = ai1wm_servmask_prefix();
     $new_prefixes[] = ai1wm_table_prefix();
     // Get database client
     if (empty($wpdb->use_mysqli)) {
         $client = new Ai1wm_Database_Mysql($wpdb);
     } else {
         $client = new Ai1wm_Database_Mysqli($wpdb);
     }
     // Set database options
     $client->set_old_table_prefixes($old_prefixes)->set_new_table_prefixes($new_prefixes)->set_old_replace_values($old_values)->set_new_replace_values($new_values);
     // Flush database
     if ($version = $config->Plugin->Version) {
         if ($version !== 'develop' && version_compare($version, '4.10', '<')) {
             $client->set_include_table_prefixes(array(ai1wm_table_prefix()));
             $client->flush();
         }
     }
     // Import database
     $client->import(ai1wm_database_path($params));
     // Flush WP cache
     ai1wm_cache_flush();
     // Activate plugins
     activate_plugins($active_servmask_plugins, null, is_multisite());
     // Set the new URL IP
     update_option(AI1WM_URL_IP, $url_ip);
     // Set the new URL adapter
     update_option(AI1WM_URL_ADAPTER, $url_adapter);
     // Set the new secret key value
     update_option(AI1WM_SECRET_KEY, $secret_key);
     // Set the new HTTP user
     update_option(AI1WM_AUTH_USER, $auth_user);
     // Set the new HTTP password
     update_option(AI1WM_AUTH_PASSWORD, $auth_password);
     return $params;
 }
 public static function execute($params)
 {
     global $wpdb;
     // Set exclude database
     if (isset($params['options']['no_database'])) {
         return $params;
     }
     // Set progress
     Ai1wm_Status::info(__('Exporting database...', AI1WM_PLUGIN_NAME));
     // Get database client
     if (empty($wpdb->use_mysqli)) {
         $client = new Ai1wm_Database_Mysql($wpdb);
     } else {
         $client = new Ai1wm_Database_Mysqli($wpdb);
     }
     // Spam comments
     if (isset($params['options']['no_spam_comments'])) {
         $client->set_table_query_clauses(ai1wm_table_prefix() . 'comments', " WHERE comment_approved != 'spam' ");
         $client->set_table_query_clauses(ai1wm_table_prefix() . 'commentmeta', sprintf(" WHERE comment_id IN ( SELECT comment_ID FROM `%s` WHERE comment_approved != 'spam' ) ", ai1wm_table_prefix() . 'comments'));
     }
     // Post revisions
     if (isset($params['options']['no_revisions'])) {
         $client->set_table_query_clauses(ai1wm_table_prefix() . 'posts', " WHERE post_type != 'revision' ");
     }
     $old_table_values = array();
     $new_table_values = array();
     // Find and replace
     if (isset($params['options']['replace']) && ($replace = $params['options']['replace'])) {
         for ($i = 0; $i < count($replace['old_value']); $i++) {
             if (!empty($replace['old_value'][$i]) && !empty($replace['new_value'][$i])) {
                 $old_table_values[] = $replace['old_value'][$i];
                 $new_table_values[] = $replace['new_value'][$i];
             }
         }
     }
     $old_table_prefixes = array();
     $new_table_prefixes = array();
     // Set table prefixes
     if (ai1wm_table_prefix()) {
         $old_table_prefixes[] = ai1wm_table_prefix();
         $new_table_prefixes[] = ai1wm_servmask_prefix();
     } else {
         // Set table prefixes based on table name
         foreach ($client->get_tables() as $table_name) {
             $old_table_prefixes[] = $table_name;
             $new_table_prefixes[] = ai1wm_servmask_prefix() . $table_name;
         }
         // Set table prefixes based on user meta
         foreach (array('capabilities', 'user_level', 'user_roles') as $user_meta) {
             $old_table_prefixes[] = $user_meta;
             $new_table_prefixes[] = ai1wm_servmask_prefix() . $user_meta;
         }
     }
     $include_table_prefixes = array();
     // Include table prefixes
     if (ai1wm_table_prefix()) {
         $include_table_prefixes[] = ai1wm_table_prefix();
     } else {
         foreach ($client->get_tables() as $table_name) {
             $include_table_prefixes[] = $table_name;
         }
     }
     // Set database options
     $client->set_old_table_prefixes($old_table_prefixes)->set_new_table_prefixes($new_table_prefixes)->set_old_replace_values($old_table_values)->set_new_replace_values($new_table_values)->set_include_table_prefixes($include_table_prefixes)->set_table_prefix_columns(ai1wm_table_prefix() . 'options', array('option_name'))->set_table_prefix_columns(ai1wm_table_prefix() . 'usermeta', array('meta_key'));
     // Status options
     $client->set_table_query_clauses(ai1wm_table_prefix() . 'options', sprintf(" WHERE option_name != '%s' ", AI1WM_STATUS));
     // Set current table index
     if (isset($params['current_table_index'])) {
         $current_table_index = (int) $params['current_table_index'];
     } else {
         $current_table_index = 0;
     }
     // Export database
     $completed = $client->export(ai1wm_database_path($params), $current_table_index, 10);
     // Export completed
     if ($completed) {
         // Get archive file
         $archive = new Ai1wm_Compressor(ai1wm_archive_path($params));
         // Add database to archive
         $archive->add_file(ai1wm_database_path($params), AI1WM_DATABASE_NAME);
         $archive->close();
         // Set progress
         Ai1wm_Status::info(__('Done exporting database.', AI1WM_PLUGIN_NAME));
     }
     // Set current table index
     $params['current_table_index'] = $current_table_index;
     // Set completed flag
     $params['completed'] = $completed;
     return $params;
 }
 /**
  * Finish import process
  *
  * @return void
  */
 public function finish()
 {
     // Set progress
     Ai1wm_Status::set(array('type' => 'finish', 'title' => __('Your data has been imported successfuly!', AI1WM_PLUGIN_NAME), 'message' => sprintf(__('You need to perform two more steps:<br />' . '<strong>1. You must save your permalinks structure twice. <a class="ai1wm-no-underline" href="%s" target="_blank">Permalinks Settings</a></strong> <small>(opens a new window)</small><br />' . '<strong>2. <a class="ai1wm-no-underline" href="https://wordpress.org/support/view/plugin-reviews/all-in-one-wp-migration?rate=5#postform" target="_blank">Review the plugin</a>.</strong> <small>(opens a new window)</small>', AI1WM_PLUGIN_NAME), admin_url('options-permalink.php#submit'))));
     // Disable maintenance mode
     Ai1wm_Maintenance::disable();
 }
	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;
	}