• NGG version 2.0.66.27

    There is a problem that i have spotted few days ago. I am using NGG for long time but not so often.
    The problem I want to talk is when You have a working site with lots of posts that have NGG gallerys included and You move site to other domain/hosting/place. After doing that and repairing database records with new site address You will get “Invalid template…” or similar instead of gallery! I do not know if this will be when You leave default template, but if You set your own template (it is stored in active themes folder “ngallery”).

    Template I have set in admin panel > Gallery > gallery settings > NextGEN Basic Thumbnails section “Template” field. After doing that I go to my post, add there some gallery and save it. Everything works and i see my template working. Then I moved my site to other server (in my case from localhost to my hosting server). Updated DB with queries that fix old server address to new. The site is working fine, but galleries are not visible only I get “[Invalid template …]” (I do not remember exactly the text now). I started looking what is wrong and found that in selection box near Template I see full path from my localhost (d:\xammp\htdocs\….\mytheme\nggallery\gallery.php). I needed manually change in every post that template option!!! Also in default “Gallery settings

    Why the plugin is not using information from WordPress to find the custom template path??? Why it uses absolute paths and saves them somewhere that is not possible to change with simple SQL query?

    https://wordpress.org/plugins/nextgen-gallery/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor photocrati

    (@photocrati)

    @vytas M. – Did you try the Reset Option under Gallery > Other Options? One of its specific functions is to correct path/URL issues after migrating a site.

    You indicated you “repairing database records with new site address”, are you absolutely certain you found and modified every single instance correctly?

    Thanks!

    – Cais.

    Thread Starter Vytas M.

    (@vytasm)

    Hi,

    hmm… “Reset settings: Reset all options to default settings” So I understand that if I press it it will reset all my settings, thumbnail sizes, my templates to default values. But this is not what I want. Or this action does something else, so it need more description near it. Does it repair all posts to?

    So it is strange that plugin uses absolute paths instead of WordPress function get_theme_root() http://codex.wordpress.org/Function_Reference/get_theme_root that returns current theme absolute path, so in this case if I change path and change that in WordPress then NGG plugin will get always right path to and I do not need to do anything. Right?

    I have looked at the DB tables and if I am right NGG crates separate post that it is not visible to user but holds information about gallery that is included in my post. But the content is encoded (I didn’t searched in source code how it is stored), so using simple SQL query I can not find/change the content that I need. For example to change all links in posts i use SQl query:

    UPDATE wp_posts SET post_content = replace(post_content, 'http://localhost/mysite', 'http://mysite.com');

    As I understand for each post that has NGG gallery included NGG creates config record and template path is also there but the record is not clear text. Am I right?

    Plugin Contributor photocrati

    (@photocrati)

    @vytas M. – You are more than welcome to manually modify your database … the Reset Option just does this for you as well as setting all other NextGEN Gallery back to their installation defaults.

    – Cais.

    Thread Starter Vytas M.

    (@vytasm)

    Yes I know that I can modify it. You still didn’t answered my question or we are speaking at different frequency and you do not understand my problem at all.

    I need solution to migrate my whole website from one domain to another. I have 100 post in almost all of them is included NGG gallery. So after moving all files WordPress is working fine but NGG gallerys are not visible and getting message
    [Not a valid template]
    To fix this I need to go in to each post open Gallery settings then go to “Customize the display settings” section and in “Template” field I see OLD path so I need manually choose from drop down my modified template again. And this must be done fol all posts or pages in WordPress!!!! Do not tell me to use Reset option for such case… as it will set all settings “back to their installation defaults”.

    If there is no way to change paths in all posts at one I propose to make them relative and not absolute in next plugin versions, I understand it takes time but if You do this i think everybody will be happy with that. And i think better way is to allow users to override default template by creating same file in active theme folder like “myTheme/nggallery/gallery.php” if this file exists it will be used, if it does not exists – default template file from plugin folder will be used. Also it would be good to have option to allow fallback to default template when custom template is deleted becouse now I get [Not a valid template] message and to fix that I need to go in each post or page…

    Plugin Contributor photocrati

    (@photocrati)

    @vytas M. – My understanding is that it is very inconvenient for you to go back and change each inserted gallery to use the specific custom template you were using prior to updating … for that I do apologize but unfortunately the options I have offered are what is currently available.

    By all means, feel free to bring your thoughts and ideas on how to improve this process (which I strongly suspect would be a one time event as I also suspect you updated from NextGEN Legacy) as a Feature Request here: http://www.nextgen-gallery.com/feature-voting/

    This will put it out in front of the community for others to add their votes for this as well.

    Thanks!

    – Cais.

    Same problem here, migrating the website to production I get this develop server path:

    (fresh install no legacy update)

    /home8/webserver/public_html/cns/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/view/gallery-caption.php

    In the dropdown of the template there is the right one:
    NEXTGEN:gallery-caption.php (that should be selected if the relative paths is keeped, but there is the absolute path mentioned before).

    and it is obviously different on the production server.

    There is no reference on the db to manually change it, I have almost 140 galleries with the wrong path in the same number of pages. It is a crazy works to do manually.

    Resetting NextGen preferences does not works.
    Please help this is insane.

    Plugin Contributor photocrati

    (@photocrati)

    @xenio2000 – This appears to be a different sort of migration issue than what can commonly appear. I would suggest starting your own topic so we can help to address your specific issue.

    Thanks!

    – Cais.

    I just installed two clean version of latest WP with latest NextGen Plugin v2.0.66.37, the problem still persist.

    If I add a gallery on a page on first wp installation and migrate all the db to the second installation (obviously changing all the path on the db to point the second wp) I get a [Not a valid template].

    Looks like there is an ABSOLUTE PATH ENCODED BASE64 (WHYYY!!!) on Table WP_POSTS with post type “displayed gallery” field post_content and post_content_filtered.

    Take a look the the absolute path in “template” that is impossible to works on different wp installation when migrating… and migrate to dev to production wordpress is a common use.

    Please give me some hope I can’t manually relink 140 galleries.

    PICTURE

    DECODED CONTENTS
    {“display_settings”:{“use_lightbox_effect”:true,”images_per_page”:”20″,”number_of_columns”:”0″,”thumbnail_width”:”120″,”thumbnail_height”:”90″,”show_all_in_lightbox”:”0″,”ajax_pagination”:”0″,”use_imagebrowser_effect”:”0″,”template”:”\/Volumes\/WORKS\/WebDev\/wp1\/wp-content\/plugins\/nextgen-gallery\/products\/photocrati_nextgen\/modules\/ngglegacy\/view\/gallery-caption.php“,”display_no_images_error”:1,”disable_pagination”:0,”show_slideshow_link”:”1″,”slideshow_link_text”:”
    etc….

    Plugin Contributor photocrati

    (@photocrati)

    @xenio2000 – Again, starting your own topic would be much better as this issue is different than the OP … as it is, you can try the Reset Option under Gallery > Other Options. If that does note help, please start a new topic or send us a Bug Report (http://nextgen-gallery.com/report-bug/)

    Thanks!

    – Cais.

    PS: See also http://codex.wordpress.org/Forum_Welcome#Where_To_Post

    Same problem here. This fix (put in root of website, for big databases execute via CLI)

    require_once('wp-blog-header.php');
    
    FixGalleryTemplatePath();
    
    // ******************************************************************************
    // FixGalleryTemplatePath
    Function FixGalleryTemplatePath()
    {
    
    echo "FixGalleryTemplatePath\n\n";
    
    global $wpdb;
    $prefix=$wpdb->prefix;
    
    $oldpath='\/home\/oldpath\/public_html\/wp-content'; // change OLD path here
    $newpath='\/home\/httpd\/vhosts\/newpath\/wp-content'; // change NEW path here
    
     $sql="SELECT ID,post_content,post_content_filtered FROM {$prefix}posts WHERE post_type='displayed_gallery'";
    
     $result = $wpdb->get_results($sql);
    
    foreach ($result as $code)
    {
    
    	$id=$code->ID;
    	$decodedpost_content_filtered=base64_decode($code->post_content_filtered);
    	$decodedpost_content_filtered=str_replace($oldpath,$newpath,$decodedpost_content_filtered);
    	$encodedpost_content_filtered=base64_encode($decodedpost_content_filtered);
    
    	$decodedpost_content=base64_decode($code->post_content);
    	$decodedpost_content=str_replace($oldpath,$newpath,$decodedpost_content);
    	$encodedpost_content=base64_encode($decodedpost_content);
    
    	$sql="UPDATE '{$prefix}posts' SET 'post_content'='$encodedpost_content','post_content_filtered'='$encodedpost_content_filtered' WHERE ('ID'='$id')";
    	$wpdb->query($sql);
    
    } 
    
    echo "Fixed!";
    
    }
    Plugin Contributor photocrati

    (@photocrati)

    @mmorselli – Thanks for sharing … and as suggested earlier, using the Reset Option under Gallery > Other Options tends to “fix” migration issues as well.

    – Cais.

    The reset option does not fix anything, I had to write a code in nodejs to fix it, same as mmorselli did in php.

    var mysql = require('mysql');
    
    var connection = mysql.createConnection(
        {
          host     : 'localhost',
          user     : 'root',
          password : 'root',
          database : 'cns_yachts',
        }
    );
    
    connection.connect();
    var queryString = "SELECT * FROM cns_posts where post_type = 'displayed_gallery'";
    connection.query(queryString, function(err, rows, fields) {
    
        if (err) throw err;
        for (var i in rows) {
    
          str = new Buffer(rows[i].post_content, 'base64').toString('ascii');
          var newstr = str.replace(/template":"(.*?)"/g,'template":"gallery-caption.php"');
    
          strEncoded = new Buffer(newstr).toString('base64');
          console.log(strEncoded + " \n");
    
     connection.query('UPDATE cns_posts SET post_content = ?, post_content_filtered = ? WHERE ID = ?', [strEncoded, strEncoded, rows[i].ID],function (err,results){
          console.log(err,results);
        }
    });
    console.log("fine");
    Plugin Contributor photocrati

    (@photocrati)

    @xenio2000 – Thanks for sharing your code as well. We’ll have a look into this and why possibly the Reset Tool / Option is not covering what these functions are.

    – Cais.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Template absolute path and migration to other hosting’ is closed to new replies.