From 5bf11de5cef52e363bc057782739ecbe239e071d Mon Sep 17 00:00:00 2001 From: Jon Gilkison Date: Wed, 19 Apr 2017 14:58:13 +0700 Subject: [PATCH] Import non-image files to S3. --- classes/tasks/ilab-s3-import-process.php | 7 +++++++ classes/tools/s3/ilab-media-s3-tool.php | 25 +++++++++++++++++------- ilab-media-tools.php | 2 +- readme.txt | 7 +++++-- views/s3/ilab-s3-importer.php | 9 ++++++++- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/classes/tasks/ilab-s3-import-process.php b/classes/tasks/ilab-s3-import-process.php index f782a102..e21c07c9 100644 --- a/classes/tasks/ilab-s3-import-process.php +++ b/classes/tasks/ilab-s3-import-process.php @@ -34,8 +34,15 @@ protected function task($item) { $data = wp_get_attachment_metadata($post_id); + if (empty($data)) { + $file = get_attached_file($post_id); + $file = _wp_relative_upload_path($file); + $data = [ 'file' => $file ]; + } + $s3tool = ILabMediaToolsManager::instance()->tools['s3']; $data = $s3tool->updateAttachmentMetadata($data, $post_id); + wp_update_attachment_metadata($post_id, $data); return false; diff --git a/classes/tools/s3/ilab-media-s3-tool.php b/classes/tools/s3/ilab-media-s3-tool.php index 5cafaa68..67949c4b 100644 --- a/classes/tools/s3/ilab-media-s3-tool.php +++ b/classes/tools/s3/ilab-media-s3-tool.php @@ -610,13 +610,24 @@ public function importProgress() { } public function importMedia() { - $query = new WP_Query([ - 'post_type' => 'attachment', - 'post_status' => 'inherit', - 'post_mime_type' =>'image', - 'fields' => 'ids', - 'nopaging' => true, - ]); + + $importDocs = false; + if (isset($_POST['importDocs'])) { + $importDocs = intval($_POST['importDocs']); + } + + $args = [ + 'post_type' => 'attachment', + 'post_status' => 'inherit', + 'nopaging' => true, + 'fields' => 'ids', + ]; + + if (!$importDocs) { + $args['post_mime_type'] = 'image'; + } + + $query = new WP_Query($args); if ($query->post_count > 0) { update_option('ilab_s3_import_status', true); diff --git a/ilab-media-tools.php b/ilab-media-tools.php index e0725fac..430d1454 100644 --- a/ilab-media-tools.php +++ b/ilab-media-tools.php @@ -4,7 +4,7 @@ Plugin URI: http://interfacelab.com/media-tools Description: Complete media management tools Author: Jon Gilkison -Version: 1.2.2 +Version: 1.2.3 Author URI: http://interfacelab.com */ diff --git a/readme.txt b/readme.txt index 83c297c0..1a805fb7 100644 --- a/readme.txt +++ b/readme.txt @@ -2,10 +2,10 @@ Contributors: interfacelab Tags: media, images, cdn, uploads, crop, imgix, s3, cloudfront, aws, amazon s3, image editing, image editor, mirror, media library, offload, offload s3 Requires at least: 4.4 -Tested up to: 4.5 +Tested up to: 4.7.3 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html -Stable tag: 1.2.2 +Stable tag: 1.2.3 Set of tools for enhancing media in WordPress. Includes image cropper, host media from S3 or CDN, integrate with Imgix and an advanced image editor. @@ -99,6 +99,9 @@ No, I'm just one very enthusiastic customer. == Changelog == += 1.2.3 = +* Fix for importing non-image files to S3 with the importer tool + = 1.2.2 = * Ability to specify Cache-Control and Expires metadata for S3 uploads (thanks to metadan) * Fix for @{versioning} bucket prefix token diff --git a/views/s3/ilab-s3-importer.php b/views/s3/ilab-s3-importer.php index 86e4c891..fd0e9eac 100644 --- a/views/s3/ilab-s3-importer.php +++ b/views/s3/ilab-s3-importer.php @@ -29,6 +29,9 @@
  • This process DOES NOT delete your files on your server, you'll have to do that yourself manually.
  • It's recommended that you have the S3 tool disabled in Tools Settings before running this task.
  • +
    + +
    Import Media
    @@ -50,10 +53,14 @@ if (importing) return false; + importing=true; + var importDocs = document.getElementById('ilab-import-non-image').checked; + var data={ - action: 'ilab_s3_import_media' + action: 'ilab_s3_import_media', + importDocs: (importDocs) ? 1 : 0 }; $.post(ajaxurl,data,function(response){