Commit 43eb7d75 authored by Joe Hoyle's avatar Joe Hoyle
Browse files

Added --dry-run ability to s3-uploads upload-directory

parent 8e3297c8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

class S3_Uploads_ChangedFilesIterator extends Aws\S3\Sync\ChangedFilesIterator {

	public $dry_run = false;
	public function accept() {

		$current = $this->current();
@@ -11,6 +12,12 @@ class S3_Uploads_ChangedFilesIterator extends Aws\S3\Sync\ChangedFilesIterator {
			return true;
		}

		if ( ! empty( $this->dry_run ) && defined( 'WP_CLI' ) ) {
			if ( $current->getMTime() > $data[1] ) {
				WP_CLI::line( "(dry-run) Uploading {$current->getPathname()} ({$data[0]} bytes)" );
			}
			return false;			
		}
		// Ensure it hasn't been modified since the mtime
		return $current->getMTime() > $data[1];
	}
+5 −0
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@

class S3_Uploads_UploadSyncBuilder extends Aws\S3\Sync\UploadSyncBuilder {

    public function __construct( $is_dry_run = false ) {
        $this->dry_run = $is_dry_run;
    }

	/**
     * Builds a UploadSync or DownloadSync object
     *
@@ -22,6 +26,7 @@ class S3_Uploads_UploadSyncBuilder extends Aws\S3\Sync\UploadSyncBuilder {
                $this->sourceConverter,
                $this->targetConverter
            );
            $this->sourceIterator->dry_run = $this->dry_run;
            $this->sourceIterator->rewind();
        }

+2 −2
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command {
	 * Upload a directory to S3
	 * 
	 * @subcommand upload-directory
	 * @synopsis <from> [<to>] [--sync]
	 * @synopsis <from> [<to>] [--sync] [--dry-run]
	 */
	public function upload_directory( $args, $args_assoc ) {

@@ -262,7 +262,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command {
				array(
					'debug' => true, 
					'params' => array( 'ACL' => 'public-read' ),
					'builder' => new S3_Uploads_UploadSyncBuilder(),
					'builder' => new S3_Uploads_UploadSyncBuilder( ! empty( $args_assoc['dry-run'] ) ),
					'force' => empty( $args_assoc['sync'] )
					) 
				);