From 22598f3c5ec4de468ada11caf500f5f34f74e7bd Mon Sep 17 00:00:00 2001 From: Jon Gilkison Date: Mon, 30 Nov 2020 18:34:01 +0700 Subject: [PATCH] * Fix for when using the ShortPixel plugin and have Media Cloud configured **NOT** to upload PDFs to cloud storage. * Fix for unlinking non-image files. * Unlink task now generates a report which you can find in your `WP_CONTENT/mcloud-reports` directory. --- classes/Tools/Storage/StorageTool.php | 12 +++++ classes/Tools/Storage/Tasks/UnlinkTask.php | 59 +++++++++++++++++++++- ilab-media-tools.php | 4 +- readme.txt | 9 +++- 4 files changed, 79 insertions(+), 5 deletions(-) diff --git a/classes/Tools/Storage/StorageTool.php b/classes/Tools/Storage/StorageTool.php index b145ca15..51feef44 100755 --- a/classes/Tools/Storage/StorageTool.php +++ b/classes/Tools/Storage/StorageTool.php @@ -4786,6 +4786,18 @@ public function handleImageOptimizer( $postId ) __METHOD__, __LINE__ ); + $mimeType = get_post_mime_type( $postId ); + + if ( StorageGlobals::mimeTypeIsIgnored( $mimeType ) ) { + Logger::info( + "Mime type {$mimeType} for {$postId} is ignored.", + [], + __METHOD__, + __LINE__ + ); + return; + } + add_filter( 'media-cloud/storage/ignore-existing-s3-data', function ( $shouldIgnore, $attachmentId ) use( $postId ) { diff --git a/classes/Tools/Storage/Tasks/UnlinkTask.php b/classes/Tools/Storage/Tasks/UnlinkTask.php index 3dac22de..53a870db 100755 --- a/classes/Tools/Storage/Tasks/UnlinkTask.php +++ b/classes/Tools/Storage/Tasks/UnlinkTask.php @@ -116,6 +116,23 @@ public static function taskOptions() { ]; } + public function reporter() { + if (empty($this->reportHeaders)) { + $allSizes = ilab_get_image_sizes(); + $sizeKeys = array_keys($allSizes); + $sizeKeys = array_sort($sizeKeys); + + $this->reportHeaders = [ + 'Post ID', + 'Attachment URL', + 'Local URL', + 'Status' + ]; + } + + return parent::reporter(); + } + //endregion //region Data @@ -160,8 +177,26 @@ public function performTask($item) { Logger::info("Processing $post_id", [], __METHOD__, __LINE__); - $meta = wp_get_attachment_metadata($post_id, true); + $isS3Info = true; + $meta = get_post_meta($post_id, 'ilab_s3_info', true); + if (empty($meta)) { + $isS3Info = false; + $meta = get_post_meta($post_id, '_wp_attachment_metadata', true); + } + + if (empty($meta)) { + $this->reporter()->add([ + $post_id, + wp_get_attachment_url($post_id), + null, + 'Missing metadata' + ]); + } + + Logger::info("Meta keys:".implode(', ', array_keys($meta))); if (isset($meta['s3'])) { + $url = wp_get_attachment_url($post_id); + unset($meta['s3']); if(isset($meta['sizes'])) { $sizes = $meta['sizes']; @@ -176,7 +211,27 @@ public function performTask($item) { $meta['sizes'] = $sizes; } - update_post_meta($post_id, '_wp_attachment_metadata', $meta); + if ($isS3Info) { + delete_post_meta($post_id, 'ilab_s3_info'); + } else { + update_post_meta($post_id, '_wp_attachment_metadata', $meta); + } + + $newUrl = wp_get_attachment_url($post_id); + + $this->reporter()->add([ + $post_id, + $url, + $newUrl, + 'Unlinked successfully' + ]); + } else { + $this->reporter()->add([ + $post_id, + wp_get_attachment_url($post_id), + null, + 'Missing cloud storage metadata' + ]); } Logger::info("Finished processing $post_id", [], __METHOD__, __LINE__); diff --git a/ilab-media-tools.php b/ilab-media-tools.php index 6a49e8d7..b70cfdee 100755 --- a/ilab-media-tools.php +++ b/ilab-media-tools.php @@ -5,7 +5,7 @@ Plugin URI: https://github.com/interfacelab/ilab-media-tools Description: Automatically upload media to Amazon S3 and integrate with Imgix, a real-time image processing CDN. Boosts site performance and simplifies workflows. Author: interfacelab -Version: 4.1.8 +Version: 4.1.9 Author URI: http://interfacelab.io */ // Copyright (c) 2016 Interfacelab LLC. All rights reserved. @@ -94,7 +94,7 @@ } // Version Defines -define( 'MEDIA_CLOUD_VERSION', '4.1.8' ); +define( 'MEDIA_CLOUD_VERSION', '4.1.9' ); define( 'MEDIA_CLOUD_INFO_VERSION', '4.0.2' ); define( 'MCLOUD_IS_BETA', false ); // Directory defines diff --git a/readme.txt b/readme.txt index 11f5915a..903143bf 100755 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Requires at least: 4.9 Tested up to: 5.6 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html -Stable tag: 4.1.8 +Stable tag: 4.1.9 Requires PHP: 7.1 Automatically store media on Amazon S3, Google Cloud Storage, DigitalOcean Spaces + others. Serve CSS/JS assets through CDNs. Integrate with Imgix. @@ -105,6 +105,13 @@ Imgix is a content delivery network with a twist. In addition to distributing y == Changelog == += 4.1.9 = + +* Fix for when using the ShortPixel plugin and have Media Cloud configured **NOT** to upload PDFs to cloud storage. +* Fix for unlinking non-image files. +* Unlink task now generates a report which you can find in your `WP_CONTENT/mcloud-reports` directory. +* You still have 3 days to use BLACKFRIDAY2020 for 33% off annual licenses, good until December 2nd. Get some! + = 4.1.8 = * And we're back. Thanks to everyone for the well wishes, truly appreciated!