WordPress.org

Ready to get started?Download WordPress

Forums

podPress
[resolved] Moved podcasts to new website, is it possible to update all paths? (13 posts)

  1. MCM
    Member
    Posted 1 year ago #

    Hi

    I moved all my podcast posts to a new domain as well as recreating the folder structure on this domain to be the same as my old one.

    e.g.
    mywebsite.com/mediafiles/
    mynewwebsite.com/mediafiles

    Is it possible to update the database to point to the NEW website files without breaking anything?

    http://wordpress.org/extend/plugins/podpress/

  2. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    There is no automatic update function which would update the stored URLs of the media files. If the files in a different location then you need to update all Location values manually e.g. by opening each post and updating the URL.

    If you know how to write MySQL commands then you could update the value this way too. The URLs are stored in the wp_postmeta table in rows with the meta_key _podPressMedia.

  3. MCM
    Member
    Posted 1 year ago #

    Will this a shot and if it works will leave code here.

  4. MCM
    Member
    Posted 1 year ago #

    Tried it but does not work, I did a diff on the cell contents and yah it replaced 100% but did not work.

    I then updated the location and did a diff and saw that some numbers before/after the string url was changed.

  5. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, you are right and my last advice was not good. The data of the _podPressMedia entries are serialized arrays. That means that the value is basically a string with a certain format. Each of the array values is preceeded by a value which is the length of the value itself. It is probably necessary to adjust these values to when you adjust the URLs.

    A further possibility is to write a script which loads the _podPressMedia values from the db and un-serializes each value, replaces the URL, serializes the array again and puts it back.

  6. MCM
    Member
    Posted 1 year ago #

    Thanks, but that sounds like mission impossible to me. :) but thanks anyhow.

  7. MCM
    Member
    Posted 1 year ago #

    FYI - we using your plugin with over 2000 podcast posts! :)

  8. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    A simple mini plugin which does that could look like this:

    <?php
    /*
    Plugin Name: podPress bulk URL update
    Plugin URI:
    Description: updates all Location URLs in _podPressMedia postmeta entries (Requirement: podPress needs to active)
    Author: ntm
    Version: 1.0
    Author URI:
    */
    add_filter('admin_init', 'podpress_location_urls');
    function podpress_location_urls() {
    	GLOBAL $wpdb;
    	$query_string = "SELECT pod.meta_id, pod.meta_value FROM ".$wpdb->prefix."postmeta as pod WHERE pod.meta_key = '_podPressMedia'";
    	$podpressmetadata = $wpdb->get_results($query_string, ARRAY_A);
    	if ( TRUE === is_array($podpressmetadata) AND FALSE === empty($podpressmetadata) ) {
    		for ($i=0; $i < count($podpressmetadata); $i++) {
    			$data_ar = unserialize($podpressmetadata[$i]['meta_value']);
    			if ( TRUE === is_array($data_ar) AND FALSE === empty($data_ar) ) {
    				for ($j=0; $j < count($data_ar); $j++) {
    					// search for http:// and replace it with http://
    					$new_url_data = str_replace('http://', 'https://', $data_ar[$j]['URI']);
    					$data_ar[$j]['URI'] = $new_url_data;
    				}
    			}
    			$podpressmetadata[$i]['meta_value'] = serialize($data_ar);
    			$result = $wpdb->update( $wpdb->prefix.'postmeta', array('meta_value' => $podpressmetadata[$i]['meta_value']), array('meta_id' => $podpressmetadata[$i]['meta_id']), array('%s'), array('%d') );
    		}
    	}
    }
    ?>

    You would need to replace the search and replace string according to your needs.

  9. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    I'm not sure how long this procedure takes. But it could some seconds. Do you what the max_execution_time limit on your server is?

    Note: This plugin starts to working on activation and works on each admin page request! (The activation may take longer as usual.)
    Maybe using the admin_init is not the best choice. But it will only work on admin page requests.

  10. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    This version will do the update actions only after the activation:

    <?php
    /*
    Plugin Name: podPress bulk URL update
    Plugin URI:
    Description: updates all Location URLs in _podPressMedia postmeta entries (Requirement: podPress needs to active)
    Author: ntm
    Version: 1.1
    Author URI:
    */
    class podPress_Location_URL_update {
    	function update_urls() {
    		GLOBAL $wpdb;
    		$query_string = "SELECT pod.meta_id, pod.meta_value FROM ".$wpdb->prefix."postmeta as pod WHERE pod.meta_key = '_podPressMedia'";
    		$podpressmetadata = $wpdb->get_results($query_string, ARRAY_A);
    		if ( TRUE === is_array($podpressmetadata) AND FALSE === empty($podpressmetadata) ) {
    			for ($i=0; $i < count($podpressmetadata); $i++) {
    				$data_ar = unserialize($podpressmetadata[$i]['meta_value']);
    				if ( TRUE === is_array($data_ar) AND FALSE === empty($data_ar) ) {
    					for ($j=0; $j < count($data_ar); $j++) {
    						// search for http:// and replace it with http://
    						$new_url_data = str_replace('https://', 'http://', $data_ar[$j]['URI']);
    						$data_ar[$j]['URI'] = $new_url_data;
    					}
    				}
    				$podpressmetadata[$i]['meta_value'] = serialize($data_ar);
    				$result = $wpdb->update( $wpdb->prefix.'postmeta', array('meta_value' => $podpressmetadata[$i]['meta_value']), array('meta_id' => $podpressmetadata[$i]['meta_id']), array('%s'), array('%d') );
    			}
    		}
    	}
    }
    register_activation_hook( __FILE__, array('podPress_Location_URL_update', 'update_urls') );
    ?>
  11. MCM
    Member
    Posted 1 year ago #

    WOW!

    Indeed scary to run the plugin but it worked! Considering I have thousands of podcast posts this is awesome.

    Thanks very much!

  12. MCM
    Member
    Posted 1 year ago #

    I noticed the preview image is still pointing to the old website, can I just use your script to update that as well?

  13. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, that is possible. Change the lines

    $new_url_data = str_replace('https://', 'http://', $data_ar[$j]['URI']);
    $data_ar[$j]['URI'] = $new_url_data;

    to

    $new_url_data = str_replace('https://', 'http://', $data_ar[$j]['previewImage']);
    $data_ar[$j]['previewImage'] = $new_url_data;

    and maybe adjust the search and replace pattern.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.