Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamwrapper: Move logic out into the open #4595

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion a8c-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct() {
return 1073741824; // 2^30
});

if ( defined( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) && true === VIP_FILESYSTEM_USE_STREAM_WRAPPER ) {
if ( ! defined( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) || constant( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) !== false ) {
$this->init_vip_filesystem();
}

Expand Down
6 changes: 3 additions & 3 deletions files/class-wp-filesystem-vip.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ private function get_transport_for_path( $filename, $context = 'read' ) {
// Uploads paths can just use PHP functions when stream wrapper is enabled.
// This is because wp_upload_dir will return a vip:// path.
if ( $this->is_uploads_path( $filename ) ) {
if ( defined( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) && true === constant( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) ) {
return $this->direct;
if ( defined( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) && false === constant( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) ) {
return $this->uploads;
}

return $this->uploads;
return $this->direct;
} elseif ( $this->is_tmp_path( $filename ) ) {
return $this->direct;
} elseif ( 'read' === $context ) {
Expand Down
4 changes: 2 additions & 2 deletions stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function track_file_upload() {
return;
}

$using_streams = false;
$using_streams = true;
if ( defined( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) ) {
$using_streams = (bool) VIP_FILESYSTEM_USE_STREAM_WRAPPER;
}
Expand Down Expand Up @@ -94,7 +94,7 @@ function track_file_delete() {
return;
}

$using_streams = false;
$using_streams = true;
if ( defined( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) ) {
$using_streams = (bool) VIP_FILESYSTEM_USE_STREAM_WRAPPER;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/files/test-wp-filesystem-vip.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ public function test__get_transport_for_path__read() {
}

public function test__get_transport_for_path__uploads_streamwrapper() {
Constant_Mocker::define( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER', true );

$get_transport_for_path = self::get_method( 'get_transport_for_path' );

$result = $get_transport_for_path->invokeArgs( $this->filesystem, [ '/tmp/wordpress/wp-content/uploads/file.file', 'read' ] );
Expand All @@ -287,6 +285,8 @@ public function test__get_transport_for_path__uploads_streamwrapper() {
}

public function test__get_transport_for_path__uploads() {
// Now that streamwrapper is enabled by default, we need to define it as disabled for this test.
define( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER', false );
$get_transport_for_path = self::get_method( 'get_transport_for_path' );

$result = $get_transport_for_path->invokeArgs( $this->filesystem, [ '/tmp/wordpress/wp-content/uploads/file.file', 'write' ] );
Expand Down
4 changes: 2 additions & 2 deletions wp-cli/vip-filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class VIP_Files_CLI_Command extends \WPCOM_VIP_CLI_Command {
* @sypnosis [--dry-run=<dry-run>] [--batch=<batch>]
*/
public function update_filesizes( $args, $assoc_args ) {
if ( ! defined( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) || true !== VIP_FILESYSTEM_USE_STREAM_WRAPPER ) {
WP_CLI::error( 'This script only works when the VIP Stream Wrapper is enabled. Please add `define( \'VIP_FILESYSTEM_USE_STREAM_WRAPPER\', true );` to vip-config.php and try again.' );
if ( defined( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) && false === constant( 'VIP_FILESYSTEM_USE_STREAM_WRAPPER' ) ) {
WP_CLI::error( 'This script only works when the VIP Stream Wrapper is enabled. If the constant \'VIP_FILESYSTEM_USE_STREAM_WRAPPER\' is defined as false, please remove it.' );
return;
}

Expand Down
Loading