Skip to content

Commit aaa25af

Browse files
committed
use transients instead of wp cache api
1 parent c36a25a commit aaa25af

18 files changed

+25
-527
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
A <strong><a href="https://hmn.md/">Human Made</a></strong> project. Maintained by @joehoyle.
2222
</td>
2323
<td align="center">
24-
<img src="https://hmn.md/content/themes/hmnmd/assets/images/hm-logo.svg" width="100" />
24+
<img src="https://humanmade.com/content/themes/hmnmd/assets/images/hm-logo.svg" width="100" />
2525
</td>
2626
</tr>
2727
</table>

inc/class-cache-layer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Cache_Layer implements \Aws\CacheInterface, \Countable {
1818
* @return mixed|null
1919
*/
2020
public function get( $key ) {
21-
return wp_cache_get( $key, 's3-uploads-cache' );
21+
return get_transient("offload_s3/{$key}");
2222
}
2323

2424
/**
@@ -30,8 +30,8 @@ public function get( $key ) {
3030
*
3131
* @return mixed
3232
*/
33-
public function set( $key, $value, $ttl = 0 ) {
34-
wp_cache_set( $key, $value, 's3-uploads-cache', $ttl );
33+
public function set( $key, $value, $ttl = WEEK_IN_SECONDS ) {
34+
set_transient("offload_s3/{$key}", $value, $ttl);
3535
}
3636

3737
/**
@@ -42,16 +42,16 @@ public function set( $key, $value, $ttl = 0 ) {
4242
* @return mixed
4343
*/
4444
public function remove( $key ) {
45-
wp_cache_delete( $key, 's3-uploads-cache' );
45+
delete_transient("offload_s3/{$key}");
4646
}
4747

4848
/**
4949
* Function provided here only for the compatibility with original \Aws\LruArrayCache example.
5050
*
5151
* @return int
5252
*/
53-
public function count():int {
53+
public function count(): int {
5454
return 0;
5555
}
5656

57-
}
57+
}

inc/class-local-stream-wrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public function url_stat( $uri, $flags ) {
512512
*/
513513
public function dir_opendir( $uri, $options ) {
514514
$this->uri = $uri;
515-
$this->handle = opendir( pathinfo($this->getLocalPath(), PATHINFO_DIRNAME) );
515+
$this->handle = opendir( $this->getLocalPath() );
516516

517517
return (bool) $this->handle;
518518
}

inc/class-plugin.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function register_stream_wrapper() {
146146
if ( defined( 'S3_UPLOADS_USE_LOCAL' ) && S3_UPLOADS_USE_LOCAL ) {
147147
stream_wrapper_register( 's3', 'S3_Uploads\Local_Stream_Wrapper', STREAM_IS_URL );
148148
} else {
149-
Stream_Wrapper::register( $this, 's3', new Cache_Layer() );
149+
Stream_Wrapper::register( $this );
150150
$acl = defined( 'S3_UPLOADS_OBJECT_ACL' ) ? S3_UPLOADS_OBJECT_ACL : 'public-read';
151151
stream_context_set_option( stream_context_get_default(), 's3', 'ACL', $acl );
152152
}
@@ -157,7 +157,7 @@ public function register_stream_wrapper() {
157157
/**
158158
* Get the s3:// path for the bucket.
159159
*/
160-
public function get_s3_path() {
160+
public function get_s3_path() : string {
161161
return 's3://' . $this->bucket;
162162
}
163163

@@ -184,12 +184,6 @@ public function filter_upload_dir( array $dirs ) : array {
184184
} else {
185185
$dirs['url'] = str_replace( $s3_path, $this->get_s3_url(), $dirs['path'] );
186186
$dirs['baseurl'] = str_replace( $s3_path, $this->get_s3_url(), $dirs['basedir'] );
187-
188-
// The s3:// protocol is not needed when displaying the media library and slows things down in some cases.
189-
if ( isset( $_POST['action'] ) && 'query-attachments' === $_POST['action'] ) {
190-
$dirs['path'] = $this->original_upload_dir['path'];
191-
$dirs['basedir'] = $this->original_upload_dir['basedir'];
192-
}
193187
}
194188
}
195189

inc/namespace.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ function init() {
2929
wp_die( 'S3_UPLOADS_REGION constant is required. Please define it in your wp-config.php' );
3030
}
3131

32+
if ( defined( 'WP_CLI' ) && WP_CLI ) {
33+
\WP_CLI::add_command( 's3-uploads', 'S3_Uploads\\WP_CLI_Command' );
34+
}
35+
3236
$instance = Plugin::get_instance();
3337
$instance->setup();
3438

@@ -132,7 +136,7 @@ function after_export_personal_data() {
132136
*
133137
* We don't want to use the default uploads folder location, as with S3 Uploads this is
134138
* going to the a s3:// custom URL handler, which is going to fail with the use of ZipArchive.
135-
* Instead we set to to sys_get_temp_dir and move the fail in the wp_privacy_personal_data_export_file_created
139+
* Instead we set to to WP's get_temp_dir and move the fail in the wp_privacy_personal_data_export_file_created
136140
* hook.
137141
*
138142
* @param string $dir
@@ -142,7 +146,7 @@ function set_wp_privacy_exports_dir( string $dir ) {
142146
if ( strpos( $dir, 's3://' ) !== 0 ) {
143147
return $dir;
144148
}
145-
$dir = sys_get_temp_dir() . '/wp_privacy_exports_dir/';
149+
$dir = get_temp_dir() . 'wp_privacy_exports_dir/';
146150
if ( ! is_dir( $dir ) ) {
147151
mkdir( $dir );
148152
file_put_contents( $dir . 'index.html', '' ); // @codingStandardsIgnoreLine FS write is ok.
@@ -158,7 +162,7 @@ function set_wp_privacy_exports_dir( string $dir ) {
158162
* the "natural" Core URL is going to be pointing to.
159163
*/
160164
function move_temp_personal_data_to_s3( string $archive_pathname ) {
161-
if ( strpos( $archive_pathname, sys_get_temp_dir() ) !== 0 ) {
165+
if ( strpos( $archive_pathname, get_temp_dir() ) !== 0 ) {
162166
return;
163167
}
164168
$upload_dir = wp_upload_dir();

phpunit.xml.dist

Lines changed: 0 additions & 25 deletions
This file was deleted.

psalm/stubs/imagick.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

3-
/**
4-
* @method Imagick clone() (PECL imagick 2.0.0)<br/>Makes an exact copy of the Imagick object
5-
* @link https://php.net/manual/en/class.imagick.php
6-
*/
7-
class Imagick implements Iterator, Countable {
3+
namespace {
4+
/**
5+
* @method Imagick clone() (PECL imagick 2.0.0)<br/>Makes an exact copy of the Imagick object
6+
* @link https://php.net/manual/en/class.imagick.php
7+
*/
8+
class Imagick implements Iterator, Countable {
89

10+
}
911
}
1012

1113
namespace WP_CLI {

s3-uploads.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
Plugin Name: S3 Uploads
55
Description: Store uploads in S3
66
Author: Human Made Limited
7-
Version: 3.0.3
7+
Version: 3.0.8
88
Author URI: https://hmn.md
99
*/
1010

1111
require_once __DIR__ . '/inc/namespace.php';
1212

1313
add_action( 'plugins_loaded', 'S3_Uploads\\init', 0 );
14-
15-
if ( defined( 'WP_CLI' ) && WP_CLI ) {
16-
WP_CLI::add_command( 's3-uploads', 'S3_Uploads\\WP_CLI_Command' );
17-
}

tests/bootstrap.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/data/gdpr.pdf

-447 KB
Binary file not shown.

tests/data/sunflower.jpg

-58 KB
Binary file not shown.

tests/data/video.m4v

-2.13 MB
Binary file not shown.

tests/run-tests.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/test-s3-uploads-image-editor-imagick.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)