public/wordpress/wp-content/plugins/backupbuddy/destinations/s33/init.php
/*	test()
	 *	
	 *	Tests ability to write to this remote destination.
	 *	
	 *	@param		array			$settings	Destination settings.
	 *	@return		bool|string					True on success, string error message on failure.
	 */
test()

Tests ability to write to this remote destination.

@param          array                   $settings       Destination settings.
@return         bool|string                                     True on success, string error message on failure.
test () Tests ability to write to this remote destination . @param array $settings Destination settings . @return bool|string True on success string error message on failure .
public static function test( $settings ) {
		$settings = self::_init( $settings );
		$sendOK = false;
		$deleteOK = false;
		$send_id = 'TEST-' . pb_backupbuddy::random_string( 12 );
		if ( ( '1' == $settings['stash_mode'] ) && ( ! isset( $settings['live_mode'] ) || ( '1' != $settings['live_mode'] ) ) ) { 
			$settings['type'] = 'stash3';
		}
		$send_response = pb_backupbuddy_destinations::send( $settings, dirname( dirname( __FILE__ ) ) . '/remote-send-test.php', $send_id ); 
		if ( true === $send_response ) {
			$send_response = __( 'Success.', 'it-l10n-backupbuddy' );
			$sendOK = true;
		} else {
			global $pb_backupbuddy_destination_errors;
			$send_response = 'Error sending test file to S3 (v3). Details: `' . implode( ', ', $pb_backupbuddy_destination_errors ) . '`.';
		}
		pb_backupbuddy::add_status_serial( 'remote_send-' . $send_id );
		$delete_response = 'n/a';
		if ( true === $sendOK ) {
			pb_backupbuddy::status( 'details', 'Preparing to delete sent test file.' );
			if ( '1' == $settings['stash_mode'] ) { 
				if ( true === ( $delete_response = pb_backupbuddy_destination_stash3::deleteFile( $settings, 'remote-send-test.php' ) ) ) { 
					$delete_response = __( 'Success.', 'it-l10n-backupbuddy' );
					$deleteOK = true;
				} else { 
					$error = 'Unable to delete Stash test file `remote-send-test.php`. Details: `' . $delete_response . '`.';
					$delete_response = $error;
					$deleteOK = false;
				}
			} else { 
				if ( true === ( $delete_response = self::deleteFile( $settings, 'remote-send-test.php' ) ) ) {
					$delete_response = __( 'Success.', 'it-l10n-backupbuddy' );
					$deleteOK = true;
				} else {
					$error = 'Unable to delete test file `remote-send-test.php`. Details: `' . $delete_response . '`.';
					pb_backupbuddy::status( 'details', $error );
					$delete_response = $error;
					$deleteOK = false;
				}
			}
		} else { 
			pb_backupbuddy::status( 'details', 'Skipping test delete due to failed send.' );
		}
		pb_backupbuddy::status( 'details', 'About to load fileoptions data.' );
		require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' );
		pb_backupbuddy::status( 'details', 'Fileoptions instance #7.' );
		$fileoptions_obj = new pb_backupbuddy_fileoptions( backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false );
		if ( true !== ( $result = $fileoptions_obj->is_ok() ) ) {
			return self::_error( __('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy' ) . ' Error: ' . $result );
		}
		pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' );
		$fileoptions = &$fileoptions_obj->options;
		if ( ( true !== $sendOK ) || ( true !== $deleteOK ) ) {
			$fileoptions['status'] = 'failure';
			$fileoptions_obj->save();
			unset( $fileoptions_obj );
			return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.';
		} else {
			$fileoptions['status'] = 'success';
			$fileoptions['finish_time'] = time();
		}
		$fileoptions_obj->save();
		unset( $fileoptions_obj );
		pb_backupbuddy::status( 'details', 'Finished test function.' );
		return true;
	}
public static function test ( $ settings ) { $ settings = self :: _init ( $ settings ) ; $ sendOK = false ; $ deleteOK = false ; $ send_id = 'TEST-' . pb_backupbuddy :: random_string ( 12 ) ; if ( ( '1' == $ settings [ 'stash_mode' ] ) && ( ! isset ( $ settings [ 'live_mode' ] ) || ( '1' != $ settings [ 'live_mode' ] ) ) ) { $ settings [ 'type' ] = 'stash3' ; } $ send_response = pb_backupbuddy_destinations :: send ( $ settings , dirname ( dirname ( __FILE__ ) ) . '/remote-send-test.php' , $ send_id ) ; if ( true === $ send_response ) { $ send_response = __ ( 'Success.' , 'it-l10n-backupbuddy' ) ; $ sendOK = true ; } else { global $ pb_backupbuddy_destination_errors ; $ send_response = 'Error sending test file to S3 (v3). Details: `' . implode ( ', ' , $ pb_backupbuddy_destination_errors ) . '`.' ; } pb_backupbuddy :: add_status_serial ( 'remote_send-' . $ send_id ) ; $ delete_response = 'n/a' ; if ( true === $ sendOK ) { pb_backupbuddy :: status ( 'details' , 'Preparing to delete sent test file.' ) ; if ( '1' == $ settings [ 'stash_mode' ] ) { if ( true === ( $ delete_response = pb_backupbuddy_destination_stash3 :: deleteFile ( $ settings , 'remote-send-test.php' ) ) ) { $ delete_response = __ ( 'Success.' , 'it-l10n-backupbuddy' ) ; $ deleteOK = true ; } else { $ error = 'Unable to delete Stash test file `remote-send-test.php`. Details: `' . $ delete_response . '`.' ; $ delete_response = $ error ; $ deleteOK = false ; } } else { if ( true === ( $ delete_response = self :: deleteFile ( $ settings , 'remote-send-test.php' ) ) ) { $ delete_response = __ ( 'Success.' , 'it-l10n-backupbuddy' ) ; $ deleteOK = true ; } else { $ error = 'Unable to delete test file `remote-send-test.php`. Details: `' . $ delete_response . '`.' ; pb_backupbuddy :: status ( 'details' , $ error ) ; $ delete_response = $ error ; $ deleteOK = false ; } } } else { pb_backupbuddy :: status ( 'details' , 'Skipping test delete due to failed send.' ) ; } pb_backupbuddy :: status ( 'details' , 'About to load fileoptions data.' ) ; require_once ( pb_backupbuddy :: plugin_path ( ) . '/classes/fileoptions.php' ) ; pb_backupbuddy :: status ( 'details' , 'Fileoptions instance #7.' ) ; $ fileoptions_obj = new pb_backupbuddy_fileoptions ( backupbuddy_core :: getLogDirectory ( ) . 'fileoptions/send-' . $ send_id . '.txt' , $ read_only = false , $ ignore_lock = false , $ create_file = false ) ; if ( true !== ( $ result = $ fileoptions_obj -> is_ok ( ) ) ) { return self :: _error ( __ ( 'Fatal Error #9034.84838. Unable to access fileoptions data.' , 'it-l10n-backupbuddy' ) . ' Error: ' . $ result ) ; } pb_backupbuddy :: status ( 'details' , 'Fileoptions data loaded.' ) ; $ fileoptions = & $ fileoptions_obj -> options ; if ( ( true !== $ sendOK ) || ( true !== $ deleteOK ) ) { $ fileoptions [ 'status' ] = 'failure' ; $ fileoptions_obj -> save ( ) ; unset ( $ fileoptions_obj ) ; return 'Send details: `' . $ send_response . '`. Delete details: `' . $ delete_response . '`.' ; } else { $ fileoptions [ 'status' ] = 'success' ; $ fileoptions [ 'finish_time' ] = time ( ) ; } $ fileoptions_obj -> save ( ) ; unset ( $ fileoptions_obj ) ; pb_backupbuddy :: status ( 'details' , 'Finished test function.' ) ; return true ; }
test()
test ()
// Try sending a file. // Stash mode but not live mode. // 3rd param true forces clearing of any current uploads. // Delete sent file if it was sent. // Stash mode. // success // error // S3 mode. // end if $sendOK. // Load destination fileoptions.