Changeset 1385690
- Timestamp:
- 04/03/2016 04:16:11 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
blue-storage/branches/2.0.0/class-blue-storage-settings.php
r1385686 r1385690 67 67 } 68 68 69 public static function copy_to_azure( $limit ) 70 { 71 //$limit = intval($_POST['image_count']); 72 73 if( $limit > 0 && $limit <= 100 ) { 74 global $wpdb; 75 $query = "SELECT * FROM $wpdb->posts WHERE post_type='attachment' AND guid NOT LIKE '%%blob.core.windows.net%%' LIMIT %d"; 76 $query_results = $wpdb->get_results( $wpdb->prepare($query,$limit) ); 77 $total_images = $wpdb->num_rows; 78 79 if( !empty($query_results) ) 80 { 81 echo '<p id="blue-storage-notice">Preparing to copy files...</p>'; 82 echo '<br/><br/><div id="blue-storage-progress-container"></div>'; 83 echo '<div id="blue-storage-progress-information"></div>'; 84 $count = 0; 85 foreach ($query_results as $attachment) { 86 $metadata = get_post_meta($attachment->ID,'_wp_attachment_metadata')[0]; 87 $alternate_sizes = $metadata['sizes']; 88 89 // Upload original file to Azure and update metadata 90 $path = get_attached_file($attachment->ID, true); 91 WindowsAzureStorageUtil::localToBlob($attachment, $path); 92 93 // We have to upload all of the various sizes created by WordPress if there are any 94 if( !empty($alternate_sizes) ) 95 { 96 foreach ($alternate_sizes as $size) 97 { 98 WindowsAzureStorageUtil::sizeToBlob($attachment->ID, $size['file'], $attachment->post_date); 99 } 100 } 101 102 //Update progress of uploads 103 $count += 1; 104 $percent = intval(($count/$total_images) * 100).'%'; 105 echo '<script language="javascript"> 106 document.getElementById("blue-storage-progress-container").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\"> </div>"; 107 document.getElementById("blue-storage-progress-information").innerHTML="'.$count.' images uploaded."; 108 </script>'; 109 echo str_repeat(' ',1024*64); 110 ob_flush(); 111 flush(); 112 } 113 echo '<p id="blue-storage-notice">' . 'Finished copying files to "' . $selected_container_name . '" container on Azure.</p><br/>'; 114 } 115 else 116 { 117 echo '<p id="blue-storage-notice">No local files found for copying to Azure.</p>'; 118 } 119 } 120 } 121 122 public static function delete_all_uploads() 123 { 124 global $wpdb; 125 $containerURL = WindowsAzureStorageUtil::getStorageUrlPrefix(false).'/'.$selected_container_name; 126 $query = "SELECT ID FROM ".$wpdb->posts." WHERE post_type='attachment' AND guid LIKE '%%%s%%'"; 127 $query_results = $wpdb->get_results( $wpdb->prepare($query,$containerURL) ); 128 129 // Delete each every blob in the media library for the selected container 130 foreach ($query_results as $result) { 131 wp_delete_attachment($result->ID); 132 } 133 134 echo '<p id="blue-storage-notice">Deleted all files in container "' . $selected_container_name . '"</p><br/>'; 135 } 136 69 137 public static function account_settings_callback() 70 138 {
Note: See TracChangeset
for help on using the changeset viewer.