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;

		// 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;
	}
 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 shutdown()
 {
     $error = error_get_last();
     // Set error type
     $type = null;
     if (isset($error['type'])) {
         $type = $error['type'];
     }
     // Set error file
     $file = null;
     if (isset($error['file'])) {
         $file = $error['file'];
     }
     // Deactivate must-use plugins on fatal and parse errors
     if (in_array($type, array(E_ERROR, E_PARSE)) && stripos($file, AI1WM_MUPLUGINS_NAME) !== false) {
         foreach (wp_get_mu_plugins() as $mu_plugin) {
             if (copy($mu_plugin, sprintf('%s-%s', $mu_plugin, date('YmdHis')))) {
                 if ($handle = fopen($mu_plugin, 'w')) {
                     fclose($handle);
                 }
             }
         }
     }
     // 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));
 }