Skip to content

Commit

Permalink
Import non-image files to S3.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawngee committed Apr 19, 2017
1 parent 19c82ce commit 5bf11de
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
7 changes: 7 additions & 0 deletions classes/tasks/ilab-s3-import-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 18 additions & 7 deletions classes/tools/s3/ilab-media-s3-tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ilab-media-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion views/s3/ilab-s3-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<li>This process DOES NOT delete your files on your server, you'll have to do that yourself manually.</li>
<li>It's recommended that you have the S3 tool disabled in <a href="admin.php?page=media-tools-top">Tools Settings</a> before running this task.</li>
</ol>
<div style="margin-top: 2em;">
<input type="checkbox" name="import-non-image" id="ilab-import-non-image" style="vertical-align: -5px; margin-right: 8px;"><label for="ilab-import-non-image">Import non-image files like zip files, Word documents, etc.</label>
</div>
<div style="margin-top: 2em;">
<a href="#" class="ilab-ajax button">Import Media</a>
</div>
Expand All @@ -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){
Expand Down

0 comments on commit 5bf11de

Please sign in to comment.