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 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 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 ) {
		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)
 {
     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( __( '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;
	}
 /**
  * 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 ) {

		// 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)
 {
     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;
 }