Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- WARNING: Try and only run this once, and only after the Download Monitor upgrade as been run.
- Also, I cannot guarantee that this will not break everything, so please use with caution!
- */
- function ebd_upgrade_from_legacy()
- {
- global $wpdb;
- $content_items = $wpdb->get_results( "SELECT content_id FROM `" . $wpdb->prefix . DLM_LU_Content_Queue::TABLE . "`" );
- $id_map = array();
- foreach ( $content_items as $item )
- {
- $post = get_post( $item->content_id );
- // content
- $content = $post->post_content;
- // generate new content
- $regex = "`\[email-download ([^\]]*)(?:download_id=([\"|']{0,1})([0-9]+)(?:[\"|']{0,1}))([^\]]*)\]`";
- $new_content = preg_replace_callback( $regex, function ( $m ) use ( $id_map, $wpdb ) {
- // check map, if not in map, fetch
- if ( ! isset( $id_map[ $m[3] ] ) ) {
- $new_id = absint( $wpdb->get_var( $wpdb->prepare( "SELECT `new_id` FROM `" . $wpdb->prefix . DLM_LU_Download_Queue::TABLE . "` WHERE `legacy_id` = %d ", absint( $m[3] ) ) ) );
- if ( ! $new_id )
- return $m[0];
- $id_map[ $m[3] ] = $new_id;
- }
- return "[email-download " . $m[1] . "download_id=" . $m[2] . $id_map[ $m[3] ] . $m[2] . $m[4] . "]";
- }, $content );
- if ( $content !== $new_content )
- $wpdb->update( $wpdb->posts, array( 'post_content' => $new_content ), array( 'ID' => $post->ID ), array( '%s' ), array( '%d' ) );
- }
- }
- if ( $_GET['ebd_upgrade'] == 'upgrade' )
- ebd_upgrade_from_legacy();
Add Comment
Please, Sign In to add comment