Loading inc/class-s3-uploads-wp-cli-command.php +36 −37 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $attachments = new WP_Query( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'all' 'post_status' => 'all', )); WP_CLI::line( sprintf( 'Attempting to move %d attachments to S3', $attachments->found_posts ) ); Loading Loading @@ -127,7 +127,6 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { WP_CLI::success( sprintf( 'Moved file %s to S3', $file ) ); } } else { WP_CLI::line( sprintf( 'Already moved to %s S3', $file ) ); } Loading Loading @@ -156,11 +155,11 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $iam = Aws\Common\Aws::factory( array( 'key' => $args_assoc['admin-key'], 'secret' => $args_assoc['admin-secret'] ) )->get( 'iam' ); $iam->createUser( array( 'UserName' => $username 'UserName' => $username, )); $credentials = $iam->createAccessKey( array( 'UserName' => $username 'UserName' => $username, )); $credentials = $credentials['AccessKey']; Loading @@ -168,7 +167,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $iam->putUserPolicy( array( 'UserName' => $username, 'PolicyName' => $username . '-policy', 'PolicyDocument' => $this->get_iam_policy() 'PolicyDocument' => $this->get_iam_policy(), )); } catch ( Exception $e ) { Loading @@ -189,7 +188,6 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $path = str_replace( strtok( S3_UPLOADS_BUCKET, '/' ) . '/', '', S3_UPLOADS_BUCKET ); } return '{ "Version": "2012-10-17", "Statement": [ Loading Loading @@ -262,7 +260,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { try { $objects = $s3->getIterator('ListObjects', array( 'Bucket' => strtok( S3_UPLOADS_BUCKET, '/' ), 'Prefix' => $prefix 'Prefix' => $prefix, )); foreach ( $objects as $object ) { WP_CLI::line( str_replace( $prefix, '', $object['Key'] ) ); Loading Loading @@ -324,7 +322,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { 'params' => array( 'ACL' => 'public-read' ), 'builder' => new S3_Uploads_UploadSyncBuilder( ! empty( $args_assoc['dry-run'] ) ), 'force' => empty( $args_assoc['sync'] ), 'concurrency' => ! empty( $args_assoc['concurrency'] ) ? $args_assoc['concurrency'] : 5 'concurrency' => ! empty( $args_assoc['concurrency'] ) ? $args_assoc['concurrency'] : 5, ) ); } catch ( Exception $e ) { Loading @@ -351,7 +349,6 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { if ( isset( $args[0] ) ) { $prefix .= ltrim( $args[0], '/' ); if ( strpos( $args[0], '.' ) === false ) { $prefix = trailingslashit( $prefix ); } Loading @@ -362,9 +359,12 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { strtok( S3_UPLOADS_BUCKET, '/' ), $prefix, $regex, array( 'before_delete', function() { array( 'before_delete', function() { WP_CLI::line( sprintf( 'Deleting file' ) ); }) }, ) ); } catch ( Exception $e ) { Loading Loading @@ -396,11 +396,10 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $dir = opendir( $src ); @mkdir( $dst ); while ( false !== ( $file = readdir( $dir ) ) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( ( '.' !== $file ) && ( '..' !== $file ) ) { if ( is_dir( $src . '/' . $file ) ) { $this->recurse_copy( $src . '/' . $file,$dst . '/' . $file ); } else { } else { WP_CLI::line( sprintf( 'Copying from %s to %s', $src . '/' . $file, $dst . '/' . $file ) ); copy( $src . '/' . $file,$dst . '/' . $file ); } Loading Loading
inc/class-s3-uploads-wp-cli-command.php +36 −37 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $attachments = new WP_Query( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'all' 'post_status' => 'all', )); WP_CLI::line( sprintf( 'Attempting to move %d attachments to S3', $attachments->found_posts ) ); Loading Loading @@ -127,7 +127,6 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { WP_CLI::success( sprintf( 'Moved file %s to S3', $file ) ); } } else { WP_CLI::line( sprintf( 'Already moved to %s S3', $file ) ); } Loading Loading @@ -156,11 +155,11 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $iam = Aws\Common\Aws::factory( array( 'key' => $args_assoc['admin-key'], 'secret' => $args_assoc['admin-secret'] ) )->get( 'iam' ); $iam->createUser( array( 'UserName' => $username 'UserName' => $username, )); $credentials = $iam->createAccessKey( array( 'UserName' => $username 'UserName' => $username, )); $credentials = $credentials['AccessKey']; Loading @@ -168,7 +167,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $iam->putUserPolicy( array( 'UserName' => $username, 'PolicyName' => $username . '-policy', 'PolicyDocument' => $this->get_iam_policy() 'PolicyDocument' => $this->get_iam_policy(), )); } catch ( Exception $e ) { Loading @@ -189,7 +188,6 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $path = str_replace( strtok( S3_UPLOADS_BUCKET, '/' ) . '/', '', S3_UPLOADS_BUCKET ); } return '{ "Version": "2012-10-17", "Statement": [ Loading Loading @@ -262,7 +260,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { try { $objects = $s3->getIterator('ListObjects', array( 'Bucket' => strtok( S3_UPLOADS_BUCKET, '/' ), 'Prefix' => $prefix 'Prefix' => $prefix, )); foreach ( $objects as $object ) { WP_CLI::line( str_replace( $prefix, '', $object['Key'] ) ); Loading Loading @@ -324,7 +322,7 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { 'params' => array( 'ACL' => 'public-read' ), 'builder' => new S3_Uploads_UploadSyncBuilder( ! empty( $args_assoc['dry-run'] ) ), 'force' => empty( $args_assoc['sync'] ), 'concurrency' => ! empty( $args_assoc['concurrency'] ) ? $args_assoc['concurrency'] : 5 'concurrency' => ! empty( $args_assoc['concurrency'] ) ? $args_assoc['concurrency'] : 5, ) ); } catch ( Exception $e ) { Loading @@ -351,7 +349,6 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { if ( isset( $args[0] ) ) { $prefix .= ltrim( $args[0], '/' ); if ( strpos( $args[0], '.' ) === false ) { $prefix = trailingslashit( $prefix ); } Loading @@ -362,9 +359,12 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { strtok( S3_UPLOADS_BUCKET, '/' ), $prefix, $regex, array( 'before_delete', function() { array( 'before_delete', function() { WP_CLI::line( sprintf( 'Deleting file' ) ); }) }, ) ); } catch ( Exception $e ) { Loading Loading @@ -396,11 +396,10 @@ class S3_Uploads_WP_CLI_Command extends WP_CLI_Command { $dir = opendir( $src ); @mkdir( $dst ); while ( false !== ( $file = readdir( $dir ) ) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( ( '.' !== $file ) && ( '..' !== $file ) ) { if ( is_dir( $src . '/' . $file ) ) { $this->recurse_copy( $src . '/' . $file,$dst . '/' . $file ); } else { } else { WP_CLI::line( sprintf( 'Copying from %s to %s', $src . '/' . $file, $dst . '/' . $file ) ); copy( $src . '/' . $file,$dst . '/' . $file ); } Loading