Skip to content

Commit

Permalink
Deploying version 3.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmjones committed Jun 13, 2023
1 parent 9f0b98d commit 5a21119
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 229 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**Requires at least:** 5.5 \
**Tested up to:** 6.2 \
**Requires PHP:** 7.2 \
**Stable tag:** 3.2.2 \
**Stable tag:** 3.2.3 \
**License:** GPLv3

Copies files to Amazon S3, DigitalOcean Spaces or Google Cloud Storage as they are uploaded to the Media Library. Optionally configure Amazon CloudFront or another CDN for faster delivery.
Expand Down Expand Up @@ -103,6 +103,10 @@ This version requires PHP 5.3.3+ and the Amazon Web Services plugin

## Changelog

### WP Offload Media Lite 3.2.3 - 2023-06-13

* Bug fix: Broken legacy amazonS3_info metadata no longer causes upgrade routines to fail

### WP Offload Media Lite 3.2.2 - 2023-05-16

* Security: Updated AWS SDK and Google Cloud SDK to address a vulnerability in `guzzlehttp/psr7` as reported in [CVE-2023-29197](https://nvd.nist.gov/vuln/detail/CVE-2023-29197)
Expand Down
2 changes: 1 addition & 1 deletion assets/css/settings.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/css/settings.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion classes/as3cf-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ public static function maybe_fix_serialized_string( $input ) {
return $input;
}

$output = preg_replace_callback( '/s:(\d+):"(.*?)";/',
$output = preg_replace_callback( '/s:(\d+):"(.*?)"\s?;/',
array( __CLASS__, 'fix_serialized_matches' ),
$output
);
Expand Down
2 changes: 1 addition & 1 deletion classes/items/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ private static function get_from_items_cache_by_bucket_and_path( $bucket, $path
*
* @return string
*/
protected static function items_table() {
public static function items_table(): string {
global $wpdb;

/* @var Amazon_S3_And_CloudFront $as3cf */
Expand Down
21 changes: 19 additions & 2 deletions classes/upgrades/upgrade-file-sizes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace DeliciousBrains\WP_Offload_Media\Upgrades;

use AS3CF_Error;
use AS3CF_Utils;
use DeliciousBrains\WP_Offload_Media\Items\Media_Library_Item;
use Exception;

Expand Down Expand Up @@ -58,14 +59,30 @@ protected function get_running_update_text() {
* @throws Exception
*/
protected function upgrade_item( $item ) {
$provider_object = unserialize( $item->provider_object );
$provider_object = AS3CF_Utils::maybe_fix_serialized_string( $item->provider_object );
$fixed = $item->provider_object !== $provider_object;

$provider_object = unserialize( $provider_object );

if ( false === $provider_object ) {
AS3CF_Error::log( 'Failed to unserialize offload meta for attachment ' . $item->ID . ': ' . $item->provider_object );
$this->error_count++;

return false;
}

if ( $fixed ) {
if ( update_post_meta( $item->ID, 'amazonS3_info', $provider_object ) ) {
$msg = sprintf( __( 'Fixed legacy amazonS3_info metadata when updating file size metadata, please check bucket and path for attachment ID %1$s', 'amazon-s3-and-cloudfront' ), $item->ID );
AS3CF_Error::log( $msg );
} else {
AS3CF_Error::log( 'Failed to fix broken serialized legacy offload metadata for attachment ' . $item->ID . ': ' . $item->provider_object );
$this->error_count++;

return false;
}
}

// Using Media_Library_Item::get_by_source_id falls back to legacy metadata and substitutes in defaults and potentially missing values.
$as3cf_item = Media_Library_Item::get_by_source_id( $item->ID );

Expand Down Expand Up @@ -190,4 +207,4 @@ protected function get_provider_attachments( $prefix, $limit = null ) {

return $wpdb->get_results( $sql, OBJECT );
}
}
}
20 changes: 18 additions & 2 deletions classes/upgrades/upgrade-items-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace DeliciousBrains\WP_Offload_Media\Upgrades;

use AS3CF_Error;
use AS3CF_Utils;
use DeliciousBrains\WP_Offload_Media\Items\Media_Library_Item;

/**
Expand Down Expand Up @@ -55,8 +56,11 @@ protected function get_running_update_text() {
* @return bool
*/
protected function upgrade_item( $item ) {
$provider_object = AS3CF_Utils::maybe_fix_serialized_string( $item->provider_object );
$fixed = $item->provider_object !== $provider_object;

// Make sure legacy metadata isn't broken.
$provider_object = unserialize( $item->provider_object );
$provider_object = unserialize( $provider_object );

if ( false === $provider_object ) {
AS3CF_Error::log( 'Failed to unserialize legacy offload metadata for attachment ' . $item->ID . ': ' . $item->provider_object );
Expand All @@ -72,6 +76,18 @@ protected function upgrade_item( $item ) {
return false;
}

if ( $fixed ) {
if ( update_post_meta( $item->ID, 'amazonS3_info', $provider_object ) ) {
$msg = sprintf( __( 'Fixed legacy amazonS3_info metadata when moved to %1$s table, please check bucket and path for attachment ID %2$s', 'amazon-s3-and-cloudfront' ), Media_Library_Item::items_table(), $item->ID );
AS3CF_Error::log( $msg );
} else {
AS3CF_Error::log( 'Failed to fix broken serialized legacy offload metadata for attachment ' . $item->ID . ': ' . $item->provider_object );
$this->error_count++;

return false;
}
}

// Using Media_Library_Item::get_by_source_id falls back to legacy metadata and substitutes in defaults and potentially missing values.
// If we're here we already know there's legacy metadata and that there isn't a new items table record yet,
// or there's legacy metadata and an existing items table record that we can just re-save without issue before deleting legacy metadata.
Expand Down Expand Up @@ -170,4 +186,4 @@ protected function get_attachments_with_legacy_metadata( $prefix, $count = false

return $wpdb->get_results( $sql, OBJECT );
}
}
}
21 changes: 19 additions & 2 deletions classes/upgrades/upgrade-meta-wp-error.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace DeliciousBrains\WP_Offload_Media\Upgrades;

use AS3CF_Error;
use AS3CF_Utils;
use Exception;

/**
Expand Down Expand Up @@ -57,14 +58,30 @@ protected function get_running_update_text() {
* @return bool
*/
protected function upgrade_item( $item ) {
$provider_object = unserialize( $item->provider_object );
$provider_object = AS3CF_Utils::maybe_fix_serialized_string( $item->provider_object );
$fixed = $item->provider_object !== $provider_object;

$provider_object = unserialize( $provider_object );

if ( false === $provider_object ) {
AS3CF_Error::log( 'Failed to unserialize offload meta for attachment ' . $item->ID . ': ' . $item->provider_object );
$this->error_count++;

return false;
}

if ( $fixed ) {
if ( update_post_meta( $item->ID, 'amazonS3_info', $provider_object ) ) {
$msg = sprintf( __( 'Fixed legacy amazonS3_info metadata when rebuilding corrupted attachment metadata, please check bucket and path for attachment ID %1$s', 'amazon-s3-and-cloudfront' ), $item->ID );
AS3CF_Error::log( $msg );
} else {
AS3CF_Error::log( 'Failed to fix broken serialized legacy offload metadata for attachment ' . $item->ID . ': ' . $item->provider_object );
$this->error_count++;

return false;
}
}

$file = get_attached_file( $item->ID, true );

if ( ! file_exists( $file ) ) {
Expand Down Expand Up @@ -151,4 +168,4 @@ protected function get_attachments_with_error_metadata( $prefix, $count = false,

return $wpdb->get_results( $sql, OBJECT );
}
}
}
Loading

0 comments on commit 5a21119

Please sign in to comment.