public/wordpress/wp-content/plugins/backupbuddy/classes/core.php
/*	send_remote_destination()
	 *	
	 *	function description
	 *	
	 *	@param		int		$destination_id		ID number (index of the destinations array) to send it.
	 *	@param		string	$file				Full file path of file to send. MAY be an array of files.
	 *	@param		string	$trigger			What triggered this backup. Valid values: scheduled, manual.
	 *	@param		bool	$send_importbuddy	Whether or not importbuddy.php should also be sent with the file to destination.
	 *	@param		bool	$delete_after		Whether or not to delete after send success after THIS send.
	 *	@param		array 	$destination_settings	If passed then this array is used instead of grabbing from settings.
	 *	@return		bool						Send status. true success, false failed.
	 */


function description

@param          int             $destination_id         ID number (index of the destinations array) to send it.
@param          string  $file                           Full file path of file to send. MAY be an array of files.
@param          string  $trigger                        What triggered this backup. Valid values: scheduled, manual.
@param          bool    $send_importbuddy       Whether or not importbuddy.php should also be sent with the file to destination.
@param          bool    $delete_after           Whether or not to delete after send success after THIS send.
@param          array   $destination_settings   If passed then this array is used instead of grabbing from settings.
@return         bool                                            Send status. true success, false failed.
function description @param int $destination_id ID number ( index of the destinations array ) to send it . @param string $file Full file path of file to send . MAY be an array of files . @param string $trigger What triggered this backup . Valid values : scheduled manual . @param bool $send_importbuddy Whether or not importbuddy . php should also be sent with the file to destination . @param bool $delete_after Whether or not to delete after send success after THIS send . @param array $destination_settings If passed then this array is used instead of grabbing from settings . @return bool Send status . true success false failed .
public static function send_remote_destination( $destination_id, $file, $trigger = '', $send_importbuddy = false, $delete_after = false, $identifier = '', $destination_settings = '' ) {
		if ( ! is_array( $file ) ) {
			if ( ! file_exists( $file ) ) {
				$utf_decoded_filename = utf8_decode( $file );
				if ( file_exists( $utf_decoded_filename ) ) {
					$file = $utf_decoded_filename;
				} else {
					pb_backupbuddy::status( 'error', 'Error #8583489734: Unable to send file `' . $file . '` to remote destination as it no longer exists. It may have been deleted or permissions are invalid.' );
					return false;
				}
			}
		}
		$migrationkey_transient_time = 60*60*24;
		if ( ! is_array( $file ) ) {
			if ( '' == $file ) {
				$backup_file_size = 50000; 
			} else {
				$backup_file_size = filesize( $file );
			}
		} else {
			$backup_file_size = -1;
		}
		if ( '' == $identifier ) {
			$identifier = pb_backupbuddy::random_string( 12 );
		}
		if ( 'migration' == $trigger ) {
			set_transient( 'pb_backupbuddy_migrationkey', $identifier, $migrationkey_transient_time );
		}
		if ( ! is_array( $file ) ) {
			pb_backupbuddy::status( 'details', 'Sending file `' . $file . '` to remote destination `' . $destination_id . '` with ID `' . $identifier . '` triggered by `' . $trigger . '`.' );
		} else {
			pb_backupbuddy::status( 'details', 'Sending multiple files (' . count( $file ) . ') in single pass to remote destination `' . $destination_id . '` with ID `' . $identifier . '` triggered by `' . $trigger . '`.' );
		}
		require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' );
		pb_backupbuddy::status( 'details', 'Fileoptions instance #35.' );
		$fileoptions_obj = new pb_backupbuddy_fileoptions( backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $identifier . '.txt', $read_only = false, $ignore_lock = true, $create_file = true );
		if ( true !== ( $result = $fileoptions_obj->is_ok() ) ) {
			pb_backupbuddy::status( 'error', __('Fatal Error #9034 A. Unable to access fileoptions data.', 'it-l10n-backupbuddy' ) . ' Error: ' . $result );
			return false;
		}
		$fileoptions = &$fileoptions_obj->options; 
		$fileoptions = array_merge(
			self::get_remote_send_defaults(),
			array(
				'destination'		=>	$destination_id,
				'file'				=>	$file,
				'file_size'			=>	$backup_file_size,
				'trigger'			=>	$trigger,						
				'send_importbuddy'	=>	$send_importbuddy,
				'start_time'		=>	time(),
				'finish_time'		=>	0,
				'status'			=>	'running',  
				'write_speed'		=>	0,
			)
		);
		pb_backupbuddy::save();
		if ( ! is_array( $destination_settings ) ) {
			$destination_settings = &pb_backupbuddy::$options['remote_destinations'][$destination_id];
		}
		if ( $send_importbuddy === true ) {
			pb_backupbuddy::status( 'details', 'Generating temporary importbuddy.php file for remote send.' );
			pb_backupbuddy::anti_directory_browsing( backupbuddy_core::getTempDirectory(), $die = false );
			$importbuddy_temp = backupbuddy_core::getTempDirectory() . 'importbuddy.php'; 
			self::importbuddy( $importbuddy_temp ); 
			pb_backupbuddy::status( 'details', 'Generated temporary importbuddy.' );
			$importbuddy_file = $importbuddy_temp; 
			$send_importbuddy = true; 
		} else {
			pb_backupbuddy::status( 'details', 'Not sending importbuddy.' );
		}
		$fileoptions_obj->save();
		$fileoptions_obj->unlock();
		unset( $fileoptions_obj );
		require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' );
		pb_backupbuddy::status( 'details', 'Calling destination send() function.' );
		$send_result = pb_backupbuddy_destinations::send( $destination_settings, $file, $identifier, $delete_after );
		pb_backupbuddy::status( 'details', 'Finished destination send() function.' );
		if ( ! empty( $send_importbuddy ) && is_readable( $importbuddy_file ) ) {
			pb_backupbuddy::status( 'details', 'Calling destination send() function for importbuddy.php.' );
			$send_result = pb_backupbuddy_destinations::send( $destination_settings, $importbuddy_file, $identifier, $delete_after );
			pb_backupbuddy::status( 'details', 'Finished destination send() function for importbuddy.php.' );
		}
		self::kick_db(); 
		pb_backupbuddy::status( 'details', 'About to load fileoptions data for saving send status.' );
		require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' );
		pb_backupbuddy::status( 'details', 'Fileoptions instance #34.' );
		$fileoptions_obj = new pb_backupbuddy_fileoptions( backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $identifier . '.txt', $read_only = false, $ignore_lock = false, $create_file = false );
		if ( true !== ( $result = $fileoptions_obj->is_ok() ) ) {
			pb_backupbuddy::status( 'error', __('Fatal Error #9034 G. Unable to access fileoptions data.', 'it-l10n-backupbuddy' ) . ' Error: ' . $result );
			return false;
		}
		pb_backupbuddy::status( 'details', 'Fileoptions data loaded for ID `' . $identifier . '`.' );
		$fileoptions = &$fileoptions_obj->options; 
		$fileoptions[$identifier]['finish_time'] = microtime(true);
		if ( $send_result === true ) { 
			$fileoptions['status'] = 'success';
			$fileoptions['finish_time'] = microtime(true);
			pb_backupbuddy::status( 'details', 'Remote send SUCCESS.' );
		} elseif ( $send_result === false ) { 
			$fileoptions['status'] = 'failure';
			pb_backupbuddy::status( 'details', 'Remote send FAILURE.' );
		} elseif ( is_array( $send_result ) ) { 
			$fileoptions['status'] = 'multipart';
			$fileoptions['finish_time'] = 0;
			$fileoptions['_multipart_id'] = $send_result[0];
			$fileoptions['_multipart_status'] = $send_result[1];
			pb_backupbuddy::status( 'details', 'Multipart send in progress.' );
		} else {
			pb_backupbuddy::status( 'error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.' );
		}
		$fileoptions_obj->save();
		if ( $send_importbuddy !== false ) {
			@unlink( $importbuddy_temp ); 
		}
		return $send_result;
	}
public static function send_remote_destination ( $ destination_id , $ file , $ trigger = '' , $ send_importbuddy = false , $ delete_after = false , $ identifier = '' , $ destination_settings = '' ) { if ( ! is_array ( $ file ) ) { if ( ! file_exists ( $ file ) ) { $ utf_decoded_filename = utf8_decode ( $ file ) ; if ( file_exists ( $ utf_decoded_filename ) ) { $ file = $ utf_decoded_filename ; } else { pb_backupbuddy :: status ( 'error' , 'Error #8583489734: Unable to send file `' . $ file . '` to remote destination as it no longer exists. It may have been deleted or permissions are invalid.' ) ; return false ; } } } $ migrationkey_transient_time = 60 * 60 * 24 ; if ( ! is_array ( $ file ) ) { if ( '' == $ file ) { $ backup_file_size = 50000 ; } else { $ backup_file_size = filesize ( $ file ) ; } } else { $ backup_file_size = - 1 ; } if ( '' == $ identifier ) { $ identifier = pb_backupbuddy :: random_string ( 12 ) ; } if ( 'migration' == $ trigger ) { set_transient ( 'pb_backupbuddy_migrationkey' , $ identifier , $ migrationkey_transient_time ) ; } if ( ! is_array ( $ file ) ) { pb_backupbuddy :: status ( 'details' , 'Sending file `' . $ file . '` to remote destination `' . $ destination_id . '` with ID `' . $ identifier . '` triggered by `' . $ trigger . '`.' ) ; } else { pb_backupbuddy :: status ( 'details' , 'Sending multiple files (' . count ( $ file ) . ') in single pass to remote destination `' . $ destination_id . '` with ID `' . $ identifier . '` triggered by `' . $ trigger . '`.' ) ; } require_once ( pb_backupbuddy :: plugin_path ( ) . '/classes/fileoptions.php' ) ; pb_backupbuddy :: status ( 'details' , 'Fileoptions instance #35.' ) ; $ fileoptions_obj = new pb_backupbuddy_fileoptions ( backupbuddy_core :: getLogDirectory ( ) . 'fileoptions/send-' . $ identifier . '.txt' , $ read_only = false , $ ignore_lock = true , $ create_file = true ) ; if ( true !== ( $ result = $ fileoptions_obj -> is_ok ( ) ) ) { pb_backupbuddy :: status ( 'error' , __ ( 'Fatal Error #9034 A. Unable to access fileoptions data.' , 'it-l10n-backupbuddy' ) . ' Error: ' . $ result ) ; return false ; } $ fileoptions = & $ fileoptions_obj -> options ; $ fileoptions = array_merge ( self :: get_remote_send_defaults ( ) , array ( 'destination' => $ destination_id , 'file' => $ file , 'file_size' => $ backup_file_size , 'trigger' => $ trigger , 'send_importbuddy' => $ send_importbuddy , 'start_time' => time ( ) , 'finish_time' => 0 , 'status' => 'running' , 'write_speed' => 0 , ) ) ; pb_backupbuddy :: save ( ) ; if ( ! is_array ( $ destination_settings ) ) { $ destination_settings = & pb_backupbuddy :: $ options [ 'remote_destinations' ] [ $ destination_id ] ; } if ( $ send_importbuddy === true ) { pb_backupbuddy :: status ( 'details' , 'Generating temporary importbuddy.php file for remote send.' ) ; pb_backupbuddy :: anti_directory_browsing ( backupbuddy_core :: getTempDirectory ( ) , $ die = false ) ; $ importbuddy_temp = backupbuddy_core :: getTempDirectory ( ) . 'importbuddy.php' ; self :: importbuddy ( $ importbuddy_temp ) ; pb_backupbuddy :: status ( 'details' , 'Generated temporary importbuddy.' ) ; $ importbuddy_file = $ importbuddy_temp ; $ send_importbuddy = true ; } else { pb_backupbuddy :: status ( 'details' , 'Not sending importbuddy.' ) ; } $ fileoptions_obj -> save ( ) ; $ fileoptions_obj -> unlock ( ) ; unset ( $ fileoptions_obj ) ; require_once ( pb_backupbuddy :: plugin_path ( ) . '/destinations/bootstrap.php' ) ; pb_backupbuddy :: status ( 'details' , 'Calling destination send() function.' ) ; $ send_result = pb_backupbuddy_destinations :: send ( $ destination_settings , $ file , $ identifier , $ delete_after ) ; pb_backupbuddy :: status ( 'details' , 'Finished destination send() function.' ) ; if ( ! empty ( $ send_importbuddy ) && is_readable ( $ importbuddy_file ) ) { pb_backupbuddy :: status ( 'details' , 'Calling destination send() function for importbuddy.php.' ) ; $ send_result = pb_backupbuddy_destinations :: send ( $ destination_settings , $ importbuddy_file , $ identifier , $ delete_after ) ; pb_backupbuddy :: status ( 'details' , 'Finished destination send() function for importbuddy.php.' ) ; } self :: kick_db ( ) ; pb_backupbuddy :: status ( 'details' , 'About to load fileoptions data for saving send status.' ) ; require_once ( pb_backupbuddy :: plugin_path ( ) . '/classes/fileoptions.php' ) ; pb_backupbuddy :: status ( 'details' , 'Fileoptions instance #34.' ) ; $ fileoptions_obj = new pb_backupbuddy_fileoptions ( backupbuddy_core :: getLogDirectory ( ) . 'fileoptions/send-' . $ identifier . '.txt' , $ read_only = false , $ ignore_lock = false , $ create_file = false ) ; if ( true !== ( $ result = $ fileoptions_obj -> is_ok ( ) ) ) { pb_backupbuddy :: status ( 'error' , __ ( 'Fatal Error #9034 G. Unable to access fileoptions data.' , 'it-l10n-backupbuddy' ) . ' Error: ' . $ result ) ; return false ; } pb_backupbuddy :: status ( 'details' , 'Fileoptions data loaded for ID `' . $ identifier . '`.' ) ; $ fileoptions = & $ fileoptions_obj -> options ; $ fileoptions [ $ identifier ] [ 'finish_time' ] = microtime ( true ) ; if ( $ send_result === true ) { $ fileoptions [ 'status' ] = 'success' ; $ fileoptions [ 'finish_time' ] = microtime ( true ) ; pb_backupbuddy :: status ( 'details' , 'Remote send SUCCESS.' ) ; } elseif ( $ send_result === false ) { $ fileoptions [ 'status' ] = 'failure' ; pb_backupbuddy :: status ( 'details' , 'Remote send FAILURE.' ) ; } elseif ( is_array ( $ send_result ) ) { $ fileoptions [ 'status' ] = 'multipart' ; $ fileoptions [ 'finish_time' ] = 0 ; $ fileoptions [ '_multipart_id' ] = $ send_result [ 0 ] ; $ fileoptions [ '_multipart_status' ] = $ send_result [ 1 ] ; pb_backupbuddy :: status ( 'details' , 'Multipart send in progress.' ) ; } else { pb_backupbuddy :: status ( 'error' , 'Error #5485785576463. Invalid status send result: `' . $ send_result . '`.' ) ; } $ fileoptions_obj -> save ( ) ; if ( $ send_importbuddy !== false ) { @ unlink ( $ importbuddy_temp ) ; } return $ send_result ; }
send_remote_destination()
send_remote_destination ()
// Check if utf8 decoding the filename helps us find it. // not sure why anything current would be sending importbuddy but NOT sending a backup but just in case... // Generate remote send ID for reference and add it as a new logging serial for better recording details. // Set migration key for later determining last initiated migration. //pb_backupbuddy::status( 'details', 'About to create initial fileoptions data.' ); //pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' ); // Set reference. // Record some statistics. // What triggered this backup. Valid values: scheduled, manual. // success, failure, running, timeout (default assumption if this is not updated in this PHP load) // Destination settings were not passed so get them based on the destination ID provided. // Full path & filename to temporary importbuddy // Create temporary importbuddy. // Add importbuddy file to the list of files to send. // Track to delete after finished. // Clear fileoptions so other stuff can access it if needed. // Pass off to destination handler. // Kick the database to make sure it didn't go away, preventing options saving. // Reload fileoptions. // Set reference. // Update stats. // succeeded. // failed. // Array so multipart. // If we sent importbuddy then delete the local copy to clean up. // Delete temporary importbuddy. // As of v5.0: Post-send deletion now handled within destinations/bootstrap.php send() to support chunked sends.