Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Upload Progress Hotfix #109

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions windows-azure-storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,27 @@ function windows_azure_storage_wp_generate_attachment_metadata( $data, $post_id
: str_replace( $upload_dir['uploads'] . DIRECTORY_SEPARATOR, '', $upload_file_name );

try {
$post_array = wp_unslash( $_POST );
$post_array = wp_parse_args( $post_array, array(
'item_id' => $post_array['name'] . '_' . $post_array['_wpnonce'],
) );
$azure_progress_key = 'azure_progress_' . sanitize_text_field( trim( $post_array['item_id'] ) );
$current = 0;
// Get full file path of uploaded file.
$data['file'] = $upload_file_name;

// Get mime-type of the file.
$mime_type = get_post_mime_type( $post_id );
$total = 1;
if ( ! empty( $data['sizes'] ) ) {
$total = count( $data['sizes'] ) + 1;
}
if ( ! empty( $data['original_image'] ) ) {
$total++;
}

try {
if ( ! isset( $data['sizes'] ) ) {
$data['sizes'] = array();
}
set_transient( $azure_progress_key, array( 'current' => ++$current, 'total' => $total, 5 * MINUTE_IN_SECONDS ) );

// only upload file if file exists locally
if ( \Windows_Azure_Helper::file_exists( $relative_file_name ) ) {
Expand Down Expand Up @@ -434,6 +445,17 @@ function windows_azure_storage_wp_generate_attachment_metadata( $data, $post_id
? $size['file']
: $file_upload_dir . DIRECTORY_SEPARATOR . $size['file'];

set_transient(
$azure_progress_key,
array( 'current' => ++$current, 'total' => $total ),
5 * MINUTE_IN_SECONDS
);

// Ensure PDF thumbnails are offloaded with JPEG mimetype instead of PDF
if ( 'application/pdf' === $mime_type ) {
$mime_type = 'image/jpeg';
}

\Windows_Azure_Helper::put_media_to_blob_storage(
$default_azure_storage_account_container_name,
$blob_name,
Expand All @@ -458,6 +480,12 @@ function windows_azure_storage_wp_generate_attachment_metadata( $data, $post_id
? $data['original_image']
: $file_upload_dir . DIRECTORY_SEPARATOR . $data['original_image'];

set_transient(
$azure_progress_key,
array( 'current' => ++$current, 'total' => $total ),
5 * MINUTE_IN_SECONDS
);

\Windows_Azure_Helper::put_media_to_blob_storage(
$default_azure_storage_account_container_name,
$blob_name,
Expand Down