Commit 832528b3 authored by zscott's avatar zscott
Browse files

updated S3_Uploads_WP_CLI_Command::verify_api_keys() to use handle copy() errors correctly

parent 72afa1a0
Loading
Loading
Loading
Loading
+7 −14
Original line number Diff line number Diff line
@@ -19,16 +19,17 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command {
		// Attempt to copy the file to S3
		WP_CLI::print_value( 'Attempting to upload file '. $s3_path );
		
		// Set Error Handler so we can catch it if it fails 
		set_error_handler( array( $this, 'copy_fail' ) );

		// Copies canolda from the test dir, upto S3
		// Copy canola from the test dir, upto S3
		$copy = copy(
			dirname( dirname(__FILE__) ) . '/tests/data/canola.jpg',
			$s3_path
		);
        
		restore_error_handler();
        // Check that copy worked
        if ( ! $copy ) {
            WP_CLI::error( 'Failed to copy / write to S3 - check your policy?' );
            return;
        }

		WP_CLI::print_value( 'File uploaded to S3 successfully' );

@@ -48,14 +49,6 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command {

    }

    /**
     * Used to handle when we failed uploading. 
     * Alternative is annon. function, but that breaks < PHP 5.3
     */
    public function copy_fail() {
		WP_CLI::error( 'Failed to copy / write to S3 - check your policy?' );
    }

	/**
	 * @subcommand migrate-attachments
	 * @synopsis [--delete-local]