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 content files and directories
  *
  * @return void
  */
 public function content()
 {
     // Total and processed files
     $total = Ai1wm_Status::get('total');
     $processed = Ai1wm_Status::get('processed');
     $progress = (int) ($processed / $total * 100) or $progress = 4;
     // Set progress
     Ai1wm_Status::set(array('type' => 'info', 'message' => sprintf(__('Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME), $total, $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($this->storage()->archive());
     // Set the file pointer to the one that we have saved
     $archive->set_file_pointer(null, $this->pointer());
     while ($archive->has_not_reached_eof()) {
         // Extract a file from archive to wp_content_dir
         $archive->extract_one_file_to(WP_CONTENT_DIR, array(AI1WM_PACKAGE_NAME, AI1WM_DATABASE_NAME));
         // Increment processed files counter
         $processed++;
         // We are only extracting files for 5 seconds at a time
         $time = microtime(true) - $start;
         if ($time > 5) {
             // More than 5 seconds have passed, break and do another request
             $completed = false;
             break;
         }
     }
     // Set new file map pointer
     $this->pointer($archive->get_file_pointer());
     // Close the archive file
     $archive->close();
     // Set progress
     Ai1wm_Status::set(array('processed' => $processed));
     // Redirect
     if ($completed) {
         $this->route_to('database');
     } else {
         $this->route_to('content');
     }
 }
 /**
  * Add content files and directories
  *
  * @return void
  */
 public function content()
 {
     // Set content offset
     if (isset($this->args['content_offset'])) {
         $content_offset = $this->args['content_offset'];
     } else {
         $content_offset = 0;
     }
     // Set archive offset
     if (isset($this->args['archive_offset'])) {
         $archive_offset = $this->args['archive_offset'];
     } else {
         $archive_offset = 0;
     }
     // Set total files
     if (isset($this->args['total'])) {
         $total = $this->args['total'];
     } else {
         $total = 1;
     }
     // Set processed files
     if (isset($this->args['processed'])) {
         $processed = $this->args['processed'];
     } else {
         $processed = 0;
     }
     // What percent of files have we processed?
     $progress = (int) ($processed / $total * 100);
     // Set progress
     if (empty($content_offset)) {
         Ai1wm_Status::set(array('type' => 'info', 'message' => sprintf(__('Restoring %d files...<br />%.2f%% complete', AI1WM_PLUGIN_NAME), $total, $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($this->storage()->archive());
     // Set the file pointer to the one that we have saved
     $archive->set_file_pointer(null, $archive_offset);
     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_DATABASE_NAME), $content_offset, 3)) {
                 // Set progress
                 if (($sub_progress = $content_offset / $archive->get_current_filesize()) < 1) {
                     $progress += $sub_progress;
                 }
                 // Set progress
                 Ai1wm_Status::set(array('type' => 'info', 'message' => sprintf(__('Restoring %d files...<br />%.2f%% complete', AI1WM_PLUGIN_NAME), $total, $progress)));
                 // Set content offset
                 $this->args['content_offset'] = $content_offset;
                 // Set archive offset
                 $this->args['archive_offset'] = $archive_offset;
                 // Close the archive file
                 $archive->close();
                 // Redirect
                 return $this->route_to('content');
             }
             // 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 counter
         $processed++;
         // Time elapsed
         if (microtime(true) - $start > 3) {
             // More than 3 seconds have passed, break and do another request
             $completed = false;
             break;
         }
     }
     // Set content offset
     $this->args['content_offset'] = $content_offset;
     // Set archive offset
     $this->args['archive_offset'] = $archive_offset;
     // Set processed files
     $this->args['processed'] = $processed;
     // Close the archive file
     $archive->close();
     // Redirect
     if ($completed) {
         $this->route_to('database');
     } else {
         $this->route_to('content');
     }
 }