public/wordpress/wp-content/plugins/backupbuddy/destinations/s3/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 ) {
		if ( class_exists( 'CFRuntime' ) ) {
			die( 'CFRuntime already defined. Another plugin may be incorrectly loading its copy of S3 libraries on BackupBuddy pages.' );
		}
		require_once( dirname( dirname( __FILE__ ) ) . '/_s3lib/aws-sdk/sdk.class.php' );
		$remote_path = self::get_remote_path( $settings['directory'] ); 
		$settings['bucket'] = strtolower( $settings['bucket'] ); 
		$send_response = pb_backupbuddy_destinations::send( $settings, dirname( dirname( __FILE__ ) ) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string( 12 ) ); 
		if ( false === $send_response ) {
			$send_response = 'Error sending test file to S3.';
		} else {
			$send_response = 'Success.';
		}
		$credentials = pb_backupbuddy_destination_s3::get_credentials( $settings );
		$s3_manage = new AmazonS3( $credentials );
		if ( $settings['ssl'] == 0 ) {
			@$s3_manage->disable_ssl(true);
		}
		if ( false === self::_prepareBucketAndRegion( $s3_manage, $settings ) ) {
			return false;
		}
		$delete_response = 'Success.';
		$delete_response = $s3_manage->delete_object( $credentials['bucket'], $remote_path . 'remote-send-test.php' );
		if ( !$delete_response->isOK() ) {
			$delete_response = 'Unable to delete test S3 file `remote-send-test.php`.';
			pb_backupbuddy::status( 'details', $delete_response . ' Details: `' . print_r( $delete_response, true ) . '`.' );
		} else {
			$delete_response = 'Success.';
		}
		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() ) ) {
			pb_backupbuddy::status( 'error', __('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy' ) . ' Error: ' . $result );
			return false;
		}
		pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' );
		$fileoptions = &$fileoptions_obj->options;
		if ( ( 'Success.' != $send_response ) || ( 'Success.' != $delete_response ) ) {
			$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'] = microtime(true);
		}
		$fileoptions_obj->save();
		unset( $fileoptions_obj );
		return true;
	}
public static function test ( $ settings ) { if ( class_exists ( 'CFRuntime' ) ) { die ( 'CFRuntime already defined. Another plugin may be incorrectly loading its copy of S3 libraries on BackupBuddy pages.' ) ; } require_once ( dirname ( dirname ( __FILE__ ) ) . '/_s3lib/aws-sdk/sdk.class.php' ) ; $ remote_path = self :: get_remote_path ( $ settings [ 'directory' ] ) ; $ settings [ 'bucket' ] = strtolower ( $ settings [ 'bucket' ] ) ; $ send_response = pb_backupbuddy_destinations :: send ( $ settings , dirname ( dirname ( __FILE__ ) ) . '/remote-send-test.php' , $ send_id = 'TEST-' . pb_backupbuddy :: random_string ( 12 ) ) ; if ( false === $ send_response ) { $ send_response = 'Error sending test file to S3.' ; } else { $ send_response = 'Success.' ; } $ credentials = pb_backupbuddy_destination_s3 :: get_credentials ( $ settings ) ; $ s3_manage = new AmazonS3 ( $ credentials ) ; if ( $ settings [ 'ssl' ] == 0 ) { @ $ s3_manage -> disable_ssl ( true ) ; } if ( false === self :: _prepareBucketAndRegion ( $ s3_manage , $ settings ) ) { return false ; } $ delete_response = 'Success.' ; $ delete_response = $ s3_manage -> delete_object ( $ credentials [ 'bucket' ] , $ remote_path . 'remote-send-test.php' ) ; if ( ! $ delete_response -> isOK ( ) ) { $ delete_response = 'Unable to delete test S3 file `remote-send-test.php`.' ; pb_backupbuddy :: status ( 'details' , $ delete_response . ' Details: `' . print_r ( $ delete_response , true ) . '`.' ) ; } else { $ delete_response = 'Success.' ; } 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 ( ) ) ) { pb_backupbuddy :: status ( 'error' , __ ( 'Fatal Error #9034.84838. Unable to access fileoptions data.' , 'it-l10n-backupbuddy' ) . ' Error: ' . $ result ) ; return false ; } pb_backupbuddy :: status ( 'details' , 'Fileoptions data loaded.' ) ; $ fileoptions = & $ fileoptions_obj -> options ; if ( ( 'Success.' != $ send_response ) || ( 'Success.' != $ delete_response ) ) { $ 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' ] = microtime ( true ) ; } $ fileoptions_obj -> save ( ) ; unset ( $ fileoptions_obj ) ; return true ; }
test()
test ()
// Has leading and trailng slashes. // Buckets must be lowercase. /*
		if ( FALSE !== strpos( $settings['bucket'], ' ' ) ) {
			$message = 'Bucket names cannot have spaces in them.';
			return $message;
		}
		*/ // Try sending a file. // 3rd param true forces clearing of any current uploads. // S3 object for managing files. // Verify bucket exists; create if not. Also set region to the region bucket exists in. // Delete sent file. // Load destination fileoptions.