• Resolved MCM

    (@nathmie)


    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?

    https://www.ads-software.com/extend/plugins/podpress/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author ntm

    (@ntm)

    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.

    Thread Starter MCM

    (@nathmie)

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

    Thread Starter MCM

    (@nathmie)

    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.

    Plugin Author ntm

    (@ntm)

    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.

    Thread Starter MCM

    (@nathmie)

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

    Thread Starter MCM

    (@nathmie)

    FYI – we using your plugin with over 2000 podcast posts! ??

    Plugin Author ntm

    (@ntm)

    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 https:// and replace it with https://
    					$new_url_data = str_replace('https://', '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.

    Plugin Author ntm

    (@ntm)

    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.

    Plugin Author ntm

    (@ntm)

    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 https:// and replace it with https://
    						$new_url_data = str_replace('https://', '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') );
    			}
    		}
    	}
    }
    register_activation_hook( __FILE__, array('podPress_Location_URL_update', 'update_urls') );
    ?>

    Thread Starter MCM

    (@nathmie)

    WOW!

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

    Thanks very much!

    Thread Starter MCM

    (@nathmie)

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

    Plugin Author ntm

    (@ntm)

    Yes, that is possible. Change the lines

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

    to

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

    and maybe adjust the search and replace pattern.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Moved podcasts to new website, is it possible to update all paths?’ is closed to new replies.