Comments (1)
This works, I take no responsibility for broken databases etc etc. I'm a php noob as well, so code might be so so.
It goes through all attachment posts and add the azure storage meta data.
Probably simple to re-add some of the code i deleted from the plugin if you want to transfer the files from local to azure if you need that.
<?php
if (!function_exists('windows_azure_storage_wp_update_attachment_metadata')) {
echo "Cant find Windows Azure Storage plugin functions</br>";
die();
}
$posts = get_posts(array('post_type' => "attachment", "posts_per_page" => 10));
foreach ($posts as $post) {
$name = $post->post_title . " " . $post->ID;
echo "Migrating " . $name . "</br>";
$existingAzureMeta = get_post_meta($post->ID, "windows_azure_storage_info", true);
if (isset($existingAzureMeta) && empty($existingAzureMeta) == false) {
echo $name . " already migrated";
echo "</br></br></br></br>";
continue;
}
$file = get_post_meta($post->ID, "_wp_attached_file", true);
$data = array(
"data" =>
array(
"file" => $file
));
$result = migrateMedia($data, $post->ID);
echo json_encode($result);
echo "</br></br></br></br>";
}
function migrateMedia($data, $post_id)
{
$default_azure_storage_account_container_name = \Windows_Azure_Helper::get_default_container();
$upload_file_name = get_attached_file($post_id, true);
// Get upload directory.
$upload_dir = wp_upload_dir();
$upload_dir['subdir'] = ltrim($upload_dir['subdir'], '/');
// Prepare blob name.
$relative_file_name = ('' === $upload_dir['subdir']) ?
basename($upload_file_name) :
str_replace($upload_dir['basedir'] . '/', '', $upload_file_name);
$data['file'] = $upload_file_name;
$url = sprintf('%1$s/%2$s',
untrailingslashit(WindowsAzureStorageUtil::get_storage_url_base()),
$relative_file_name
);
$data['url'] = $url;
$thumbnails = array();
delete_post_meta($post_id, 'windows_azure_storage_info');
add_post_meta(
$post_id, 'windows_azure_storage_info',
array(
'container' => $default_azure_storage_account_container_name,
'blob' => $relative_file_name,
'url' => $url,
'thumbnails' => $thumbnails
)
);
return $data;
}
from windows-azure-storage.
Related Issues (20)
- Add a "Build release zip" GitHub Action
- Release version 4.3.4
- The plugin hasn't been tested with the latest version of WordPress
- IMG Broken after CNAME change HOT 1
- Add a 'Replace Media File' option
- WP 6.2.2 error HOT 3
- Release version 4.3.5
- `DEV_STORE_KEY` replacement HOT 1
- Add PHP checks
- moving assets to azure storage
- The plugin hasn't been tested with the latest version of WordPress HOT 1
- Webp copy of original jpeg image not uploading to Azure Storage
- Upgrade Cypress to version 13
- Using sas token to upload
- Need the images to be uploaded to wp-content/uploads/ HOT 3
- Retirement notice: The Azure Storage PHP client libraries will be retired on 17 March 2024
- Release version 4.4.0
- Update Azure Blob API to latest version
- The plugin hasn't been tested with an upcoming version of WordPress HOT 1
- Incorrect Content-Type being applied to uploaded files in v 4.4.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from windows-azure-storage.