Skip to content

Commit

Permalink
* Fix for when using the ShortPixel plugin and have Media Cloud confi…
Browse files Browse the repository at this point in the history
…gured **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.
  • Loading branch information
jawngee committed Nov 30, 2020
1 parent 988233b commit 22598f3
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 5 deletions.
12 changes: 12 additions & 0 deletions classes/Tools/Storage/StorageTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
59 changes: 57 additions & 2 deletions classes/Tools/Storage/Tasks/UnlinkTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'];
Expand All @@ -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__);
Expand Down
4 changes: 2 additions & 2 deletions ilab-media-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit 22598f3

Please sign in to comment.